forked from OSchip/llvm-project
[Loop vectorizer] Simplified GEP cloning. NFC.
Simplified GEP cloning in vectorizeMemoryInstruction(). Added an assertion that checks consecutive GEP, which should have only one loop-variant operand. Differential Revision: https://reviews.llvm.org/D24557 llvm-svn: 281851
This commit is contained in:
parent
05ee64e67a
commit
a1a0e7ddbe
|
@ -2783,44 +2783,35 @@ void InnerLoopVectorizer::vectorizeMemoryInstruction(Instruction *Instr) {
|
||||||
// Handle consecutive loads/stores.
|
// Handle consecutive loads/stores.
|
||||||
GetElementPtrInst *Gep = getGEPInstruction(Ptr);
|
GetElementPtrInst *Gep = getGEPInstruction(Ptr);
|
||||||
if (ConsecutiveStride) {
|
if (ConsecutiveStride) {
|
||||||
if (Gep && Legal->isInductionVariable(Gep->getPointerOperand())) {
|
if (Gep) {
|
||||||
setDebugLocFromInst(Builder, Gep);
|
|
||||||
auto *FirstBasePtr = getScalarValue(Gep->getPointerOperand(), 0, 0);
|
|
||||||
|
|
||||||
// Create the new GEP with the new induction variable.
|
|
||||||
GetElementPtrInst *Gep2 = cast<GetElementPtrInst>(Gep->clone());
|
|
||||||
Gep2->setOperand(0, FirstBasePtr);
|
|
||||||
Gep2->setName("gep.indvar.base");
|
|
||||||
Ptr = Builder.Insert(Gep2);
|
|
||||||
} else if (Gep) {
|
|
||||||
setDebugLocFromInst(Builder, Gep);
|
|
||||||
assert(PSE.getSE()->isLoopInvariant(PSE.getSCEV(Gep->getPointerOperand()),
|
|
||||||
OrigLoop) &&
|
|
||||||
"Base ptr must be invariant");
|
|
||||||
// The last index does not have to be the induction. It can be
|
|
||||||
// consecutive and be a function of the index. For example A[I+1];
|
|
||||||
unsigned NumOperands = Gep->getNumOperands();
|
unsigned NumOperands = Gep->getNumOperands();
|
||||||
unsigned InductionOperand = getGEPInductionOperand(Gep);
|
#ifndef NDEBUG
|
||||||
// Create the new GEP with the new induction variable.
|
// The original GEP that identified as a consecutive memory access
|
||||||
|
// should have only one loop-variant operand.
|
||||||
|
unsigned NumOfLoopVariantOps = 0;
|
||||||
|
for (unsigned i = 0; i < NumOperands; ++i)
|
||||||
|
if (!PSE.getSE()->isLoopInvariant(PSE.getSCEV(Gep->getOperand(i)),
|
||||||
|
OrigLoop))
|
||||||
|
NumOfLoopVariantOps++;
|
||||||
|
assert(NumOfLoopVariantOps == 1 &&
|
||||||
|
"Consecutive GEP should have only one loop-variant operand");
|
||||||
|
#endif
|
||||||
GetElementPtrInst *Gep2 = cast<GetElementPtrInst>(Gep->clone());
|
GetElementPtrInst *Gep2 = cast<GetElementPtrInst>(Gep->clone());
|
||||||
|
Gep2->setName("gep.indvar");
|
||||||
|
|
||||||
for (unsigned i = 0; i < NumOperands; ++i) {
|
// A new GEP is created for a 0-lane value of the first unroll iteration.
|
||||||
Value *GepOperand = Gep->getOperand(i);
|
// The GEPs for the rest of the unroll iterations are computed below as an
|
||||||
Instruction *GepOperandInst = dyn_cast<Instruction>(GepOperand);
|
// offset from this GEP.
|
||||||
|
for (unsigned i = 0; i < NumOperands; ++i)
|
||||||
// Update last index or loop invariant instruction anchored in loop.
|
// We can apply getScalarValue() for all GEP indices. It returns an
|
||||||
if (i == InductionOperand ||
|
// original value for loop-invariant operand and 0-lane for consecutive
|
||||||
(GepOperandInst && OrigLoop->contains(GepOperandInst))) {
|
// operand.
|
||||||
assert((i == InductionOperand ||
|
Gep2->setOperand(i, getScalarValue(Gep->getOperand(i),
|
||||||
PSE.getSE()->isLoopInvariant(PSE.getSCEV(GepOperandInst),
|
0, /* First unroll iteration */
|
||||||
OrigLoop)) &&
|
0 /* 0-lane of the vector */ ));
|
||||||
"Must be last index or loop invariant");
|
setDebugLocFromInst(Builder, Gep);
|
||||||
|
|
||||||
Gep2->setOperand(i, getScalarValue(GepOperand, 0, 0));
|
|
||||||
Gep2->setName("gep.indvar.idx");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ptr = Builder.Insert(Gep2);
|
Ptr = Builder.Insert(Gep2);
|
||||||
|
|
||||||
} else { // No GEP
|
} else { // No GEP
|
||||||
// Use the induction element ptr.
|
// Use the induction element ptr.
|
||||||
assert(isa<PHINode>(Ptr) && "Invalid induction ptr");
|
assert(isa<PHINode>(Ptr) && "Invalid induction ptr");
|
||||||
|
|
Loading…
Reference in New Issue