[llvm] [instcombine] Scalarize operands of vector geps if possible (PR #145402)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 23 23:41:09 PDT 2025
================
@@ -3058,6 +3058,31 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
return replaceInstUsesWith(GEP, NewGEP);
}
+ // Scalarize vector operands; prefer splat-of-gep.as canonical form.
+ if (GEPType->isVectorTy() && llvm::any_of(GEP.operands(), [](Value *Op) {
+ return Op->getType()->isVectorTy() && getSplatValue(Op);
+ })) {
+ SmallVector<Value *> NewOps;
+ for (auto &Op : GEP.operands()) {
+ if (Op->getType()->isVectorTy())
+ if (Value *Scalar = getSplatValue(Op)) {
+ NewOps.push_back(Scalar);
+ continue;
+ }
+ NewOps.push_back(Op);
+ }
+
+ Value *Res = Builder.CreateGEP(GEP.getSourceElementType(), NewOps[0],
+ ArrayRef(NewOps).drop_front(), GEP.getName(),
+ GEP.getNoWrapFlags());
+ if (llvm::all_of(NewOps,
+ [](Value *Op) { return !Op->getType()->isVectorTy(); })) {
----------------
dtcxzyw wrote:
```suggestion
if (!Res->getType()->isVectorTy()) {
```
It should be simpler.
https://github.com/llvm/llvm-project/pull/145402
More information about the llvm-commits
mailing list