]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/69802 (gcc ICE at -O1 and above on valid code...
authorJakub Jelinek <jakub@redhat.com>
Thu, 7 Jul 2016 21:46:16 +0000 (23:46 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 7 Jul 2016 21:46:16 +0000 (23:46 +0200)
Backported from mainline
2016-02-16  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/69802
* tree-ssa-reassoc.c (update_range_test): If op is
SSA_NAME_IS_DEFAULT_DEF, give up unless tem is a positive
op == 1 test of precision 1 integral op, otherwise handle
that case as op itself.  Fix up formatting.
(optimize_range_tests_to_bit_test, optimize_range_tests): Fix
up formatting.

* gcc.dg/pr69802.c: New test.

From-SVN: r238135

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr69802.c [new file with mode: 0644]
gcc/tree-ssa-reassoc.c

index 5b4d4dfe847ef586d783a5ca483798193469d58c..5cb436212f0e85e605f886d9e1b208d49dd93581 100644 (file)
@@ -1,6 +1,16 @@
 2016-07-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-02-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/69802
+       * tree-ssa-reassoc.c (update_range_test): If op is
+       SSA_NAME_IS_DEFAULT_DEF, give up unless tem is a positive
+       op == 1 test of precision 1 integral op, otherwise handle
+       that case as op itself.  Fix up formatting.
+       (optimize_range_tests_to_bit_test, optimize_range_tests): Fix
+       up formatting.
+
        2014-12-12  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/64280
index fb63d67ac83dfc85ab901fe38165b3fbff373945..c07963b222d45ad760be176e80b8ee043c43172d 100644 (file)
@@ -1,6 +1,11 @@
 2016-07-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-02-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/69802
+       * gcc.dg/pr69802.c: New test.
+
        2016-02-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/69797
diff --git a/gcc/testsuite/gcc.dg/pr69802.c b/gcc/testsuite/gcc.dg/pr69802.c
new file mode 100644 (file)
index 0000000..27ee02f
--- /dev/null
@@ -0,0 +1,23 @@
+/* PR tree-optimization/69802 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wall" } */
+
+struct S { unsigned f : 1; };
+int a, d;
+
+int
+foo (void)
+{
+  unsigned b = 0;
+  struct S c;
+  d = ((1 && b) < c.f) & c.f;  /* { dg-warning "is used uninitialized" } */
+  return a;
+}
+
+int
+bar (_Bool c)
+{
+  unsigned b = 0;
+  d = ((1 && b) < c) & c;
+  return a;
+}
index 60b4dae38a79834b33d3754339ec1c74b669cbe2..6bd52cca3d56446d6662f688ba6895e14ed703b9 100644 (file)
@@ -2091,10 +2091,33 @@ update_range_test (struct range_entry *range, struct range_entry *otherrange,
   tree tem = build_range_check (loc, optype, exp, in_p, low, high);
   enum warn_strict_overflow_code wc = WARN_STRICT_OVERFLOW_COMPARISON;
   gimple_stmt_iterator gsi;
+  unsigned int uid;
 
   if (tem == NULL_TREE)
     return false;
 
+  /* If op is default def SSA_NAME, there is no place to insert the
+     new comparison.  Give up, unless we can use OP itself as the
+     range test.  */
+  if (op && SSA_NAME_IS_DEFAULT_DEF (op))
+    {
+      if (op == range->exp
+         && ((TYPE_PRECISION (optype) == 1 && TYPE_UNSIGNED (optype))
+             || TREE_CODE (optype) == BOOLEAN_TYPE)
+         && (op == tem
+             || (TREE_CODE (tem) == EQ_EXPR
+                 && TREE_OPERAND (tem, 0) == op
+                 && integer_onep (TREE_OPERAND (tem, 1))))
+         && opcode != BIT_IOR_EXPR
+         && (opcode != ERROR_MARK || oe->rank != BIT_IOR_EXPR))
+       {
+         stmt = NULL;
+         tem = op;
+       }
+      else
+       return false;
+    }
+
   if (strict_overflow_p && issue_strict_overflow_warning (wc))
     warning_at (loc, OPT_Wstrict_overflow,
                "assuming signed overflow does not occur "
@@ -2128,11 +2151,22 @@ update_range_test (struct range_entry *range, struct range_entry *otherrange,
     tem = invert_truthvalue_loc (loc, tem);
 
   tem = fold_convert_loc (loc, optype, tem);
-  gsi = gsi_for_stmt (stmt);
+  if (stmt)
+    {
+      gsi = gsi_for_stmt (stmt);
+      uid = gimple_uid (stmt);
+    }
+  else
+    {
+      gsi = gsi_none ();
+      uid = 0;
+    }
+  if (stmt == NULL)
+    gcc_checking_assert (tem == op);
   /* In rare cases range->exp can be equal to lhs of stmt.
      In that case we have to insert after the stmt rather then before
      it.  */
-  if (op == range->exp)
+  else if (op == range->exp)
     tem = force_gimple_operand_gsi (&gsi, tem, true, NULL_TREE, false,
                                    GSI_CONTINUE_LINKING);
   else
@@ -2145,7 +2179,7 @@ update_range_test (struct range_entry *range, struct range_entry *otherrange,
     if (gimple_uid (gsi_stmt (gsi)))
       break;
     else
-      gimple_set_uid (gsi_stmt (gsi), gimple_uid (stmt));
+      gimple_set_uid (gsi_stmt (gsi), uid);
 
   oe->op = tem;
   range->exp = exp;