forked from OSchip/llvm-project
Fix LoopIdiomRecognize pass return status
Introduce an helper class to aggregate the cleanup in case of rollback. Differential Revision: https://reviews.llvm.org/D81230
This commit is contained in:
parent
d4e183f686
commit
1cafd8a5d1
|
@ -1010,6 +1010,29 @@ bool LoopIdiomRecognize::processLoopStridedStore(
|
|||
return true;
|
||||
}
|
||||
|
||||
class ExpandedValuesCleaner {
|
||||
SCEVExpander &Expander;
|
||||
TargetLibraryInfo *TLI;
|
||||
SmallVector<Value *, 4> ExpandedValues;
|
||||
bool Commit = false;
|
||||
|
||||
public:
|
||||
ExpandedValuesCleaner(SCEVExpander &Expander, TargetLibraryInfo *TLI)
|
||||
: Expander(Expander), TLI(TLI) {}
|
||||
|
||||
void add(Value *V) { ExpandedValues.push_back(V); }
|
||||
|
||||
void commit() { Commit = true; }
|
||||
|
||||
~ExpandedValuesCleaner() {
|
||||
if (!Commit) {
|
||||
Expander.clear();
|
||||
for (auto *V : ExpandedValues)
|
||||
RecursivelyDeleteTriviallyDeadInstructions(V, TLI);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/// If the stored value is a strided load in the same loop with the same stride
|
||||
/// this may be transformable into a memcpy. This kicks in for stuff like
|
||||
/// for (i) A[i] = B[i];
|
||||
|
@ -1040,6 +1063,8 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(StoreInst *SI,
|
|||
IRBuilder<> Builder(Preheader->getTerminator());
|
||||
SCEVExpander Expander(*SE, *DL, "loop-idiom");
|
||||
|
||||
ExpandedValuesCleaner EVC(Expander, TLI);
|
||||
|
||||
const SCEV *StrStart = StoreEv->getStart();
|
||||
unsigned StrAS = SI->getPointerAddressSpace();
|
||||
Type *IntIdxTy = Builder.getIntNTy(DL->getIndexSizeInBits(StrAS));
|
||||
|
@ -1056,16 +1081,13 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(StoreInst *SI,
|
|||
// checking everything.
|
||||
Value *StoreBasePtr = Expander.expandCodeFor(
|
||||
StrStart, Builder.getInt8PtrTy(StrAS), Preheader->getTerminator());
|
||||
EVC.add(StoreBasePtr);
|
||||
|
||||
SmallPtrSet<Instruction *, 1> Stores;
|
||||
Stores.insert(SI);
|
||||
if (mayLoopAccessLocation(StoreBasePtr, ModRefInfo::ModRef, CurLoop, BECount,
|
||||
StoreSize, *AA, Stores)) {
|
||||
Expander.clear();
|
||||
// If we generated new code for the base pointer, clean up.
|
||||
RecursivelyDeleteTriviallyDeadInstructions(StoreBasePtr, TLI);
|
||||
StoreSize, *AA, Stores))
|
||||
return false;
|
||||
}
|
||||
|
||||
const SCEV *LdStart = LoadEv->getStart();
|
||||
unsigned LdAS = LI->getPointerAddressSpace();
|
||||
|
@ -1078,15 +1100,11 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(StoreInst *SI,
|
|||
// mutated by the loop.
|
||||
Value *LoadBasePtr = Expander.expandCodeFor(
|
||||
LdStart, Builder.getInt8PtrTy(LdAS), Preheader->getTerminator());
|
||||
EVC.add(LoadBasePtr);
|
||||
|
||||
if (mayLoopAccessLocation(LoadBasePtr, ModRefInfo::Mod, CurLoop, BECount,
|
||||
StoreSize, *AA, Stores)) {
|
||||
Expander.clear();
|
||||
// If we generated new code for the base pointer, clean up.
|
||||
RecursivelyDeleteTriviallyDeadInstructions(LoadBasePtr, TLI);
|
||||
RecursivelyDeleteTriviallyDeadInstructions(StoreBasePtr, TLI);
|
||||
StoreSize, *AA, Stores))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (avoidLIRForMultiBlockLoop())
|
||||
return false;
|
||||
|
@ -1098,6 +1116,7 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(StoreInst *SI,
|
|||
|
||||
Value *NumBytes =
|
||||
Expander.expandCodeFor(NumBytesS, IntIdxTy, Preheader->getTerminator());
|
||||
EVC.add(NumBytes);
|
||||
|
||||
CallInst *NewCall = nullptr;
|
||||
// Check whether to generate an unordered atomic memcpy:
|
||||
|
@ -1157,6 +1176,7 @@ bool LoopIdiomRecognize::processLoopStoreOfLoopLoad(StoreInst *SI,
|
|||
if (MSSAU && VerifyMemorySSA)
|
||||
MSSAU->getMemorySSA()->verifyMemorySSA();
|
||||
++NumMemCpy;
|
||||
EVC.commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue