]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR middle-end/48973 (Inliner bug with one-bit (1-bit) bitfield)
authorJakub Jelinek <jakub@redhat.com>
Tue, 19 Jul 2011 19:28:41 +0000 (21:28 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 19 Jul 2011 19:28:41 +0000 (21:28 +0200)
Backport from mainline
2011-05-23  Jakub Jelinek  <jakub@redhat.com>

PR middle-end/48973
* expr.c (expand_expr_real_1) <case LT_EXPR>: If do_store_flag
failed and the comparison has a single bit signed type, use
constm1_rtx instead of const1_rtx for true value.
(do_store_flag): If TREE_TYPE (exp) is single bit signed type, disable
single bit test optimization, pass -1 instead of 1 as last
parameter to emit_store_flag and use constm1_rtx instead of
const1_rtx as true value.

* gcc.c-torture/execute/pr48973-1.c: New test.
* gcc.c-torture/execute/pr48973-2.c: New test.

From-SVN: r176482

gcc/ChangeLog
gcc/expr.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr48973-1.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/execute/pr48973-2.c [new file with mode: 0644]

index 3a0debf8ded42e7d03ab4e217c64cd7dc279f7ba..9b062d745c73be6930dae907b8b855cafe93dc49 100644 (file)
@@ -1,6 +1,17 @@
 2011-07-19  Jakub Jelinek  <jakub@redhat.com>
 
        Backport from mainline
+       2011-05-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/48973
+       * expr.c (expand_expr_real_1) <case LT_EXPR>: If do_store_flag
+       failed and the comparison has a single bit signed type, use
+       constm1_rtx instead of const1_rtx for true value.
+       (do_store_flag): If TREE_TYPE (exp) is single bit signed type, disable
+       single bit test optimization, pass -1 instead of 1 as last
+       parameter to emit_store_flag and use constm1_rtx instead of
+       const1_rtx as true value.
+
        2011-05-18  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/49039
index fd6788905612c15cbd0d1515fc55ac3293692589..0d96eb334417328b66189778b35f0293da08bb24 100644 (file)
@@ -9113,10 +9113,12 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
          /* If temp is constant, we can just compute the result.  */
          if (GET_CODE (temp) == CONST_INT)
            {
-             if (INTVAL (temp) != 0)
-               emit_move_insn (target, const1_rtx);
-             else
+             if (INTVAL (temp) == 0)
                emit_move_insn (target, const0_rtx);
+             else if (TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type))
+               emit_move_insn (target, constm1_rtx);
+             else
+               emit_move_insn (target, const1_rtx);
 
              return target;
            }
@@ -9133,7 +9135,9 @@ expand_expr_real_1 (tree exp, rtx target, enum machine_mode tmode,
          op1 = gen_label_rtx ();
          emit_cmp_and_jump_insns (temp, const0_rtx, EQ, NULL_RTX,
                                   GET_MODE (temp), unsignedp, op1);
-         emit_move_insn (temp, const1_rtx);
+         emit_move_insn (temp,
+                         TYPE_PRECISION (type) == 1 && !TYPE_UNSIGNED (type)
+                         ? constm1_rtx : const1_rtx);
          emit_label (op1);
          return temp;
        }
@@ -9757,7 +9761,7 @@ do_store_flag (tree exp, rtx target, enum machine_mode mode, int only_cheap)
   rtx op0, op1;
   enum insn_code icode;
   rtx subtarget = target;
-  rtx result, label;
+  rtx result, label, trueval = const1_rtx;
 
   /* If this is a TRUTH_NOT_EXPR, set a flag indicating we must invert the
      result at the end.  We can't simply invert the test since it would
@@ -9887,7 +9891,9 @@ do_store_flag (tree exp, rtx target, enum machine_mode mode, int only_cheap)
 
   if ((code == NE || code == EQ)
       && TREE_CODE (arg0) == BIT_AND_EXPR && integer_zerop (arg1)
-      && integer_pow2p (TREE_OPERAND (arg0, 1)))
+      && integer_pow2p (TREE_OPERAND (arg0, 1))
+      && (TYPE_PRECISION (TREE_TYPE (exp)) != 1
+         || TYPE_UNSIGNED (TREE_TYPE (exp))))
     {
       tree type = lang_hooks.types.type_for_mode (mode, unsignedp);
       return expand_expr (fold_single_bit_test (code == NE ? NE_EXPR : EQ_EXPR,
@@ -9939,13 +9945,18 @@ do_store_flag (tree exp, rtx target, enum machine_mode mode, int only_cheap)
   if (target == 0)
     target = gen_reg_rtx (mode);
 
+  if (TYPE_PRECISION (TREE_TYPE (exp)) == 1
+      && !TYPE_UNSIGNED (TREE_TYPE (exp)))
+    trueval = constm1_rtx;
+
   result = emit_store_flag (target, code, op0, op1,
-                           operand_mode, unsignedp, 1);
+                           operand_mode, unsignedp,
+                           trueval == const1_rtx ? 1 : -1);
 
   if (result)
     {
       if (invert)
-       result = expand_binop (mode, xor_optab, result, const1_rtx,
+       result = expand_binop (mode, xor_optab, result, trueval,
                               result, 0, OPTAB_LIB_WIDEN);
       return result;
     }
@@ -9955,12 +9966,12 @@ do_store_flag (tree exp, rtx target, enum machine_mode mode, int only_cheap)
       || reg_mentioned_p (target, op0) || reg_mentioned_p (target, op1))
     target = gen_reg_rtx (GET_MODE (target));
 
-  emit_move_insn (target, invert ? const0_rtx : const1_rtx);
+  emit_move_insn (target, invert ? const0_rtx : trueval);
   label = gen_label_rtx ();
   do_compare_rtx_and_jump (op0, op1, code, unsignedp, operand_mode, NULL_RTX,
                           NULL_RTX, label, -1);
 
-  emit_move_insn (target, invert ? const1_rtx : const0_rtx);
+  emit_move_insn (target, invert ? trueval : const0_rtx);
   emit_label (label);
 
   return target;
index 6076dda8183cf092b831cb1d54e02933cb7090b0..254103cd857ecb17ea5cf8a4b80a1bb5a67303ef 100644 (file)
@@ -1,6 +1,12 @@
 2011-07-19  Jakub Jelinek  <jakub@redhat.com>
 
        Backport from mainline
+       2011-05-23  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/48973
+       * gcc.c-torture/execute/pr48973-1.c: New test.
+       * gcc.c-torture/execute/pr48973-2.c: New test.
+
        2011-05-18  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/49039
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr48973-1.c b/gcc/testsuite/gcc.c-torture/execute/pr48973-1.c
new file mode 100644 (file)
index 0000000..02688a0
--- /dev/null
@@ -0,0 +1,20 @@
+/* PR middle-end/48973 */
+
+extern void abort (void);
+struct S { int f : 1; } s;
+int v = -1;
+
+void
+foo (unsigned int x)
+{
+  if (x != -1U)
+    abort ();
+}
+
+int
+main ()
+{
+  s.f = (v & 1) > 0;
+  foo (s.f);
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr48973-2.c b/gcc/testsuite/gcc.c-torture/execute/pr48973-2.c
new file mode 100644 (file)
index 0000000..a64d491
--- /dev/null
@@ -0,0 +1,14 @@
+/* PR middle-end/48973 */
+
+extern void abort (void);
+struct S { int f : 1; } s;
+int v = -1;
+
+int
+main ()
+{
+  s.f = v < 0;
+  if ((unsigned int) s.f != -1U)
+    abort ();
+  return 0;
+}