Skip to content

Commit c48a5c8

Browse files
committed
[RISCV] Fix vmerge.vvm/vmv.v.v getting folded into ops with mismatching EEW
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. This is incorrect if we end up changing the mask or AVL of the op. This gets 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 ef618b7 commit c48a5c8

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3855,11 +3855,19 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
38553855
// If we end up changing the VL or mask of True, then we need to make sure it
38563856
// doesn't raise any observable fp exceptions, since changing the active
38573857
// elements will affect how fflags is set.
3858-
if (TrueVL != VL || !IsMasked)
3858+
if (TrueVL != VL || !IsMasked) {
38593859
if (mayRaiseFPException(True.getNode()) &&
38603860
!True->getFlags().hasNoFPExcept())
38613861
return false;
38623862

3863+
// If the EEW of True is different from vmerge's SEW, then we cannot change
3864+
// the VL or mask.
3865+
if (Log2_64(True.getSimpleValueType().getScalarSizeInBits()) !=
3866+
N->getConstantOperandVal(
3867+
RISCVII::getSEWOpNum(TII->get(N->getMachineOpcode())) - 1))
3868+
return false;
3869+
}
3870+
38633871
SDLoc DL(N);
38643872

38653873
// From the preconditions we checked above, we know the mask and thus glue

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,10 @@ define <vscale x 2 x i32> @true_mask_vmerge_implicit_passthru(<vscale x 2 x i32>
12001200
define <vscale x 2 x i32> @unfoldable_mismatched_sew_mask(<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) {
12011201
; CHECK-LABEL: unfoldable_mismatched_sew_mask:
12021202
; CHECK: # %bb.0:
1203-
; CHECK-NEXT: vsetvli zero, a0, e64, m1, tu, mu
1204-
; CHECK-NEXT: vadd.vv v8, v9, v10, v0.t
1203+
; CHECK-NEXT: vsetvli zero, a0, e64, m1, ta, ma
1204+
; CHECK-NEXT: vadd.vv v9, v9, v10
1205+
; CHECK-NEXT: vsetvli zero, a0, e32, m1, tu, ma
1206+
; CHECK-NEXT: vmerge.vvm v8, v8, v9, v0
12051207
; CHECK-NEXT: ret
12061208
%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)
12071209
%a.bitcast = bitcast <vscale x 1 x i64> %a to <vscale x 2 x i32>
@@ -1218,8 +1220,10 @@ define <vscale x 2 x i32> @unfoldable_mismatched_sew_mask(<vscale x 2 x i32> %pa
12181220
define <vscale x 2 x i32> @unfoldable_mismatched_sew_avl(<vscale x 2 x i32> %passthru, <vscale x 1 x i64> %x, <vscale x 1 x i64> %y) {
12191221
; CHECK-LABEL: unfoldable_mismatched_sew_avl:
12201222
; CHECK: # %bb.0:
1221-
; CHECK-NEXT: vsetivli zero, 3, e64, m1, tu, ma
1222-
; CHECK-NEXT: vadd.vv v8, v9, v10
1223+
; CHECK-NEXT: vsetivli zero, 5, e64, m1, ta, ma
1224+
; CHECK-NEXT: vadd.vv v9, v9, v10
1225+
; CHECK-NEXT: vsetivli zero, 3, e32, m1, tu, ma
1226+
; CHECK-NEXT: vmv.v.v v8, v9
12231227
; CHECK-NEXT: ret
12241228
%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 5)
12251229
%a.bitcast = bitcast <vscale x 1 x i64> %a to <vscale x 2 x i32>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,10 @@ define <vscale x 2 x i32> @unfoldable_vredsum(<vscale x 2 x i32> %passthru, <vsc
184184
define <vscale x 2 x i32> @unfoldable_mismatched_sew_diff_vl(<vscale x 2 x i32> %passthru, <vscale x 1 x i64> %x, <vscale x 1 x i64> %y) {
185185
; CHECK-LABEL: unfoldable_mismatched_sew_diff_vl:
186186
; CHECK: # %bb.0:
187-
; CHECK-NEXT: vsetivli zero, 3, e64, m1, tu, ma
188-
; CHECK-NEXT: vadd.vv v8, v9, v10
187+
; CHECK-NEXT: vsetivli zero, 6, e64, m1, ta, ma
188+
; CHECK-NEXT: vadd.vv v9, v9, v10
189+
; CHECK-NEXT: vsetivli zero, 3, e32, m1, tu, ma
190+
; CHECK-NEXT: vmv.v.v v8, v9
189191
; CHECK-NEXT: ret
190192
%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 6)
191193
%a.bitcast = bitcast <vscale x 1 x i64> %a to <vscale x 2 x i32>

0 commit comments

Comments
 (0)