]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR rtl-optimization/70429 (Wrong code with -O1.)
authorJakub Jelinek <jakub@redhat.com>
Thu, 7 Jul 2016 21:50:41 +0000 (23:50 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 7 Jul 2016 21:50:41 +0000 (23:50 +0200)
Backported from mainline
2016-03-29  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/70429
* combine.c (simplify_shift_const_1): For ASHIFTRT don't optimize
(cst1 >> count) >> cst2 into (cst1 >> cst2) >> count if
mode != result_mode.

* gcc.c-torture/execute/pr70429.c: New test.

From-SVN: r238141

gcc/ChangeLog
gcc/combine.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/pr70429.c [new file with mode: 0644]

index 52b69c8f3ea27e026d10434f48c2dbf2296d9a94..1dbd3df30629af3e632899eb4855687bb594ccba 100644 (file)
@@ -1,6 +1,13 @@
 2016-07-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-03-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/70429
+       * combine.c (simplify_shift_const_1): For ASHIFTRT don't optimize
+       (cst1 >> count) >> cst2 into (cst1 >> cst2) >> count if
+       mode != result_mode.
+
        2016-03-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/70222
index c48d9b11e47bd244f8e53b684d07a12b39c9e35e..d2f00d1b7e7dbc66b7541ed361ac369792e81c7f 100644 (file)
@@ -10182,6 +10182,11 @@ simplify_shift_const_1 (enum rtx_code code, enum machine_mode result_mode,
                                       >> orig_count, result_mode,
                                       &complement_p))
                break;
+             /* For ((int) (cstLL >> count)) >> cst2 just give up.  Queuing
+                up outer sign extension (often left and right shift) is
+                hardly more efficient than the original.  See PR70429.  */
+             if (code == ASHIFTRT && mode != result_mode)
+               break;
 
              rtx new_rtx = simplify_const_binary_operation (code, mode,
                                                             XEXP (varop, 0),
index dac1b34b1b3b3a64b3f132a555d44d447ec8bfa7..888311c89cf006a83bbf1aa7616ac0babb78524a 100644 (file)
@@ -1,6 +1,11 @@
 2016-07-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-03-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/70429
+       * gcc.c-torture/execute/pr70429.c: New test.
+
        2016-03-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR rtl-optimization/70222
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr70429.c b/gcc/testsuite/gcc.c-torture/execute/pr70429.c
new file mode 100644 (file)
index 0000000..6b08c8e
--- /dev/null
@@ -0,0 +1,17 @@
+/* PR rtl-optimization/70429 */
+
+__attribute__((noinline, noclone)) int
+foo (int a)
+{
+  return (int) (0x14ff6e2207db5d1fLL >> a) >> 4;
+}
+
+int
+main ()
+{
+  if (sizeof (int) != 4 || sizeof (long long) != 8 || __CHAR_BIT__ != 8)
+    return 0;
+  if (foo (1) != 0x3edae8 || foo (2) != -132158092)
+    __builtin_abort ();
+  return 0;
+}