[llvm] [SLP]Support copyable GEP/zext main ops and relax gather pointer compatibility (PR #221599)

Ryan Buchner via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 23:30:48 PDT 2026


================
@@ -857,6 +858,95 @@ bool isSelectedBaseLoad(Type *ScalarTy, ArrayRef<Value *> PointerOps,
   return TrueBase != nullptr;
 }
 
+Type *getCommonGEPIndexType(ArrayRef<Value *> VL, Instruction *VL0,
+                            function_ref<bool(Value *)> IsGEPLane,
+                            const DataLayout &DL) {
+  constexpr unsigned IndexIdx = 1;
+  Type *VL0Ty = VL0->getOperand(IndexIdx)->getType();
+  Type *PtrIdxTy =
+      DL.getIndexType(VL0->getOperand(0)->getType()->getScalarType());
+  bool AllSameTy = true;
+  bool HasNonConstIdx = false;
+  bool ConstsFitVL0Ty = true;
+  for (Value *V : make_filter_range(VL, IsGEPLane)) {
+    Value *Op = cast<GetElementPtrInst>(V)->getOperand(IndexIdx);
+    if (Op->getType() != VL0Ty)
+      AllSameTy = false;
+    auto *CI = dyn_cast<ConstantInt>(Op);
+    if (!CI) {
+      // Non-constant indices are not cast, they must have the main op type.
+      if (Op->getType() != VL0Ty)
+        return nullptr;
+      HasNonConstIdx = true;
+      continue;
+    }
+    if (!CI->getValue().isSignedIntN(VL0Ty->getIntegerBitWidth()))
+      ConstsFitVL0Ty = false;
+  }
+  if (AllSameTy)
+    return VL0Ty;
+  if (!HasNonConstIdx || VL0Ty == PtrIdxTy)
+    return PtrIdxTy;
----------------
bababuck wrote:

But in that case wouldn't it be better to use the mainop's index type rather than fall back to `VL0Ty`? I don't see a test case that hits this, will try to generate one.

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


More information about the llvm-commits mailing list