From patchwork Sun Sep 4 09:23:32 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Rosen X-Patchwork-Id: 3858 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 470C423EF8 for ; Sun, 4 Sep 2011 09:24:00 +0000 (UTC) Received: from mail-fx0-f52.google.com (mail-fx0-f52.google.com [209.85.161.52]) by fiordland.canonical.com (Postfix) with ESMTP id 22FC0A181A9 for ; Sun, 4 Sep 2011 09:24:00 +0000 (UTC) Received: by fxd18 with SMTP id 18so4109840fxd.11 for ; Sun, 04 Sep 2011 02:24:00 -0700 (PDT) Received: by 10.223.4.133 with SMTP id 5mr3335509far.81.1315128215030; Sun, 04 Sep 2011 02:23:35 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.11.8 with SMTP id m8cs26277lab; Sun, 4 Sep 2011 02:23:34 -0700 (PDT) Received: by 10.216.184.147 with SMTP id s19mr2709312wem.36.1315128214328; Sun, 04 Sep 2011 02:23:34 -0700 (PDT) Received: from mail-ww0-f50.google.com (mail-ww0-f50.google.com [74.125.82.50]) by mx.google.com with ESMTPS id v48si3425222wec.66.2011.09.04.02.23.33 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 04 Sep 2011 02:23:33 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of ira.rosen@linaro.org) client-ip=74.125.82.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 74.125.82.50 is neither permitted nor denied by best guess record for domain of ira.rosen@linaro.org) smtp.mail=ira.rosen@linaro.org Received: by wwi36 with SMTP id 36so4256747wwi.31 for ; Sun, 04 Sep 2011 02:23:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.37.87 with SMTP id w23mr2758945wbd.55.1315128212875; Sun, 04 Sep 2011 02:23:32 -0700 (PDT) Received: by 10.227.11.66 with HTTP; Sun, 4 Sep 2011 02:23:32 -0700 (PDT) Date: Sun, 4 Sep 2011 12:23:32 +0300 Message-ID: Subject: [patch] Fix PR tree-optimization/50208 From: Ira Rosen To: gcc-patches@gcc.gnu.org Cc: Patch Tracking Hi, While analyzing def stmt in vectorizer pattern detection, we access its stmt_vec_info which is initialized only for statements inside the loop being analyzed. Hence if the def stmt is outside the loop, we get a segfault. This patch checks that a statement is inside the loop before accessing its stmt_vec_info. Bootstrapped and tested on powerpc64-suse-linux. Committed. Ira ChangeLog: 2011-09-04 Jakub Jelinek Ira Rosen PR tree-optimization/50208 * tree-vect-patterns.c (vect_handle_widen_mult_by_const): Add an argument. Check that def_stmt is inside the loop. (vect_recog_widen_mult_pattern): Update calls to vect_handle_widen_mult_by_cons. (vect_operation_fits_smaller_type): Check that def_stmt is inside the loop. testsuite/ChangeLog: 2011-09-04 Jakub Jelinek Ira Rosen PR tree-optimization/50208 * gcc.dg/vect/no-fre-pre-pr50208.c: New test. * gcc.dg/vect/vect.exp: Run no-fre-pre-*.c tests with -fno-tree-fre -fno-tree-pre. Index: testsuite/gcc.dg/vect/no-fre-pre-pr50208.c =================================================================== --- testsuite/gcc.dg/vect/no-fre-pre-pr50208.c (revision 0) +++ testsuite/gcc.dg/vect/no-fre-pre-pr50208.c (revision 0) @@ -0,0 +1,17 @@ +/* { dg-do compile } */ + +char c; +int a, b; + +void foo (int j) +{ + int i; + while (--j) + { + b = 3; + for (i = 0; i < 2; ++i) + a = b ^ c; + } +} + +/* { dg-final { cleanup-tree-dump "vect" } } */ Index: testsuite/gcc.dg/vect/vect.exp =================================================================== --- testsuite/gcc.dg/vect/vect.exp (revision 178506) +++ testsuite/gcc.dg/vect/vect.exp (working copy) @@ -263,6 +263,12 @@ lappend DEFAULT_VECTCFLAGS "-fno-tree-fre" dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/no-tree-fre-*.\[cS\]]] \ "" $DEFAULT_VECTCFLAGS +# -fno-tree-fre -fno-tree-pre +set DEFAULT_VECTCFLAGS $SAVED_DEFAULT_VECTCFLAGS +lappend DEFAULT_VECTCFLAGS "-fno-tree-fre" "-fno-tree-pre" +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/no-fre-pre*.\[cS\]]] \ + "" $DEFAULT_VECTCFLAGS + # Clean up. set dg-do-what-default ${save-dg-do-what-default} Index: tree-vect-patterns.c =================================================================== --- tree-vect-patterns.c (revision 178506) +++ tree-vect-patterns.c (working copy) @@ -344,12 +344,14 @@ vect_recog_dot_prod_pattern (VEC (gimple, heap) ** replace a_T = (TYPE) a_t; with a_it - (interm_type) a_t; */ static bool -vect_handle_widen_mult_by_const (tree const_oprnd, tree *oprnd, +vect_handle_widen_mult_by_const (gimple stmt, tree const_oprnd, tree *oprnd, VEC (gimple, heap) **stmts, tree type, tree *half_type, gimple def_stmt) { tree new_type, new_oprnd, tmp; gimple new_stmt; + loop_vec_info loop_info = STMT_VINFO_LOOP_VINFO (vinfo_for_stmt (stmt)); + struct loop *loop = LOOP_VINFO_LOOP (loop_info); if (int_fits_type_p (const_oprnd, *half_type)) { @@ -359,6 +361,8 @@ static bool } if (TYPE_PRECISION (type) < (TYPE_PRECISION (*half_type) * 4) + || !gimple_bb (def_stmt) + || !flow_bb_inside_loop_p (loop, gimple_bb (def_stmt)) || !vinfo_for_stmt (def_stmt)) return false; @@ -527,7 +531,8 @@ vect_recog_widen_mult_pattern (VEC (gimple, heap) { if (TREE_CODE (oprnd0) == INTEGER_CST && TREE_CODE (half_type1) == INTEGER_TYPE - && vect_handle_widen_mult_by_const (oprnd0, &oprnd1, stmts, type, + && vect_handle_widen_mult_by_const (last_stmt, oprnd0, &oprnd1, + stmts, type, &half_type1, def_stmt1)) half_type0 = half_type1; else @@ -537,7 +542,8 @@ vect_recog_widen_mult_pattern (VEC (gimple, heap) { if (TREE_CODE (oprnd1) == INTEGER_CST && TREE_CODE (half_type0) == INTEGER_TYPE - && vect_handle_widen_mult_by_const (oprnd1, &oprnd0, stmts, type, + && vect_handle_widen_mult_by_const (last_stmt, oprnd1, &oprnd0, + stmts, type, &half_type0, def_stmt0)) half_type1 = half_type0; else @@ -868,6 +874,8 @@ vect_operation_fits_smaller_type (gimple stmt, tre tree interm_type = NULL_TREE, half_type, tmp, new_oprnd, type; gimple def_stmt, new_stmt; bool first = false; + loop_vec_info loop_info = STMT_VINFO_LOOP_VINFO (vinfo_for_stmt (stmt)); + struct loop *loop = LOOP_VINFO_LOOP (loop_info); *new_def_stmt = NULL; @@ -898,6 +906,8 @@ vect_operation_fits_smaller_type (gimple stmt, tre { first = true; if (!widened_name_p (oprnd, stmt, &half_type, &def_stmt, false) + || !gimple_bb (def_stmt) + || !flow_bb_inside_loop_p (loop, gimple_bb (def_stmt)) || !vinfo_for_stmt (def_stmt)) return false; }