]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/77309 (wrong code at -Os and above on x86_64-linux...
authorBernd Schmidt <bernds@redhat.com>
Mon, 12 Dec 2016 13:01:28 +0000 (13:01 +0000)
committerBernd Schmidt <bernds@gcc.gnu.org>
Mon, 12 Dec 2016 13:01:28 +0000 (13:01 +0000)
Backport from mainline
2016-11-07  Bernd Schmidt  <bschmidt@redhat.com>

        PR rtl-optimization/77309
        * combine.c (make_compound_operation): Allow EQ for IN_CODE, and
        don't assume an equality comparison for plain COMPARE.
        (simplify_comparison): Pass a more accurate code to
        make_compound_operation.

        PR rtl-optimization/77309
        * gcc.dg/torture/pr77309.c: New test.

From-SVN: r243550

gcc/ChangeLog
gcc/combine.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr77309.c [new file with mode: 0644]

index f47615b4225c8562b8c0311743f75743c0f2b63d..a6b3df545cdecc8d185ad5ece3b208bb9df5629f 100644 (file)
@@ -1,3 +1,14 @@
+2016-12-12  Bernd Schmidt  <bschmidt@redhat.com>
+
+       Backport from mainline
+       2016-11-07  Bernd Schmidt  <bschmidt@redhat.com>
+
+        PR rtl-optimization/77309
+        * combine.c (make_compound_operation): Allow EQ for IN_CODE, and
+        don't assume an equality comparison for plain COMPARE.
+        (simplify_comparison): Pass a more accurate code to
+        make_compound_operation.
+
 2016-12-07  Segher Boessenkool  <segher@kernel.crashing.org>
 
        Backport from mainline
index fb3215370deb4a7ec5f92d064b7a439eb9b79b4e..a6c13445858218611d4587b4bec2bd20f9785c5d 100644 (file)
@@ -7726,10 +7726,12 @@ extract_left_shift (rtx x, int count)
 
    We try, as much as possible, to re-use rtl expressions to save memory.
 
-   IN_CODE says what kind of expression we are processing.  Normally, it is
-   SET.  In a memory address (inside a MEM, PLUS or minus, the latter two
-   being kludges), it is MEM.  When processing the arguments of a comparison
-   or a COMPARE against zero, it is COMPARE.  */
+   IN_CODE says what kind of expression we are processing.  Normally,
+   it is SET.  In a memory address (inside a MEM, PLUS or minus, the
+   latter two being kludges), it is MEM.  When processing the
+   arguments of a comparison or a COMPARE against zero, it is COMPARE,
+   or EQ if more + precisely it is an equality comparison against
+   zero..  */
 
 rtx
 make_compound_operation (rtx x, enum rtx_code in_code)
@@ -7743,11 +7745,17 @@ make_compound_operation (rtx x, enum rtx_code in_code)
   rtx new_rtx = 0;
   rtx tem;
   const char *fmt;
+  bool equality_comparison = false;
 
   /* Select the code to be used in recursive calls.  Once we are inside an
      address, we stay there.  If we have a comparison, set to COMPARE,
      but once inside, go back to our default of SET.  */
 
+  if (in_code == EQ)
+    {
+      equality_comparison = true;
+      in_code = COMPARE;
+    }
   next_code = (code == MEM ? MEM
               : ((code == PLUS || code == MINUS)
                  && SCALAR_INT_MODE_P (mode)) ? MEM
@@ -7935,11 +7943,12 @@ make_compound_operation (rtx x, enum rtx_code in_code)
       /* If we are in a comparison and this is an AND with a power of two,
         convert this into the appropriate bit extract.  */
       else if (in_code == COMPARE
-              && (i = exact_log2 (UINTVAL (XEXP (x, 1)))) >= 0)
+              && (i = exact_log2 (UINTVAL (XEXP (x, 1)))) >= 0
+              && (equality_comparison || i < GET_MODE_PRECISION (mode) - 1))
        new_rtx = make_extraction (mode,
-                              make_compound_operation (XEXP (x, 0),
-                                                       next_code),
-                              i, NULL_RTX, 1, 1, 0, 1);
+                                  make_compound_operation (XEXP (x, 0),
+                                                           next_code),
+                                  i, NULL_RTX, 1, 1, 0, 1);
 
       break;
 
@@ -12253,7 +12262,11 @@ simplify_comparison (enum rtx_code code, rtx *pop0, rtx *pop1)
      We can never remove a SUBREG for a non-equality comparison because
      the sign bit is in a different place in the underlying object.  */
 
-  op0 = make_compound_operation (op0, op1 == const0_rtx ? COMPARE : SET);
+  rtx_code op0_mco_code = SET;
+  if (op1 == const0_rtx)
+    op0_mco_code = code == NE || code == EQ ? EQ : COMPARE;
+
+  op0 = make_compound_operation (op0, op0_mco_code);
   op1 = make_compound_operation (op1, SET);
 
   if (GET_CODE (op0) == SUBREG && subreg_lowpart_p (op0)
index c560323c275f46b853ace2a0b5940b59269aae12..f09906befb99485bc44acc018b2e8e3718738e72 100644 (file)
@@ -1,3 +1,11 @@
+2016-12-12  Bernd Schmidt  <bschmidt@redhat.com>
+
+       Backport from mainline
+       2016-11-07  Bernd Schmidt  <bschmidt@redhat.com>
+
+        PR rtl-optimization/77309
+        * gcc.dg/torture/pr77309.c: New test.
+
 2016-12-08  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/78551
diff --git a/gcc/testsuite/gcc.dg/torture/pr77309.c b/gcc/testsuite/gcc.dg/torture/pr77309.c
new file mode 100644 (file)
index 0000000..5bdbc0a
--- /dev/null
@@ -0,0 +1,14 @@
+/* { dg-do run } */
+
+int a, b;
+
+int main ()
+{
+  long c = 1 % (2 ^ b);
+  c = -c & ~(~(b ^ ~b) || a);
+
+  if (c >= 0)
+    __builtin_abort ();
+
+  return 0;
+}