re PR tree-optimization/67690 (wrong code with -O2 on x86_64/Linux)
authorMarek Polacek <polacek@redhat.com>
Wed, 30 Sep 2015 09:24:02 +0000 (09:24 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 30 Sep 2015 09:24:02 +0000 (09:24 +0000)
PR tree-optimization/67690
* tree-ssa-ifcombine.c (pass_tree_ifcombine::execute): Call
reset_flow_sensitive_info_in_bb.
* tree-ssa-tail-merge.c (replace_block_by): Likewise.
* tree-ssanames.c: Include "gimple-iterator.h".
(reset_flow_sensitive_info_in_bb): New function.
* tree-ssanames.h (reset_flow_sensitive_info_in_bb): Declare.

* gcc.dg/torture/pr67690.c: New test.

From-SVN: r228284

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr67690.c [new file with mode: 0644]
gcc/tree-ssa-ifcombine.c
gcc/tree-ssa-tail-merge.c
gcc/tree-ssanames.c
gcc/tree-ssanames.h

index d29e5d9d1862959c3cb7ad853a5a312540ff4bbe..0b3ce92c0e425a35ac20236246b967a0ef6221fd 100644 (file)
@@ -1,3 +1,13 @@
+2015-09-30  Marek Polacek  <polacek@redhat.com>
+
+       PR tree-optimization/67690
+       * tree-ssa-ifcombine.c (pass_tree_ifcombine::execute): Call
+       reset_flow_sensitive_info_in_bb.
+       * tree-ssa-tail-merge.c (replace_block_by): Likewise.
+       * tree-ssanames.c: Include "gimple-iterator.h".
+       (reset_flow_sensitive_info_in_bb): New function.
+       * tree-ssanames.h (reset_flow_sensitive_info_in_bb): Declare.
+
 2015-09-30  Thomas Schwinge  <thomas@codesourcery.com>
 
        * config/i386/intelmic-mkoffload.c (target_ilp32): Remove
index da03478c028318f96c1c0033b55379315ca4653c..36a41d6c129cae9ab4a09e4bcee57fbd6bd7d79c 100644 (file)
@@ -1,3 +1,8 @@
+2015-09-30  Marek Polacek  <polacek@redhat.com>
+
+       PR tree-optimization/67690
+       * gcc.dg/torture/pr67690.c: New test.
+
 2015-09-30  Christophe Lyon  <christophe.lyon@linaro.org>
 
        * g++.dg/cpp0x/stdint.C: Move dg-require-effective-target after
diff --git a/gcc/testsuite/gcc.dg/torture/pr67690.c b/gcc/testsuite/gcc.dg/torture/pr67690.c
new file mode 100644 (file)
index 0000000..491de51
--- /dev/null
@@ -0,0 +1,32 @@
+/* { dg-do run } */
+
+const int c1 = 1;
+const int c2 = 2;
+
+int
+check (int i)
+{
+  int j;
+  if (i >= 0)
+    j = c2 - i;
+  else
+    j = c2 - i;
+  return c2 - c1 + 1 > j;
+}
+
+int invoke (int *pi) __attribute__ ((noinline,noclone));
+int
+invoke (int *pi)
+{
+  return check (*pi);
+}
+
+int
+main ()
+{
+  int i = c1;
+  int ret = invoke (&i);
+  if (!ret)
+    __builtin_abort ();
+  return 0;
+}
index 9f041748fc25f321e4f9eaf34d91c1a21cfafc80..66be430f96bb725c00a4b46e6647ad71c61e2564 100644 (file)
@@ -769,16 +769,7 @@ pass_tree_ifcombine::execute (function *fun)
          {
            /* Clear range info from all stmts in BB which is now executed
               conditional on a always true/false condition.  */
-           for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
-                !gsi_end_p (gsi); gsi_next (&gsi))
-             {
-               gimple *stmt = gsi_stmt (gsi);
-               ssa_op_iter i;
-               tree op;
-               FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF)
-                 reset_flow_sensitive_info (op);
-             }
-
+           reset_flow_sensitive_info_in_bb (bb);
            cfg_changed |= true;
          }
     }
index 0ce59e8051a8ea7ccf8e8ce40cbe5080c43174d7..487961e5c99f14a812fa9c92e0e0de2d5441f342 100644 (file)
@@ -1534,6 +1534,10 @@ replace_block_by (basic_block bb1, basic_block bb2)
       e2->probability = GCOV_COMPUTE_SCALE (e2->count, out_sum);
     }
 
+  /* Clear range info from all stmts in BB2 -- this transformation
+     could make them out of date.  */
+  reset_flow_sensitive_info_in_bb (bb2);
+
   /* Do updates that use bb1, before deleting bb1.  */
   release_last_vdef (bb1);
   same_succ_flush_bb (bb1);
index 41992905fbb1340a7347fe4cbd13ad477830578a..7235dc3d56ab98793c8ab711e9aade7d45fe3312 100644 (file)
@@ -23,6 +23,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "backend.h"
 #include "tree.h"
 #include "gimple.h"
+#include "gimple-iterator.h"
 #include "hard-reg-set.h"
 #include "ssa.h"
 #include "alias.h"
@@ -544,6 +545,29 @@ reset_flow_sensitive_info (tree name)
     SSA_NAME_RANGE_INFO (name) = NULL;
 }
 
+/* Clear all flow sensitive data from all statements and PHI definitions
+   in BB.  */
+
+void
+reset_flow_sensitive_info_in_bb (basic_block bb)
+{
+  for (gimple_stmt_iterator gsi = gsi_start_bb (bb); !gsi_end_p (gsi);
+       gsi_next (&gsi))
+    {
+      gimple *stmt = gsi_stmt (gsi);
+      ssa_op_iter i;
+      tree op;
+      FOR_EACH_SSA_TREE_OPERAND (op, stmt, i, SSA_OP_DEF)
+       reset_flow_sensitive_info (op);
+    }
+
+  for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
+       gsi_next (&gsi))
+    {
+      tree phi_def = gimple_phi_result (gsi.phi ());
+      reset_flow_sensitive_info (phi_def);
+    }
+}
 
 /* Release all the SSA_NAMEs created by STMT.  */
 
index 22ff6094a0b9ca7fed3d6acaa960c13296749328..5688ca566bf78700c83a4e2fed6b1de741654dad 100644 (file)
@@ -95,6 +95,7 @@ extern tree duplicate_ssa_name_fn (struct function *, tree, gimple *);
 extern void duplicate_ssa_name_range_info (tree, enum value_range_type,
                                           struct range_info_def *);
 extern void reset_flow_sensitive_info (tree);
+extern void reset_flow_sensitive_info_in_bb (basic_block);
 extern void release_defs (gimple *);
 extern void replace_ssa_name_symbol (tree, tree);