Blame SOURCES/gcc12-pr105991.patch

0fe1ac
commit 6c175b3d170de2bb02b7bd45b3348eec05d28451
0fe1ac
Author: Roger Sayle <roger@nextmovesoftware.com>
0fe1ac
Date:   Mon Jul 4 13:58:37 2022 +0100
0fe1ac
0fe1ac
    PR target/105991: Recognize PLUS and XOR forms of rldimi in rs6000.md.
0fe1ac
    
0fe1ac
    This patch addresses PR target/105991 where a change to prefer representing
0fe1ac
    shifts and adds at the tree-level as multiplications, causes problems for
0fe1ac
    the rldimi patterns in the powerpc backend.  The issue is that rs6000.md
0fe1ac
    models this pattern using IOR, and some variants that have the equivalent
0fe1ac
    PLUS or XOR in the RTL fail to match some *rotl<mode>4_insert patterns.
0fe1ac
    This is fixed in this patch by adding a define_insn_and_split to locally
0fe1ac
    canonicalize the PLUS and XOR forms to the backend's preferred IOR form.
0fe1ac
    
0fe1ac
    Backported from master.
0fe1ac
    
0fe1ac
    2022-07-04  Roger Sayle  <roger@nextmovesoftware.com>
0fe1ac
                Marek Polacek  <polacek@redhat.com>
0fe1ac
                Segher Boessenkool  <segher@kernel.crashing.org>
0fe1ac
                Kewen Lin  <linkw@linux.ibm.com>
0fe1ac
    
0fe1ac
    gcc/ChangeLog
0fe1ac
            PR target/105991
0fe1ac
            * config/rs6000/rs6000.md (rotl<mode>3_insert_3): Check that
0fe1ac
            exact_log2 doesn't return -1 (or zero).
0fe1ac
            (plus_xor): New code iterator.
0fe1ac
            (*rotl<mode>3_insert_3_): New define_insn_and_split.
0fe1ac
    
0fe1ac
    gcc/testsuite/ChangeLog
0fe1ac
            PR target/105991
0fe1ac
            * gcc.target/powerpc/pr105991.c: New test case.
0fe1ac
0fe1ac
diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md
0fe1ac
index 64049a6e521..6082ded8c31 100644
0fe1ac
--- a/gcc/config/rs6000/rs6000.md
0fe1ac
+++ b/gcc/config/rs6000/rs6000.md
0fe1ac
@@ -4178,7 +4178,8 @@ (define_insn "rotl<mode>3_insert_3"
0fe1ac
 			  (match_operand:GPR 4 "const_int_operand" "n"))
0fe1ac
 		 (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
0fe1ac
 			     (match_operand:SI 2 "const_int_operand" "n"))))]
0fe1ac
-  "INTVAL (operands[2]) == exact_log2 (UINTVAL (operands[4]) + 1)"
0fe1ac
+  "INTVAL (operands[2]) > 0
0fe1ac
+   && INTVAL (operands[2]) == exact_log2 (UINTVAL (operands[4]) + 1)"
0fe1ac
 {
0fe1ac
   if (<MODE>mode == SImode)
0fe1ac
     return "rlwimi %0,%1,%h2,0,31-%h2";
0fe1ac
@@ -4187,6 +4188,24 @@ (define_insn "rotl<mode>3_insert_3"
0fe1ac
 }
0fe1ac
   [(set_attr "type" "insert")])
0fe1ac
 
0fe1ac
+; Canonicalize the PLUS and XOR forms to IOR for rotl<mode>3_insert_3
0fe1ac
+(define_code_iterator plus_xor [plus xor])
0fe1ac
+
0fe1ac
+(define_insn_and_split "*rotl<mode>3_insert_3_"
0fe1ac
+  [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
0fe1ac
+	(plus_xor:GPR
0fe1ac
+	  (and:GPR (match_operand:GPR 3 "gpc_reg_operand" "0")
0fe1ac
+		   (match_operand:GPR 4 "const_int_operand" "n"))
0fe1ac
+	  (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
0fe1ac
+		      (match_operand:SI 2 "const_int_operand" "n"))))]
0fe1ac
+  "INTVAL (operands[2]) > 0
0fe1ac
+   && INTVAL (operands[2]) == exact_log2 (UINTVAL (operands[4]) + 1)"
0fe1ac
+  "#"
0fe1ac
+  "&& 1"
0fe1ac
+  [(set (match_dup 0)
0fe1ac
+	(ior:GPR (and:GPR (match_dup 3) (match_dup 4))
0fe1ac
+		 (ashift:GPR (match_dup 1) (match_dup 2))))])
0fe1ac
+
0fe1ac
 (define_code_iterator plus_ior_xor [plus ior xor])
0fe1ac
 
0fe1ac
 (define_split
0fe1ac
diff --git a/gcc/testsuite/gcc.target/powerpc/pr105991.c b/gcc/testsuite/gcc.target/powerpc/pr105991.c
0fe1ac
new file mode 100644
0fe1ac
index 00000000000..0d9d130cb63
0fe1ac
--- /dev/null
0fe1ac
+++ b/gcc/testsuite/gcc.target/powerpc/pr105991.c
0fe1ac
@@ -0,0 +1,12 @@
0fe1ac
+/* { dg-do compile } */
0fe1ac
+/* { dg-options "-O2" } */
0fe1ac
+/* { dg-require-effective-target lp64 } */
0fe1ac
+unsigned long long
0fe1ac
+foo (unsigned long long value)
0fe1ac
+{
0fe1ac
+  value &= 0xffffffff;
0fe1ac
+  value |= value << 32;
0fe1ac
+  return value;
0fe1ac
+}
0fe1ac
+/* { dg-final { scan-assembler {\mrldimi\M} } } */
0fe1ac
+