[llvm] [VPlan] Introduce VPGEPInstruction (PR #193510)

Ramkumar Ramachandra via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 31 01:44:03 PDT 2026


================
@@ -1604,6 +1604,63 @@ class VPInstructionWithType : public VPInstruction {
 #endif
 };
 
+class VPGEPInstruction : public VPInstruction {
+  /// The source element type of the GEP.
+  Type *SourceElementTy;
+
+public:
+  VPGEPInstruction(Type *SourceElementTy, ArrayRef<VPValue *> Operands,
+                   const VPIRFlags &Flags = {},
+                   const VPIRMetadata &Metadata = {},
+                   DebugLoc DL = DebugLoc::getUnknown(), Twine Name = "",
+                   Value *UV = nullptr)
+      : VPInstruction(Instruction::GetElementPtr, Operands, Flags, Metadata, DL,
+                      Name, Operands[0]->getScalarType()),
+        SourceElementTy(SourceElementTy) {
+    setUnderlyingValue(UV);
+  }
+
+  static inline bool classof(const VPRecipeBase *R) {
+    auto *VPI = dyn_cast<VPInstruction>(R);
+    return VPI && VPI->getOpcode() == Instruction::GetElementPtr;
+  }
+
+  Type *getSourceElementType() const { return SourceElementTy; }
+
+  VPGEPInstruction *clone() override {
+    return new VPGEPInstruction(getSourceElementType(), operands(), *this,
+                                *this, getDebugLoc(), getName(),
+                                getUnderlyingValue());
+  }
+
+  /// Returns true if the recipe only uses the first lane of operand \p Op.
+  bool usesFirstLaneOnly(const VPValue *Op) const override;
+
+  /// Returns true if the recipe uses scalars of operand \p Op.
+  bool usesScalars(const VPValue *Op) const override {
+    assert(is_contained(operands(), Op) &&
+           "Op must be an operand of the recipe");
+    return true;
+  }
+
+  InstructionCost computeCost(ElementCount VF,
+                              VPCostContext &Ctx) const override {
+    // We mark this instruction as zero-cost because the cost of GEPs in
+    // vectorized code depends on whether the corresponding memory instruction
+    // is scalarized or not. Therefore, we handle GEPs with the memory
+    // instruction cost.
----------------
artagnon wrote:

I think we cost stores with GEPs already?

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


More information about the llvm-commits mailing list