[llvm] [RISCV] Implement codegen for XAndesPerf lea instructions (PR #137925)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 30 09:45:49 PDT 2025


================
@@ -659,30 +659,103 @@ def : Pat<(i32 (and GPR:$rs, 0xFFFF)), (PACK GPR:$rs, (XLenVT X0))>;
 let Predicates = [HasStdExtZbkb, NoStdExtZbb, IsRV64] in
 def : Pat<(i64 (and GPR:$rs, 0xFFFF)), (PACKW GPR:$rs, (XLenVT X0))>;
 
-let Predicates = [HasStdExtZba] in {
+multiclass ShxAddPat<int i, Instruction shxadd> {
+def : Pat<(XLenVT (add_like_non_imm12 (shl GPR:$rs1, (XLenVT i)), GPR:$rs2)),
+          (shxadd GPR:$rs1, GPR:$rs2)>;
+def : Pat<(XLenVT (riscv_shl_add GPR:$rs1, (XLenVT i), GPR:$rs2)),
+          (shxadd GPR:$rs1, GPR:$rs2)>;
 
-foreach i = {1,2,3} in {
-  defvar shxadd = !cast<Instruction>("SH"#i#"ADD");
-  def : Pat<(XLenVT (add_like_non_imm12 (shl GPR:$rs1, (XLenVT i)), GPR:$rs2)),
-            (shxadd GPR:$rs1, GPR:$rs2)>;
-  def : Pat<(XLenVT (riscv_shl_add GPR:$rs1, (XLenVT i), GPR:$rs2)),
-            (shxadd GPR:$rs1, GPR:$rs2)>;
-
-  defvar pat = !cast<ComplexPattern>("sh"#i#"add_op");
-  // More complex cases use a ComplexPattern.
-  def : Pat<(XLenVT (add_like_non_imm12 pat:$rs1, GPR:$rs2)),
-            (shxadd pat:$rs1, GPR:$rs2)>;
+defvar pat = !cast<ComplexPattern>("sh"#i#"add_op");
+// More complex cases use a ComplexPattern.
+def : Pat<(XLenVT (add_like_non_imm12 pat:$rs1, GPR:$rs2)),
+          (shxadd pat:$rs1, GPR:$rs2)>;
 }
 
-def : Pat<(add_like (XLenVT GPR:$r), CSImm12MulBy4:$i),
-          (SH2ADD (XLenVT (ADDI (XLenVT X0), CSImm12MulBy4:$i)),
+class CSImm12MulBy4Pat<Instruction sh2add>
+    : Pat<(add_like (XLenVT GPR:$r), CSImm12MulBy4:$i),
+          (sh2add (XLenVT (ADDI (XLenVT X0), CSImm12MulBy4:$i)),
                   GPR:$r)>;
-def : Pat<(add_like (XLenVT GPR:$r), CSImm12MulBy8:$i),
-          (SH3ADD (XLenVT (ADDI (XLenVT X0), CSImm12MulBy8:$i)),
+
+class CSImm12MulBy8Pat<Instruction sh3add>
+    : Pat<(add_like (XLenVT GPR:$r), CSImm12MulBy8:$i),
+          (sh3add (XLenVT (ADDI (XLenVT X0), CSImm12MulBy8:$i)),
                   GPR:$r)>;
 
+let Predicates = [HasStdExtZba] in {
+
----------------
topperc wrote:

Remove this blank line and indent everything in this `let` by 2 spaces

https://github.com/llvm/llvm-project/pull/137925


More information about the llvm-commits mailing list