Skip to content

Commit 6b52570

Browse files
lukel97tru
authored andcommitted
[RISCV] Fix vmerge.vvm/vmv.v.v getting folded into ops with mismatching EEW (llvm#101152)
As noted in https://github.com/llvm/llvm-project/pull/100367/files#r1695448771, we currently fold in vmerge.vvms and vmv.v.vs into their ops even if the EEW is different which leads to an incorrect transform. This checks the op's EEW via its simple value type for now since there doesn't seem to be any existing information about the EEW size of instructions. We'll probably need to encode this at some point if we want to be able to access it at the MachineInstr level in llvm#100367
1 parent 7fa3ba5 commit 6b52570

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3721,6 +3721,10 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
37213721
assert(!Mask || cast<RegisterSDNode>(Mask)->getReg() == RISCV::V0);
37223722
assert(!Glue || Glue.getValueType() == MVT::Glue);
37233723

3724+
// If the EEW of True is different from vmerge's SEW, then we can't fold.
3725+
if (True.getSimpleValueType() != N->getSimpleValueType(0))
3726+
return false;
3727+
37243728
// We require that either merge and false are the same, or that merge
37253729
// is undefined.
37263730
if (Merge != False && !isImplicitDef(Merge))

llvm/test/CodeGen/RISCV/rvv/combine-vmv.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,17 @@ define <vscale x 2 x i32> @unfoldable_vredsum(<vscale x 2 x i32> %passthru, <vsc
168168
%b = call <vscale x 2 x i32> @llvm.riscv.vmv.v.v.nxv2i32(<vscale x 2 x i32> %passthru, <vscale x 2 x i32> %a, iXLen 1)
169169
ret <vscale x 2 x i32> %b
170170
}
171+
172+
define <vscale x 2 x i32> @unfoldable_mismatched_sew(<vscale x 2 x i32> %passthru, <vscale x 1 x i64> %x, <vscale x 1 x i64> %y, iXLen %avl) {
173+
; CHECK-LABEL: unfoldable_mismatched_sew:
174+
; CHECK: # %bb.0:
175+
; CHECK-NEXT: vsetvli zero, a0, e64, m1, ta, ma
176+
; CHECK-NEXT: vadd.vv v9, v9, v10
177+
; CHECK-NEXT: vsetvli zero, a0, e32, m1, tu, ma
178+
; CHECK-NEXT: vmv.v.v v8, v9
179+
; CHECK-NEXT: ret
180+
%a = call <vscale x 1 x i64> @llvm.riscv.vadd.nxv1i64.nxv1i64(<vscale x 1 x i64> poison, <vscale x 1 x i64> %x, <vscale x 1 x i64> %y, iXLen %avl)
181+
%a.bitcast = bitcast <vscale x 1 x i64> %a to <vscale x 2 x i32>
182+
%b = call <vscale x 2 x i32> @llvm.riscv.vmv.v.v.nxv2i32(<vscale x 2 x i32> %passthru, <vscale x 2 x i32> %a.bitcast, iXLen %avl)
183+
ret <vscale x 2 x i32> %b
184+
}

llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-vops.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,3 +1196,24 @@ define <vscale x 2 x i32> @true_mask_vmerge_implicit_passthru(<vscale x 2 x i32>
11961196
)
11971197
ret <vscale x 2 x i32> %b
11981198
}
1199+
1200+
1201+
define <vscale x 2 x i32> @unfoldable_mismatched_sew(<vscale x 2 x i32> %passthru, <vscale x 1 x i64> %x, <vscale x 1 x i64> %y, <vscale x 2 x i1> %mask, i64 %avl) {
1202+
; CHECK-LABEL: unfoldable_mismatched_sew:
1203+
; CHECK: # %bb.0:
1204+
; CHECK-NEXT: vsetvli zero, a0, e64, m1, ta, ma
1205+
; CHECK-NEXT: vadd.vv v9, v9, v10
1206+
; CHECK-NEXT: vsetvli zero, a0, e32, m1, tu, ma
1207+
; CHECK-NEXT: vmv.v.v v8, v9
1208+
; CHECK-NEXT: ret
1209+
%a = call <vscale x 1 x i64> @llvm.riscv.vadd.nxv1i64.nxv1i64(<vscale x 1 x i64> poison, <vscale x 1 x i64> %x, <vscale x 1 x i64> %y, i64 %avl)
1210+
%a.bitcast = bitcast <vscale x 1 x i64> %a to <vscale x 2 x i32>
1211+
%b = call <vscale x 2 x i32> @llvm.riscv.vmerge.nxv2i32.nxv2i32(
1212+
<vscale x 2 x i32> %passthru,
1213+
<vscale x 2 x i32> %passthru,
1214+
<vscale x 2 x i32> %a.bitcast,
1215+
<vscale x 2 x i1> splat (i1 true),
1216+
i64 %avl
1217+
)
1218+
ret <vscale x 2 x i32> %b
1219+
}

0 commit comments

Comments
 (0)