]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR rtl-optimization/70222 (Test miscompiled with -O1)
authorJakub Jelinek <jakub@redhat.com>
Thu, 7 Jul 2016 21:49:58 +0000 (23:49 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 7 Jul 2016 21:49:58 +0000 (23:49 +0200)
Backported from mainline
2016-03-15  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/70222
* combine.c (simplify_shift_const_1): For A >> B >> C LSHIFTRT
optimization if mode is different from result_mode, queue up masking
of the result in outer_op.  Formatting fix.

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

From-SVN: r238140

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

index 1abaf860f55b468b90d3a3ff29b622a28110b6c3..52b69c8f3ea27e026d10434f48c2dbf2296d9a94 100644 (file)
@@ -1,6 +1,13 @@
 2016-07-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-03-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/70222
+       * combine.c (simplify_shift_const_1): For A >> B >> C LSHIFTRT
+       optimization if mode is different from result_mode, queue up masking
+       of the result in outer_op.  Formatting fix.
+
        2016-03-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/70169
index a22aba7d48e478b253c59f40a0c6c8d9a1ea80ea..c48d9b11e47bd244f8e53b684d07a12b39c9e35e 100644 (file)
@@ -10173,9 +10173,19 @@ simplify_shift_const_1 (enum rtx_code code, enum machine_mode result_mode,
                   && CONST_INT_P (XEXP (varop, 0))
                   && !CONST_INT_P (XEXP (varop, 1)))
            {
+             /* For ((unsigned) (cstULL >> count)) >> cst2 we have to make
+                sure the result will be masked.  See PR70222.  */
+             if (code == LSHIFTRT
+                 && mode != result_mode
+                 && !merge_outer_ops (&outer_op, &outer_const, AND,
+                                      GET_MODE_MASK (result_mode)
+                                      >> orig_count, result_mode,
+                                      &complement_p))
+               break;
+
              rtx new_rtx = simplify_const_binary_operation (code, mode,
-                                                        XEXP (varop, 0),
-                                                        GEN_INT (count));
+                                                            XEXP (varop, 0),
+                                                            GEN_INT (count));
              varop = gen_rtx_fmt_ee (code, mode, new_rtx, XEXP (varop, 1));
              count = 0;
              continue;
index 9a70102ba3e47f056341f5b1d059c932a55c9cf7..dac1b34b1b3b3a64b3f132a555d44d447ec8bfa7 100644 (file)
@@ -1,6 +1,12 @@
 2016-07-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-03-15  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/70222
+       * gcc.c-torture/execute/pr70222-1.c: New test.
+       * gcc.c-torture/execute/pr70222-2.c: New test.
+
        2016-03-11  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/70169
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr70222-1.c b/gcc/testsuite/gcc.c-torture/execute/pr70222-1.c
new file mode 100644 (file)
index 0000000..d79672e
--- /dev/null
@@ -0,0 +1,30 @@
+/* PR rtl-optimization/70222 */
+
+int a = 1;
+unsigned int b = 2;
+int c = 0;
+int d = 0;
+
+void
+foo ()
+{
+  int e = ((-(c >= c)) < b) > ((int) (-1ULL >> ((a / a) * 15)));
+  d = -e;
+}
+
+__attribute__((noinline, noclone)) void
+bar (int x)
+{
+  if (x != -1)
+    __builtin_abort ();
+}
+
+int
+main ()
+{
+#if __CHAR_BIT__ == 8 && __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ == 8
+  foo ();
+  bar (d);
+#endif
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr70222-2.c b/gcc/testsuite/gcc.c-torture/execute/pr70222-2.c
new file mode 100644 (file)
index 0000000..7611c98
--- /dev/null
@@ -0,0 +1,20 @@
+/* PR rtl-optimization/70222 */
+
+#if __CHAR_BIT__ == 8 && __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ == 8
+__attribute__((noinline, noclone)) unsigned int
+foo (int x)
+{
+  unsigned long long y = -1ULL >> x;
+  return (unsigned int) y >> 31;
+}
+#endif
+
+int
+main ()
+{
+#if __CHAR_BIT__ == 8 && __SIZEOF_INT__ == 4 && __SIZEOF_LONG_LONG__ == 8
+  if (foo (15) != 1 || foo (32) != 1 || foo (33) != 0)
+    __builtin_abort ();
+#endif
+  return 0;
+}