[PATCH] D103536: [CodeGen] Fix a scalable-vector crash in VSELECT legalization
Fraser Cormack via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 2 10:12:03 PDT 2021
frasercrmck created this revision.
frasercrmck added reviewers: craig.topper, sdesmalen, peterwaller-arm, c-rhodes, kmclaughlin.
Herald added subscribers: luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
frasercrmck requested review of this revision.
Herald added subscribers: llvm-commits, MaskRay.
Herald added a project: LLVM.
The `DAGTypeLegalizer::WidenVSELECTMask` function is not (yet) ready for
scalable vector types, and has numerous places in which it tries to grab
either the fixed size or number of elements of its types.
I believe that it should be possible to update this method to properly
account for scalable-vector types, but we don't have test cases for
that; RISC-V bails out early on as it has legal i1 vector masks. As
such, this patch just prevents it from crashing.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D103536
Files:
llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
llvm/test/CodeGen/RISCV/rvv/vselect-fp-rv32.ll
llvm/test/CodeGen/RISCV/rvv/vselect-fp-rv64.ll
Index: llvm/test/CodeGen/RISCV/rvv/vselect-fp-rv64.ll
===================================================================
--- llvm/test/CodeGen/RISCV/rvv/vselect-fp-rv64.ll
+++ llvm/test/CodeGen/RISCV/rvv/vselect-fp-rv64.ll
@@ -420,3 +420,30 @@
%sel = select <vscale x 16 x i1> %cond, <vscale x 16 x double> %vb, <vscale x 16 x double> zeroinitializer
ret <vscale x 16 x double> %sel
}
+
+define void @vselect_legalize_regression(<vscale x 16 x double> %a, <vscale x 16 x i1> %ma, <vscale x 16 x i1> %mb, <vscale x 16 x double>* %out) {
+; CHECK-LABEL: vselect_legalize_regression:
+; CHECK: # %bb.0:
+; CHECK-NEXT: vsetvli a2, zero, e8,m2,ta,mu
+; CHECK-NEXT: vle1.v v25, (a0)
+; CHECK-NEXT: vmand.mm v25, v0, v25
+; CHECK-NEXT: csrr a0, vlenb
+; CHECK-NEXT: srli a0, a0, 3
+; CHECK-NEXT: vsetvli a2, zero, e8,mf4,ta,mu
+; CHECK-NEXT: vslidedown.vx v0, v25, a0
+; CHECK-NEXT: vmv1r.v v2, v25
+; CHECK-NEXT: vsetvli a2, zero, e64,m8,ta,mu
+; CHECK-NEXT: vmv.v.i v24, 0
+; CHECK-NEXT: vmerge.vvm v16, v24, v16, v0
+; CHECK-NEXT: vmv1r.v v0, v2
+; CHECK-NEXT: vmerge.vvm v8, v24, v8, v0
+; CHECK-NEXT: vs8r.v v8, (a1)
+; CHECK-NEXT: slli a0, a0, 6
+; CHECK-NEXT: add a0, a1, a0
+; CHECK-NEXT: vs8r.v v16, (a0)
+; CHECK-NEXT: ret
+ %cond = and <vscale x 16 x i1> %ma, %mb
+ %sel = select <vscale x 16 x i1> %cond, <vscale x 16 x double> %a, <vscale x 16 x double> zeroinitializer
+ store <vscale x 16 x double> %sel, <vscale x 16 x double>* %out
+ ret void
+}
Index: llvm/test/CodeGen/RISCV/rvv/vselect-fp-rv32.ll
===================================================================
--- llvm/test/CodeGen/RISCV/rvv/vselect-fp-rv32.ll
+++ llvm/test/CodeGen/RISCV/rvv/vselect-fp-rv32.ll
@@ -420,3 +420,30 @@
%sel = select <vscale x 16 x i1> %cond, <vscale x 16 x double> %vb, <vscale x 16 x double> zeroinitializer
ret <vscale x 16 x double> %sel
}
+
+define void @vselect_legalize_regression(<vscale x 16 x double> %a, <vscale x 16 x i1> %ma, <vscale x 16 x i1> %mb, <vscale x 16 x double>* %out) {
+; CHECK-LABEL: vselect_legalize_regression:
+; CHECK: # %bb.0:
+; CHECK-NEXT: vsetvli a2, zero, e8,m2,ta,mu
+; CHECK-NEXT: vle1.v v25, (a0)
+; CHECK-NEXT: vmand.mm v25, v0, v25
+; CHECK-NEXT: csrr a0, vlenb
+; CHECK-NEXT: srli a0, a0, 3
+; CHECK-NEXT: vsetvli a2, zero, e8,mf4,ta,mu
+; CHECK-NEXT: vslidedown.vx v0, v25, a0
+; CHECK-NEXT: vmv1r.v v2, v25
+; CHECK-NEXT: vsetvli a2, zero, e64,m8,ta,mu
+; CHECK-NEXT: vmv.v.i v24, 0
+; CHECK-NEXT: vmerge.vvm v16, v24, v16, v0
+; CHECK-NEXT: vmv1r.v v0, v2
+; CHECK-NEXT: vmerge.vvm v8, v24, v8, v0
+; CHECK-NEXT: vs8r.v v8, (a1)
+; CHECK-NEXT: slli a0, a0, 6
+; CHECK-NEXT: add a0, a1, a0
+; CHECK-NEXT: vs8r.v v16, (a0)
+; CHECK-NEXT: ret
+ %cond = and <vscale x 16 x i1> %ma, %mb
+ %sel = select <vscale x 16 x i1> %cond, <vscale x 16 x double> %a, <vscale x 16 x double> zeroinitializer
+ store <vscale x 16 x double> %sel, <vscale x 16 x double>* %out
+ ret void
+}
Index: llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
+++ llvm/lib/CodeGen/SelectionDAG/LegalizeVectorTypes.cpp
@@ -4254,6 +4254,11 @@
return SDValue();
EVT VSelVT = N->getValueType(0);
+
+ // This method can't handle scalable vector types.
+ if (VSelVT.isScalableVector())
+ return SDValue();
+
// Only handle vector types which are a power of 2.
if (!isPowerOf2_64(VSelVT.getSizeInBits()))
return SDValue();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103536.349312.patch
Type: text/x-patch
Size: 3625 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210602/fc22a61b/attachment.bin>
More information about the llvm-commits
mailing list