Skip to content

Commit 0207270

Browse files
authored
[RISCV] Don't remove extends for i1 indices in mgather/mscatter (llvm#83951)
1 parent 55c466d commit 0207270

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20042,11 +20042,12 @@ Value *RISCVTargetLowering::emitMaskedAtomicCmpXchgIntrinsic(
2004220042

2004320043
bool RISCVTargetLowering::shouldRemoveExtendFromGSIndex(SDValue Extend,
2004420044
EVT DataVT) const {
20045-
// We have indexed loads for all legal index types. Indices are always
20046-
// zero extended
20045+
// We have indexed loads for all supported EEW types. Indices are always
20046+
// zero extended.
2004720047
return Extend.getOpcode() == ISD::ZERO_EXTEND &&
20048-
isTypeLegal(Extend.getValueType()) &&
20049-
isTypeLegal(Extend.getOperand(0).getValueType());
20048+
isTypeLegal(Extend.getValueType()) &&
20049+
isTypeLegal(Extend.getOperand(0).getValueType()) &&
20050+
Extend.getOperand(0).getValueType().getVectorElementType() != MVT::i1;
2005020051
}
2005120052

2005220053
bool RISCVTargetLowering::shouldConvertFpToSat(unsigned Op, EVT FPVT,

llvm/test/CodeGen/RISCV/rvv/mgather-sdnode.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2153,3 +2153,19 @@ define <vscale x 32 x i8> @mgather_baseidx_nxv32i8(ptr %base, <vscale x 32 x i8>
21532153
%v = call <vscale x 32 x i8> @llvm.masked.gather.nxv32i8.nxv32p0(<vscale x 32 x ptr> %ptrs, i32 2, <vscale x 32 x i1> %m, <vscale x 32 x i8> %passthru)
21542154
ret <vscale x 32 x i8> %v
21552155
}
2156+
2157+
define <vscale x 1 x i8> @mgather_baseidx_zext_nxv1i1_nxv1i8(ptr %base, <vscale x 1 x i1> %idxs, <vscale x 1 x i1> %m, <vscale x 1 x i8> %passthru) {
2158+
; CHECK-LABEL: mgather_baseidx_zext_nxv1i1_nxv1i8:
2159+
; CHECK: # %bb.0:
2160+
; CHECK-NEXT: vsetvli a1, zero, e8, mf8, ta, mu
2161+
; CHECK-NEXT: vmv.v.i v10, 0
2162+
; CHECK-NEXT: vmerge.vim v10, v10, 1, v0
2163+
; CHECK-NEXT: vmv1r.v v0, v8
2164+
; CHECK-NEXT: vluxei8.v v9, (a0), v10, v0.t
2165+
; CHECK-NEXT: vmv1r.v v8, v9
2166+
; CHECK-NEXT: ret
2167+
%eidxs = zext <vscale x 1 x i1> %idxs to <vscale x 1 x i8>
2168+
%ptrs = getelementptr inbounds i8, ptr %base, <vscale x 1 x i8> %eidxs
2169+
%v = call <vscale x 1 x i8> @llvm.masked.gather.nxv1i8.nxv1p0(<vscale x 1 x ptr> %ptrs, i32 1, <vscale x 1 x i1> %m, <vscale x 1 x i8> %passthru)
2170+
ret <vscale x 1 x i8> %v
2171+
}

llvm/test/CodeGen/RISCV/rvv/mscatter-sdnode.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1831,3 +1831,18 @@ define void @mscatter_baseidx_nxv16i16_nxv16f64(<vscale x 8 x double> %val0, <vs
18311831
call void @llvm.masked.scatter.nxv16f64.nxv16p0(<vscale x 16 x double> %v1, <vscale x 16 x ptr> %ptrs, i32 8, <vscale x 16 x i1> %m)
18321832
ret void
18331833
}
1834+
1835+
define void @mscatter_baseidx_zext_nxv1i1_nxv1i8(<vscale x 1 x i8> %val, ptr %base, <vscale x 1 x i1> %idxs, <vscale x 1 x i1> %m) {
1836+
; CHECK-LABEL: mscatter_baseidx_zext_nxv1i1_nxv1i8:
1837+
; CHECK: # %bb.0:
1838+
; CHECK-NEXT: vsetvli a1, zero, e8, mf8, ta, ma
1839+
; CHECK-NEXT: vmv.v.i v10, 0
1840+
; CHECK-NEXT: vmerge.vim v10, v10, 1, v0
1841+
; CHECK-NEXT: vmv1r.v v0, v9
1842+
; CHECK-NEXT: vsoxei8.v v8, (a0), v10, v0.t
1843+
; CHECK-NEXT: ret
1844+
%eidxs = zext <vscale x 1 x i1> %idxs to <vscale x 1 x i8>
1845+
%ptrs = getelementptr inbounds i8, ptr %base, <vscale x 1 x i8> %eidxs
1846+
call void @llvm.masked.scatter.nxv1i8.nxv1p0(<vscale x 1 x i8> %val, <vscale x 1 x ptr> %ptrs, i32 1, <vscale x 1 x i1> %m)
1847+
ret void
1848+
}

0 commit comments

Comments
 (0)