Skip to content

Commit d01c051

Browse files
authored
[RISCV] Fix vmerge.vvm/vmv.v.v getting folded into ops with mismatching EEW (#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 #100367
1 parent 8f7910a commit d01c051

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
@@ -3733,6 +3733,10 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
37333733
assert(!Mask || cast<RegisterSDNode>(Mask)->getReg() == RISCV::V0);
37343734
assert(!Glue || Glue.getValueType() == MVT::Glue);
37353735

3736+
// If the EEW of True is different from vmerge's SEW, then we can't fold.
3737+
if (True.getSimpleValueType() != N->getSimpleValueType(0))
3738+
return false;
3739+
37363740
// We require that either passthru and false are the same, or that passthru
37373741
// is undefined.
37383742
if (Passthru != False && !isImplicitDef(Passthru))

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+
}

llvm/test/CodeGen/RISCV/rvv/vmv.v.v-peephole.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,17 @@ define <vscale x 2 x i32> @unfoldable_vredsum(<vscale x 2 x i32> %passthru, <vsc
180180
%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)
181181
ret <vscale x 2 x i32> %b
182182
}
183+
184+
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) {
185+
; CHECK-LABEL: unfoldable_mismatched_sew:
186+
; CHECK: # %bb.0:
187+
; CHECK-NEXT: vsetvli zero, a0, e64, m1, ta, ma
188+
; CHECK-NEXT: vadd.vv v9, v9, v10
189+
; CHECK-NEXT: vsetvli zero, a0, e32, m1, tu, ma
190+
; CHECK-NEXT: vmv.v.v v8, v9
191+
; CHECK-NEXT: ret
192+
%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)
193+
%a.bitcast = bitcast <vscale x 1 x i64> %a to <vscale x 2 x i32>
194+
%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)
195+
ret <vscale x 2 x i32> %b
196+
}

0 commit comments

Comments
 (0)