diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp --- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp +++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp @@ -608,31 +608,42 @@ default: break; - case Intrinsic::riscv_vsetvli: { + case Intrinsic::riscv_vsetvli: + case Intrinsic::riscv_vsetvlimax: { if (!Subtarget->hasStdExtV()) break; - assert(Node->getNumOperands() == 5); + bool VLMax = IntNo == Intrinsic::riscv_vsetvlimax; + unsigned Offset = VLMax ? 2 : 3; + + assert(Node->getNumOperands() == Offset + 2 && + "Unexpected number of operands"); RISCVVSEW VSEW = - static_cast(Node->getConstantOperandVal(3) & 0x7); - RISCVVLMUL VLMul = - static_cast(Node->getConstantOperandVal(4) & 0x7); + static_cast(Node->getConstantOperandVal(Offset) & 0x7); + RISCVVLMUL VLMul = static_cast( + Node->getConstantOperandVal(Offset + 1) & 0x7); unsigned VTypeI = RISCVVType::encodeVTYPE( VLMul, VSEW, /*TailAgnostic*/ true, /*MaskAgnostic*/ false); SDValue VTypeIOp = CurDAG->getTargetConstant(VTypeI, DL, XLenVT); - SDValue VLOperand = Node->getOperand(2); - if (auto *C = dyn_cast(VLOperand)) { - uint64_t AVL = C->getZExtValue(); - if (isUInt<5>(AVL)) { - SDValue VLImm = CurDAG->getTargetConstant(AVL, DL, XLenVT); - ReplaceNode(Node, - CurDAG->getMachineNode(RISCV::PseudoVSETIVLI, DL, XLenVT, + SDValue VLOperand; + if (VLMax) { + VLOperand = CurDAG->getRegister(RISCV::X0, XLenVT); + } else { + VLOperand = Node->getOperand(2); + + if (auto *C = dyn_cast(VLOperand)) { + uint64_t AVL = C->getZExtValue(); + if (isUInt<5>(AVL)) { + SDValue VLImm = CurDAG->getTargetConstant(AVL, DL, XLenVT); + ReplaceNode( + Node, CurDAG->getMachineNode(RISCV::PseudoVSETIVLI, DL, XLenVT, MVT::Other, VLImm, VTypeIOp, /* Chain */ Node->getOperand(0))); - return; + return; + } } } @@ -642,28 +653,6 @@ /* Chain */ Node->getOperand(0))); return; } - case Intrinsic::riscv_vsetvlimax: { - if (!Subtarget->hasStdExtV()) - break; - - assert(Node->getNumOperands() == 4); - - RISCVVSEW VSEW = - static_cast(Node->getConstantOperandVal(2) & 0x7); - RISCVVLMUL VLMul = - static_cast(Node->getConstantOperandVal(3) & 0x7); - - unsigned VTypeI = RISCVVType::encodeVTYPE( - VLMul, VSEW, /*TailAgnostic*/ true, /*MaskAgnostic*/ false); - SDValue VTypeIOp = CurDAG->getTargetConstant(VTypeI, DL, XLenVT); - - SDValue VLOperand = CurDAG->getRegister(RISCV::X0, XLenVT); - ReplaceNode(Node, - CurDAG->getMachineNode(RISCV::PseudoVSETVLI, DL, XLenVT, - MVT::Other, VLOperand, VTypeIOp, - /* Chain */ Node->getOperand(0))); - return; - } case Intrinsic::riscv_vlseg2: case Intrinsic::riscv_vlseg3: case Intrinsic::riscv_vlseg4: