[PATCH] D113792: [SLP]Adjust GEP indices types when trying to build entries.
Alexey Bataev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 12 12:18:07 PST 2021
ABataev created this revision.
ABataev added reviewers: RKSimon, vporpo, anton-afanasyev, dtemirbulatov.
Herald added a subscriber: hiraditya.
ABataev requested review of this revision.
Herald added a project: LLVM.
Need to adjust the types of GEPs indices when building the tree
entries/operands. Otherwise some of the nodes might differ and
vectorizer is unable to correctly find them and count their cost.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D113792
Files:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===================================================================
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3865,15 +3865,39 @@
TreeEntry *TE = newTreeEntry(VL, Bundle /*vectorized*/, S, UserTreeIdx,
ReuseShuffleIndicies);
LLVM_DEBUG(dbgs() << "SLP: added a vector of GEPs.\n");
- TE->setOperandsInOrder();
- for (unsigned i = 0, e = 2; i < e; ++i) {
- ValueList Operands;
- // Prepare the operand vector.
- for (Value *V : VL)
- Operands.push_back(cast<Instruction>(V)->getOperand(i));
-
- buildTree_rec(Operands, Depth + 1, {TE, i});
+ SmallVector<ValueList, 2> Operands;
+ Operands.emplace_back();
+ // Prepare the operand vector for pointer operands.
+ for (Value *V : VL)
+ Operands.back().push_back(
+ cast<GetElementPtrInst>(V)->getPointerOperand());
+ TE->setOperand(0, Operands.back());
+ // Need to cast all indices to the same type before vectorization to
+ // avoid crash.
+ const int IndexIdx = 1;
+ Operands.emplace_back();
+ Type *VL0Ty = VL0->getOperand(IndexIdx)->getType();
+ Type *Ty = all_of(VL,
+ [VL0Ty](Value *V) {
+ return VL0Ty == cast<GetElementPtrInst>(V)
+ ->getOperand(IndexIdx)
+ ->getType();
+ })
+ ? VL0Ty
+ : DL->getIndexType(cast<GetElementPtrInst>(VL0)
+ ->getPointerOperandType()
+ ->getScalarType());
+ // Prepare the operand vector.
+ for (Value *V : VL) {
+ auto *Op = cast<Instruction>(V)->getOperand(IndexIdx);
+ auto *CI = cast<ConstantInt>(Op);
+ Operands.back().push_back(ConstantExpr::getIntegerCast(
+ CI, Ty, CI->getValue().isSignBitSet()));
}
+ TE->setOperand(IndexIdx, Operands.back());
+
+ for (unsigned I = 0, Ops = Operands.size(); I < Ops; ++I)
+ buildTree_rec(Operands[I], Depth + 1, {TE, I});
return;
}
case Instruction::Store: {
@@ -6276,25 +6300,10 @@
Value *Op0 = vectorizeTree(E->getOperand(0));
- std::vector<Value *> OpVecs;
- for (int j = 1, e = cast<GetElementPtrInst>(VL0)->getNumOperands(); j < e;
- ++j) {
- ValueList &VL = E->getOperand(j);
- // Need to cast all elements to the same type before vectorization to
- // avoid crash.
- Type *VL0Ty = VL0->getOperand(j)->getType();
- Type *Ty = llvm::all_of(
- VL, [VL0Ty](Value *V) { return VL0Ty == V->getType(); })
- ? VL0Ty
- : DL->getIndexType(cast<GetElementPtrInst>(VL0)
- ->getPointerOperandType()
- ->getScalarType());
- for (Value *&V : VL) {
- auto *CI = cast<ConstantInt>(V);
- V = ConstantExpr::getIntegerCast(CI, Ty,
- CI->getValue().isSignBitSet());
- }
- Value *OpVec = vectorizeTree(VL);
+ SmallVector<Value *> OpVecs;
+ for (int J = 1, N = cast<GetElementPtrInst>(VL0)->getNumOperands(); J < N;
+ ++J) {
+ Value *OpVec = vectorizeTree(E->getOperand(J));
OpVecs.push_back(OpVec);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113792.386913.patch
Type: text/x-patch
Size: 3623 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211112/7844f404/attachment.bin>
More information about the llvm-commits
mailing list