]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR rtl-optimization/78378 (wrong code when combining shift + mult +...
authorJakub Jelinek <jakub@redhat.com>
Tue, 30 May 2017 07:40:21 +0000 (09:40 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 30 May 2017 07:40:21 +0000 (09:40 +0200)
Backported from mainline
2016-11-16  Jakub Jelinek  <jakub@redhat.com>

PR rtl-optimization/78378
* combine.c (make_extraction): Use force_to_mode for non-{REG,MEM}
inner only if pos is 0.  Fix up formatting.

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

From-SVN: r248623

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

index 7772c3d7749aadd961dbc12e2494b861e67bf3b0..0f79e4fe0417ece409da3d344b734a41d1413bbd 100644 (file)
@@ -1,6 +1,12 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-11-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/78378
+       * combine.c (make_extraction): Use force_to_mode for non-{REG,MEM}
+       inner only if pos is 0.  Fix up formatting.
+
        2016-11-07  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/78227
index a6c13445858218611d4587b4bec2bd20f9785c5d..936aa756eea999b987eb07b7090ac78118dd1fd4 100644 (file)
@@ -7342,6 +7342,7 @@ make_extraction (machine_mode mode, rtx inner, HOST_WIDE_INT pos,
   if (tmode != BLKmode
       && ((pos_rtx == 0 && (pos % BITS_PER_WORD) == 0
           && !MEM_P (inner)
+          && (pos == 0 || REG_P (inner))
           && (inner_mode == tmode
               || !REG_P (inner)
               || TRULY_NOOP_TRUNCATION_MODES_P (tmode, inner_mode)
@@ -7418,10 +7419,9 @@ make_extraction (machine_mode mode, rtx inner, HOST_WIDE_INT pos,
        }
       else
        new_rtx = force_to_mode (inner, tmode,
-                            len >= HOST_BITS_PER_WIDE_INT
-                            ? ~(unsigned HOST_WIDE_INT) 0
-                            : ((unsigned HOST_WIDE_INT) 1 << len) - 1,
-                            0);
+                                len >= HOST_BITS_PER_WIDE_INT
+                                ? ~(unsigned HOST_WIDE_INT) 0
+                                : ((unsigned HOST_WIDE_INT) 1 << len) - 1, 0);
 
       /* If this extraction is going into the destination of a SET,
         make a STRICT_LOW_PART unless we made a MEM.  */
index 74f7bfdf55d2d52b13dc8beda1dde37fa6152b1f..78d6ccf89c43610b3353589f65c5dbafe1391b76 100644 (file)
@@ -1,6 +1,11 @@
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2016-11-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR rtl-optimization/78378
+       * gcc.c-torture/execute/pr78378.c: New test.
+
        2016-11-07  Jakub Jelinek  <jakub@redhat.com>
 
        PR target/78227
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr78378.c b/gcc/testsuite/gcc.c-torture/execute/pr78378.c
new file mode 100644 (file)
index 0000000..05c1f9c
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR rtl-optimization/78378 */
+
+unsigned long long __attribute__ ((noinline, noclone))
+foo (unsigned long long x)
+{
+  x <<= 41;
+  x /= 232;
+  return 1 + (unsigned short) x;
+}
+
+int
+main ()
+{
+  unsigned long long x = foo (1);
+  if (x != 0x2c24)
+    __builtin_abort();
+  return 0;
+}