]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR tree-optimization/69802 (gcc ICE at -O1 and above on valid code on x86_64...
authorJakub Jelinek <jakub@redhat.com>
Tue, 16 Feb 2016 09:12:37 +0000 (10:12 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 16 Feb 2016 09:12:37 +0000 (10:12 +0100)
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: r233446

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

index b7878906b9bcd10db0475ce4c0849126a08b8bf4..2700b6bd41082907198e6ad5d28c775214c729ef 100644 (file)
@@ -1,3 +1,13 @@
+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.
+
 2016-02-16  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/69586
index 9ce6eb83836f70a0751f400f7965bddacb43b418..4d6884ed5c49cb287e852a728ffd1652e48cfe7c 100644 (file)
@@ -1,3 +1,8 @@
+2016-02-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/69802
+       * gcc.dg/pr69802.c: New test.
+
 2016-02-16  Richard Biener  <rguenther@suse.de>
 
        PR middle-end/69801
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 e53cc5683b4e3bb50ce77b8887311975752e554b..17eb64f1aa7a9905da1c178bbc92022fc5387bbe 100644 (file)
@@ -2046,19 +2046,41 @@ update_range_test (struct range_entry *range, struct range_entry *otherrange,
 {
   operand_entry *oe = (*ops)[range->idx];
   tree op = oe->op;
-  gimple *stmt = op ? SSA_NAME_DEF_STMT (op) :
-    last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id));
+  gimple *stmt = op ? SSA_NAME_DEF_STMT (op)
+                   : last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id));
   location_t loc = gimple_location (stmt);
   tree optype = op ? TREE_TYPE (op) : boolean_type_node;
   tree tem = build_range_check (loc, optype, unshare_expr (exp),
                                in_p, low, high);
   enum warn_strict_overflow_code wc = WARN_STRICT_OVERFLOW_COMPARISON;
   gimple_stmt_iterator gsi;
-  unsigned int i;
+  unsigned int i, 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 "
@@ -2096,12 +2118,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);
-  unsigned int uid = gimple_uid (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 stmt is a PHI, insert it at the start of the basic block.  */
-  if (op != range->exp)
+  else if (op != range->exp)
     {
       gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT);
       tem = force_gimple_operand_gsi (&gsi, tem, true, NULL_TREE, true,
@@ -2489,7 +2521,7 @@ optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length,
          operand_entry *oe = (*ops)[ranges[i].idx];
          tree op = oe->op;
          gimple *stmt = op ? SSA_NAME_DEF_STMT (op)
-                          : last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id));
+                           : last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id));
          location_t loc = gimple_location (stmt);
          tree optype = op ? TREE_TYPE (op) : boolean_type_node;
 
@@ -2553,7 +2585,7 @@ optimize_range_tests_to_bit_test (enum tree_code opcode, int first, int length,
          gcc_assert (TREE_CODE (exp) == SSA_NAME);
          gimple_set_visited (SSA_NAME_DEF_STMT (exp), true);
          gimple *g = gimple_build_assign (make_ssa_name (optype),
-                                         BIT_IOR_EXPR, tem, exp);
+                                          BIT_IOR_EXPR, tem, exp);
          gimple_set_location (g, loc);
          gimple_seq_add_stmt_without_update (&seq, g);
          exp = gimple_assign_lhs (g);
@@ -2599,8 +2631,9 @@ optimize_range_tests (enum tree_code opcode,
       oe = (*ops)[i];
       ranges[i].idx = i;
       init_range_entry (ranges + i, oe->op,
-                       oe->op ? NULL :
-                         last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id)));
+                       oe->op
+                       ? NULL
+                       : last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id)));
       /* For | invert it now, we will invert it again before emitting
         the optimized expression.  */
       if (opcode == BIT_IOR_EXPR