Skip to content

Commit d738b68

Browse files
fixup! implement non-VLMAX cases in selectVLOp
1 parent e31dc4a commit d738b68

File tree

5 files changed

+85
-67
lines changed

5 files changed

+85
-67
lines changed

llvm/lib/Target/RISCV/GISel/RISCVInstructionSelector.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,21 @@ RISCVInstructionSelector::selectVLOp(MachineOperand &Root) const {
385385
assert(Root.isReg() && "Expected operand to be a Register");
386386
MachineInstr *RootDef = MRI.getVRegDef(Root.getReg());
387387

388-
if (RootDef->getOpcode() == TargetOpcode::G_CONSTANT &&
389-
RootDef->getOperand(1).getCImm()->getSExtValue() == RISCV::VLMaxSentinel)
390-
// If the operand is a G_CONSTANT with value VLMaxSentinel, convert it
391-
// to an immediate with value VLMaxSentinel. This is recognized specially by
392-
// the vsetvli insertion pass.
393-
return {
394-
{[=](MachineInstrBuilder &MIB) { MIB.addImm(RISCV::VLMaxSentinel); }}};
395-
396-
// FIXME: Implement non-VLMAX case. ISEL will fail gracefully by returning
397-
// like this for now.
398-
return std::nullopt;
388+
if (RootDef->getOpcode() == TargetOpcode::G_CONSTANT) {
389+
auto C = RootDef->getOperand(1).getCImm();
390+
if (C->getSExtValue() == RISCV::VLMaxSentinel || C->getValue().isAllOnes())
391+
// If the operand is a G_CONSTANT with value VLMaxSentinel or all ones,
392+
// convert it to an immediate with value VLMaxSentinel. This is recognized
393+
// specially by the vsetvli insertion pass.
394+
return {{[=](MachineInstrBuilder &MIB) {
395+
MIB.addImm(RISCV::VLMaxSentinel);
396+
}}};
397+
398+
if (isUInt<5>(C->getZExtValue()))
399+
return {
400+
{[=](MachineInstrBuilder &MIB) { MIB.addImm(C->getZExtValue()); }}};
401+
}
402+
return {{[=](MachineInstrBuilder &MIB) { MIB.addReg(Root.getReg()); }}};
399403
}
400404

401405
InstructionSelector::ComplexRendererFns

llvm/test/CodeGen/RISCV/GlobalISel/instruction-select/rvv/fail-select-vl-nonconst.mir

Lines changed: 0 additions & 19 deletions
This file was deleted.

llvm/test/CodeGen/RISCV/GlobalISel/instruction-select/rvv/fail-select-vl-nonzero.mir

Lines changed: 0 additions & 19 deletions
This file was deleted.

llvm/test/CodeGen/RISCV/GlobalISel/instruction-select/rvv/fail-select-vl-zero.mir

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
2+
# RUN: llc -mtriple=riscv32 -mattr=+v,+m -run-pass=instruction-select \
3+
# RUN: -verify-machineinstrs %s -o - | FileCheck %s
4+
5+
name: negative_vl
6+
legalized: true
7+
regBankSelected: true
8+
tracksRegLiveness: true
9+
body: |
10+
bb.1:
11+
%0:gprb(s32) = G_CONSTANT i32 -2
12+
%1:vrb(<vscale x 1 x s1>) = G_VMCLR_VL %0(s32)
13+
$v0 = COPY %1(<vscale x 1 x s1>)
14+
PseudoRET implicit $v0
15+
...
16+
---
17+
name: nonconst_vl
18+
legalized: true
19+
regBankSelected: true
20+
tracksRegLiveness: true
21+
body: |
22+
bb.1:
23+
liveins: $x10
24+
; CHECK-LABEL: name: nonconst_vl
25+
; CHECK: liveins: $x10
26+
; CHECK-NEXT: {{ $}}
27+
; CHECK-NEXT: [[COPY:%[0-9]+]]:gprnox0 = COPY $x10
28+
; CHECK-NEXT: [[PseudoVMCLR_M_B1_:%[0-9]+]]:vr = PseudoVMCLR_M_B1 [[COPY]], 0 /* e8 */
29+
; CHECK-NEXT: $v0 = COPY [[PseudoVMCLR_M_B1_]]
30+
; CHECK-NEXT: PseudoRET implicit $v0
31+
%0:gprb(s32) = COPY $x10
32+
%1:vrb(<vscale x 1 x s1>) = G_VMCLR_VL %0(s32)
33+
$v0 = COPY %1(<vscale x 1 x s1>)
34+
PseudoRET implicit $v0
35+
...
36+
37+
---
38+
name: nonzero_vl
39+
legalized: true
40+
regBankSelected: true
41+
tracksRegLiveness: true
42+
body: |
43+
bb.1:
44+
; CHECK-LABEL: name: nonzero_vl
45+
; CHECK: [[PseudoVMCLR_M_B1_:%[0-9]+]]:vr = PseudoVMCLR_M_B1 1, 0 /* e8 */
46+
; CHECK-NEXT: $v0 = COPY [[PseudoVMCLR_M_B1_]]
47+
; CHECK-NEXT: PseudoRET implicit $v0
48+
%0:gprb(s32) = G_CONSTANT i32 1
49+
%1:vrb(<vscale x 1 x s1>) = G_VMCLR_VL %0(s32)
50+
$v0 = COPY %1(<vscale x 1 x s1>)
51+
PseudoRET implicit $v0
52+
...
53+
54+
---
55+
name: zero_vl
56+
legalized: true
57+
regBankSelected: true
58+
tracksRegLiveness: true
59+
body: |
60+
bb.1:
61+
; CHECK-LABEL: name: zero_vl
62+
; CHECK: [[PseudoVMCLR_M_B1_:%[0-9]+]]:vr = PseudoVMCLR_M_B1 0, 0 /* e8 */
63+
; CHECK-NEXT: $v0 = COPY [[PseudoVMCLR_M_B1_]]
64+
; CHECK-NEXT: PseudoRET implicit $v0
65+
%0:gprb(s32) = G_CONSTANT i32 0
66+
%1:vrb(<vscale x 1 x s1>) = G_VMCLR_VL %0(s32)
67+
$v0 = COPY %1(<vscale x 1 x s1>)
68+
PseudoRET implicit $v0
69+
...
70+

0 commit comments

Comments
 (0)