Blame SOURCES/gcc12-pr105991.patch

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