[llvm] 4899b8d - [RISCV] Don't require splats to have a single use in performReverseEVLCombine. (#208326)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 21:05:57 PDT 2026
Author: Craig Topper
Date: 2026-07-08T21:05:52-07:00
New Revision: 4899b8d6f6b9d48349d89528ec6898704b289672
URL: https://github.com/llvm/llvm-project/commit/4899b8d6f6b9d48349d89528ec6898704b289672
DIFF: https://github.com/llvm/llvm-project/commit/4899b8d6f6b9d48349d89528ec6898704b289672.diff
LOG: [RISCV] Don't require splats to have a single use in performReverseEVLCombine. (#208326)
Test was written by Claude
Added:
Modified:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/vp-combine-reverse-load.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 0499db029945d..df1692bdf9679 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -19925,14 +19925,14 @@ static SDValue performReverseEVLCombine(SDNode *N,
SmallVector<SDValue> Worklist = {Op};
while (!Worklist.empty()) {
SDValue X = Worklist.pop_back_val();
+ if (DAG.isSplatValue(X))
+ continue;
if (!X.hasOneUser())
return SDValue();
if (auto *VPL = dyn_cast<VPLoadSDNode>(X)) {
if (VPLoad && VPLoad != VPL)
return SDValue();
VPLoad = VPL;
- } else if (DAG.isSplatValue(X)) {
- continue;
} else if (DAG.getTargetLoweringInfo().isBinOp(X.getOpcode()) &&
X->getNumValues() == 1) {
append_range(Worklist, X->op_values());
diff --git a/llvm/test/CodeGen/RISCV/rvv/vp-combine-reverse-load.ll b/llvm/test/CodeGen/RISCV/rvv/vp-combine-reverse-load.ll
index b7235b78f6175..14eb48aa44ceb 100644
--- a/llvm/test/CodeGen/RISCV/rvv/vp-combine-reverse-load.ll
+++ b/llvm/test/CodeGen/RISCV/rvv/vp-combine-reverse-load.ll
@@ -313,3 +313,33 @@ define <vscale x 2 x float> @binop_multiuse(ptr %ptr, i32 zeroext %evl) {
%rev = call <vscale x 2 x float> @llvm.experimental.vp.reverse(<vscale x 2 x float> %fadd, <vscale x 2 x i1> splat (i1 true), i32 %evl)
ret <vscale x 2 x float> %rev
}
+
+; The splat leaf of the binop feeding vp.reverse is the same constant used by
+; an unrelated binop elsewhere in the function, so the splat_vector node ends
+; up with more than one use. That must not prevent the combine: a shared
+; splat constant is not mutated by the fold, so it should still succeed.
+define <vscale x 2 x float> @binop_shared_splat(ptr %ptr, <vscale x 2 x float> %x, i32 zeroext %evl) {
+; CHECK-LABEL: binop_shared_splat:
+; CHECK: # %bb.0:
+; CHECK-NEXT: slli a2, a1, 2
+; CHECK-NEXT: add a0, a2, a0
+; CHECK-NEXT: li a2, -4
+; CHECK-NEXT: addi a0, a0, -4
+; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, ma
+; CHECK-NEXT: vlse32.v v9, (a0), a2
+; CHECK-NEXT: lui a0, 260096
+; CHECK-NEXT: fmv.w.x fa5, a0
+; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, ma
+; CHECK-NEXT: vfadd.vf v9, v9, fa5
+; CHECK-NEXT: vfadd.vf v8, v8, fa5
+; CHECK-NEXT: vfadd.vv v8, v9, v8
+; CHECK-NEXT: ret
+ %load = call <vscale x 2 x float> @llvm.vp.load(ptr %ptr, <vscale x 2 x i1> splat (i1 true), i32 %evl)
+ %fadd = fadd <vscale x 2 x float> %load, splat (float 1.0)
+ %rev = call <vscale x 2 x float> @llvm.experimental.vp.reverse(<vscale x 2 x float> %fadd, <vscale x 2 x i1> splat (i1 true), i32 %evl)
+
+ %other = fadd <vscale x 2 x float> %x, splat (float 1.0)
+
+ %sum = fadd <vscale x 2 x float> %rev, %other
+ ret <vscale x 2 x float> %sum
+}
More information about the llvm-commits
mailing list