[llvm] [RISCV] Handle .vx/.vi pseudos in hasAllNBitUsers (PR #67419)

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 27 11:34:40 PDT 2023


================
@@ -2752,6 +2752,175 @@ bool RISCVDAGToDAGISel::selectSHXADD_UWOp(SDValue N, unsigned ShAmt,
   return false;
 }
 
+static bool vectorPseudoHasAllNBitUsers(SDNode *User, unsigned UserOpNo,
+                                        unsigned Bits,
+                                        const TargetInstrInfo *TII) {
+  const RISCVVPseudosTable::PseudoInfo *PseudoInfo =
+      RISCVVPseudosTable::getPseudoInfo(User->getMachineOpcode());
+
+  if (!PseudoInfo)
+    return false;
+
+  const MCInstrDesc &MCID = TII->get(User->getMachineOpcode());
+  const uint64_t TSFlags = MCID.TSFlags;
+  if (!RISCVII::hasSEWOp(TSFlags))
+    return false;
+  assert(RISCVII::hasVLOp(TSFlags));
+
+  bool HasGlueOp = User->getGluedNode() != nullptr;
+  unsigned ChainOpIdx = User->getNumOperands() - HasGlueOp - 1;
+  bool HasChainOp = User->getOperand(ChainOpIdx).getValueType() == MVT::Other;
+  bool HasVecPolicyOp = RISCVII::hasVecPolicyOp(TSFlags);
+  unsigned VLIdx =
+      User->getNumOperands() - HasVecPolicyOp - HasChainOp - HasGlueOp - 2;
+  const unsigned Log2SEW = User->getConstantOperandVal(VLIdx + 1);
+
+  // TODO: The Largest VL 65,536 occurs for LMUL=8 and SEW=8 with
+  // VLEN=65,536. We could check if Bits < 16 here.
+  if (UserOpNo == VLIdx)
----------------
preames wrote:

I ended up talking with Luke abut this offline, and convinced myself that I'm at least mostly wrong here.

We have existing transforms - such as narrowing a vmv.s.x to lmul in DAG combine - which assume the AVL value here will be well defined.  I couldn't find clear evidence in code that we consistently follow the AVL to VL rules from the vector specification, but we definitely do rely on AVL values larger than VL being defined.

As an aside, looking at the intrinsic docs they say "Intrinsics will at most operate vlmax (derived in 3.4.2 of v-spec) elements. "  I'm unclear if this is meant to match the vector specifications rules, or if this is meant to imply a clamp.  

So, in terms of this review, Craig's correct, and removing the TODO was definitely the right call here.

https://github.com/llvm/llvm-project/pull/67419


More information about the llvm-commits mailing list