Skip to content

Commit 6f30d00

Browse files
committed
[RISCV] Merge the vsetvli and vsetvlimax intrinsic selection
These have very similar code just with a different number of operands and handling for vsetivl. Differential Revision: https://reviews.llvm.org/D96834
1 parent 519f591 commit 6f30d00

File tree

1 file changed

+24
-35
lines changed

1 file changed

+24
-35
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -608,31 +608,42 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
608608
default:
609609
break;
610610

611-
case Intrinsic::riscv_vsetvli: {
611+
case Intrinsic::riscv_vsetvli:
612+
case Intrinsic::riscv_vsetvlimax: {
612613
if (!Subtarget->hasStdExtV())
613614
break;
614615

615-
assert(Node->getNumOperands() == 5);
616+
bool VLMax = IntNo == Intrinsic::riscv_vsetvlimax;
617+
unsigned Offset = VLMax ? 2 : 3;
618+
619+
assert(Node->getNumOperands() == Offset + 2 &&
620+
"Unexpected number of operands");
616621

617622
RISCVVSEW VSEW =
618-
static_cast<RISCVVSEW>(Node->getConstantOperandVal(3) & 0x7);
619-
RISCVVLMUL VLMul =
620-
static_cast<RISCVVLMUL>(Node->getConstantOperandVal(4) & 0x7);
623+
static_cast<RISCVVSEW>(Node->getConstantOperandVal(Offset) & 0x7);
624+
RISCVVLMUL VLMul = static_cast<RISCVVLMUL>(
625+
Node->getConstantOperandVal(Offset + 1) & 0x7);
621626

622627
unsigned VTypeI = RISCVVType::encodeVTYPE(
623628
VLMul, VSEW, /*TailAgnostic*/ true, /*MaskAgnostic*/ false);
624629
SDValue VTypeIOp = CurDAG->getTargetConstant(VTypeI, DL, XLenVT);
625630

626-
SDValue VLOperand = Node->getOperand(2);
627-
if (auto *C = dyn_cast<ConstantSDNode>(VLOperand)) {
628-
uint64_t AVL = C->getZExtValue();
629-
if (isUInt<5>(AVL)) {
630-
SDValue VLImm = CurDAG->getTargetConstant(AVL, DL, XLenVT);
631-
ReplaceNode(Node,
632-
CurDAG->getMachineNode(RISCV::PseudoVSETIVLI, DL, XLenVT,
631+
SDValue VLOperand;
632+
if (VLMax) {
633+
VLOperand = CurDAG->getRegister(RISCV::X0, XLenVT);
634+
} else {
635+
VLOperand = Node->getOperand(2);
636+
637+
if (auto *C = dyn_cast<ConstantSDNode>(VLOperand)) {
638+
uint64_t AVL = C->getZExtValue();
639+
if (isUInt<5>(AVL)) {
640+
SDValue VLImm = CurDAG->getTargetConstant(AVL, DL, XLenVT);
641+
ReplaceNode(
642+
Node, CurDAG->getMachineNode(RISCV::PseudoVSETIVLI, DL, XLenVT,
633643
MVT::Other, VLImm, VTypeIOp,
634644
/* Chain */ Node->getOperand(0)));
635-
return;
645+
return;
646+
}
636647
}
637648
}
638649

@@ -642,28 +653,6 @@ void RISCVDAGToDAGISel::Select(SDNode *Node) {
642653
/* Chain */ Node->getOperand(0)));
643654
return;
644655
}
645-
case Intrinsic::riscv_vsetvlimax: {
646-
if (!Subtarget->hasStdExtV())
647-
break;
648-
649-
assert(Node->getNumOperands() == 4);
650-
651-
RISCVVSEW VSEW =
652-
static_cast<RISCVVSEW>(Node->getConstantOperandVal(2) & 0x7);
653-
RISCVVLMUL VLMul =
654-
static_cast<RISCVVLMUL>(Node->getConstantOperandVal(3) & 0x7);
655-
656-
unsigned VTypeI = RISCVVType::encodeVTYPE(
657-
VLMul, VSEW, /*TailAgnostic*/ true, /*MaskAgnostic*/ false);
658-
SDValue VTypeIOp = CurDAG->getTargetConstant(VTypeI, DL, XLenVT);
659-
660-
SDValue VLOperand = CurDAG->getRegister(RISCV::X0, XLenVT);
661-
ReplaceNode(Node,
662-
CurDAG->getMachineNode(RISCV::PseudoVSETVLI, DL, XLenVT,
663-
MVT::Other, VLOperand, VTypeIOp,
664-
/* Chain */ Node->getOperand(0)));
665-
return;
666-
}
667656
case Intrinsic::riscv_vlseg2:
668657
case Intrinsic::riscv_vlseg3:
669658
case Intrinsic::riscv_vlseg4:

0 commit comments

Comments
 (0)