rs6000: Wrap diff of immediates in const (PR83629)
authorSegher Boessenkool <segher@kernel.crashing.org>
Wed, 10 Jan 2018 15:13:07 +0000 (16:13 +0100)
committerSegher Boessenkool <segher@gcc.gnu.org>
Wed, 10 Jan 2018 15:13:07 +0000 (16:13 +0100)
In various of our 32-bit load_toc patterns we take the difference of
two immediates (labels) as a term to something bigger; but this isn't
canonical RTL, it needs to be wrapped in CONST.

PR target/83629
* config/rs6000/rs6000.md (load_toc_v4_PIC_2, load_toc_v4_PIC_3b,
load_toc_v4_PIC_3c): Wrap const term in CONST RTL.

testsuite/
PR target/83629
* gcc.target/powerpc/pr83629.c: New testcase.

From-SVN: r256432

gcc/ChangeLog
gcc/config/rs6000/rs6000.md
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.target/powerpc/pr83629.c [new file with mode: 0644]

index 01a89c72ef34a2d803b13df310fe6300147816f2..8b5bda301cab911793466230213f6b3c7db3aac4 100644 (file)
@@ -1,3 +1,9 @@
+2018-01-10  Segher Boessenkool  <segher@kernel.crashing.org>
+
+       PR target/83629
+       * config/rs6000/rs6000.md (load_toc_v4_PIC_2, load_toc_v4_PIC_3b,
+       load_toc_v4_PIC_3c): Wrap const term in CONST RTL.
+
 2018-01-10  Richard Biener  <rguenther@suse.de>
 
        PR debug/83765
index 3d3ead4ec4906e3e6c61db2329b52a33dc756028..b718e209e3a996ce3fa1aacc39db35d010199176 100644 (file)
 
 (define_insn "load_toc_v4_PIC_2"
   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
-       (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
-                  (minus:SI (match_operand:SI 2 "immediate_operand" "s")
-                            (match_operand:SI 3 "immediate_operand" "s")))))]
+       (mem:SI (plus:SI
+                 (match_operand:SI 1 "gpc_reg_operand" "b")
+                 (const
+                   (minus:SI (match_operand:SI 2 "immediate_operand" "s")
+                             (match_operand:SI 3 "immediate_operand" "s"))))))]
   "TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
   "lwz %0,%2-%3(%1)"
   [(set_attr "type" "load")])
 
 (define_insn "load_toc_v4_PIC_3b"
   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
-       (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
-                (high:SI
-                  (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
-                            (match_operand:SI 3 "symbol_ref_operand" "s")))))]
+       (plus:SI
+         (match_operand:SI 1 "gpc_reg_operand" "b")
+         (high:SI
+           (const
+             (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
+                       (match_operand:SI 3 "symbol_ref_operand" "s"))))))]
   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic"
   "addis %0,%1,%2-%3@ha")
 
 (define_insn "load_toc_v4_PIC_3c"
   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
-       (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
-                  (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
-                            (match_operand:SI 3 "symbol_ref_operand" "s"))))]
+       (lo_sum:SI
+         (match_operand:SI 1 "gpc_reg_operand" "b")
+         (const
+           (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
+                     (match_operand:SI 3 "symbol_ref_operand" "s")))))]
   "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic"
   "addi %0,%1,%2-%3@l")
 
index f99a83ddd78336abcc89e278e05ffe55af0f0797..11266ff69eefd3ecb233ca06fd83a4f31a8fada9 100644 (file)
@@ -1,3 +1,8 @@
+2018-01-10  Segher Boessenkool  <segher@kernel.crashing.org>
+
+       PR target/83629
+       * gcc.target/powerpc/pr83629.c: New testcase.
+
 2018-01-10  Richard Biener  <rguenther@suse.de>
 
        PR testsuite/78768
diff --git a/gcc/testsuite/gcc.target/powerpc/pr83629.c b/gcc/testsuite/gcc.target/powerpc/pr83629.c
new file mode 100644 (file)
index 0000000..aeff699
--- /dev/null
@@ -0,0 +1,9 @@
+/* { dg-options "-O2 -fPIC -frename-registers --param=sched-autopref-queue-depth=0 -mcpu=603" } */
+
+extern void bar (void *);
+
+void
+foo (void)
+{
+  bar ("");
+}