[llvm] [RISCV] Match mul_vl(v, (add_vl v1, splat 1)) to vmadd_vl (PR #71495)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 6 23:48:24 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Liao Chunyu (ChunyuLiao)
<details>
<summary>Changes</summary>
Comparison with gcc: https://gcc.godbolt.org/z/xjePx87Y7
---
Full diff: https://github.com/llvm/llvm-project/pull/71495.diff
2 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td (+18)
- (modified) llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll (+15)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
index d92d3975d12f533..bd4a08cd3859398 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td
@@ -2292,6 +2292,24 @@ defm : VPatMultiplyAddVL_VV_VX<riscv_sub_vl, "PseudoVNMSUB">;
defm : VPatMultiplyAccVL_VV_VX<riscv_add_vl_oneuse, "PseudoVMACC">;
defm : VPatMultiplyAccVL_VV_VX<riscv_sub_vl_oneuse, "PseudoVNMSAC">;
+// mul_vl(v, (add_vl v1, splat 1)) is a special case of vmadd.
+foreach vti = AllIntegerVectors in {
+ let Predicates = GetVTypePredicates<vti>.Predicates in {
+ // NOTE: We choose VMADD because it has the most commuting freedom. So it
+ // works best with how TwoAddressInstructionPass tries commuting.
+ def : Pat<(vti.Vector
+ (riscv_mul_vl vti.RegClass:$rs1,
+ (riscv_add_vl_oneuse vti.RegClass:$rd,
+ (vti.Vector (riscv_vmv_v_x_vl
+ (vti.Vector undef), 1, VLOpFrag)),
+ srcvalue, (vti.Mask true_mask), VLOpFrag),
+ srcvalue, (vti.Mask true_mask), VLOpFrag)),
+ (!cast<Instruction>("PseudoVMADD_VV_"#vti.LMul.MX)
+ vti.RegClass:$rd, vti.RegClass:$rs1, vti.RegClass:$rs1,
+ GPR:$vl, vti.Log2SEW, TAIL_AGNOSTIC)>;
+ }
+}
+
// 11.14. Vector Widening Integer Multiply-Add Instructions
defm : VPatWidenMultiplyAddVL_VV_VX<riscv_vwmacc_vl, "PseudoVWMACC">;
defm : VPatWidenMultiplyAddVL_VV_VX<riscv_vwmaccu_vl, "PseudoVWMACCU">;
diff --git a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll
index c95d144a970895c..a7f7f8c4a8136c9 100644
--- a/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll
@@ -8237,3 +8237,18 @@ define void @mulhs_vx_v2i64(ptr %x) {
store <2 x i64> %b, ptr %x
ret void
}
+
+define void @madd_vv_v2i64(ptr %x, <2 x i64> %y) {
+; CHECK-LABEL: madd_vv_v2i64:
+; CHECK: # %bb.0:
+; CHECK-NEXT: vsetivli zero, 2, e64, m1, ta, ma
+; CHECK-NEXT: vle64.v v9, (a0)
+; CHECK-NEXT: vmadd.vv v9, v8, v8
+; CHECK-NEXT: vse64.v v9, (a0)
+; CHECK-NEXT: ret
+ %a = load <2 x i64>, ptr %x
+ %b = add <2 x i64> %a, <i64 1, i64 1>
+ %c = mul <2 x i64> %b, %y
+ store <2 x i64> %c, ptr %x
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/71495
More information about the llvm-commits
mailing list