[PATCH] D96834: [RISCV] Merge the vsetvli and vsetvlimax intrinsic selection

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 16 19:50:36 PST 2021


craig.topper created this revision.
craig.topper added reviewers: HsiangKai, frasercrmck, evandro.
Herald added subscribers: StephenFan, vkmr, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, asb, hiraditya.
craig.topper requested review of this revision.
Herald added a subscriber: MaskRay.
Herald added a project: LLVM.

These have very similar code just with a different number of
operands and handling for vsetivl.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D96834

Files:
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp


Index: llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ 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<RISCVVSEW>(Node->getConstantOperandVal(3) & 0x7);
-      RISCVVLMUL VLMul =
-          static_cast<RISCVVLMUL>(Node->getConstantOperandVal(4) & 0x7);
+          static_cast<RISCVVSEW>(Node->getConstantOperandVal(Offset) & 0x7);
+      RISCVVLMUL VLMul = static_cast<RISCVVLMUL>(
+          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<ConstantSDNode>(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<ConstantSDNode>(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<RISCVVSEW>(Node->getConstantOperandVal(2) & 0x7);
-      RISCVVLMUL VLMul =
-          static_cast<RISCVVLMUL>(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:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D96834.324174.patch
Type: text/x-patch
Size: 3455 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210217/7180a03a/attachment.bin>


More information about the llvm-commits mailing list