Upgrade TypePromotionTransaction to be able to report changes in CodeGenPrepare

optimizeMemoryInst was reporting no change while still modifying the IR.
Inspect the status of TypePromotionTransaction to get a better status.

Related to https://reviews.llvm.org/D80916

Differential Revision: https://reviews.llvm.org/D81256
This commit is contained in:
serge-sans-paille 2020-06-23 15:44:29 +02:00
parent f54d0e36be
commit edc7da2405
1 changed files with 14 additions and 11 deletions

View File

@ -2822,8 +2822,9 @@ public:
TypePromotionTransaction(SetOfInstrs &RemovedInsts) TypePromotionTransaction(SetOfInstrs &RemovedInsts)
: RemovedInsts(RemovedInsts) {} : RemovedInsts(RemovedInsts) {}
/// Advocate every changes made in that transaction. /// Advocate every changes made in that transaction. Return true if any change
void commit(); /// happen.
bool commit();
/// Undo all the changes made after the given point. /// Undo all the changes made after the given point.
void rollback(ConstRestorationPt Point); void rollback(ConstRestorationPt Point);
@ -2929,11 +2930,13 @@ TypePromotionTransaction::getRestorationPoint() const {
return !Actions.empty() ? Actions.back().get() : nullptr; return !Actions.empty() ? Actions.back().get() : nullptr;
} }
void TypePromotionTransaction::commit() { bool TypePromotionTransaction::commit() {
for (CommitPt It = Actions.begin(), EndIt = Actions.end(); It != EndIt; for (CommitPt It = Actions.begin(), EndIt = Actions.end(); It != EndIt;
++It) ++It)
(*It)->commit(); (*It)->commit();
bool Modified = !Actions.empty();
Actions.clear(); Actions.clear();
return Modified;
} }
void TypePromotionTransaction::rollback( void TypePromotionTransaction::rollback(
@ -4959,7 +4962,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
TPT.rollback(LastKnownGood); TPT.rollback(LastKnownGood);
return false; return false;
} }
TPT.commit(); bool Modified = TPT.commit();
// Get the combined AddrMode (or the only AddrMode, if we only had one). // Get the combined AddrMode (or the only AddrMode, if we only had one).
ExtAddrMode AddrMode = AddrModes.getAddrMode(); ExtAddrMode AddrMode = AddrModes.getAddrMode();
@ -4973,7 +4976,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
})) { })) {
LLVM_DEBUG(dbgs() << "CGP: Found local addrmode: " << AddrMode LLVM_DEBUG(dbgs() << "CGP: Found local addrmode: " << AddrMode
<< "\n"); << "\n");
return false; return Modified;
} }
// Insert this computation right after this user. Since our caller is // Insert this computation right after this user. Since our caller is
@ -5014,7 +5017,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
// We can't add more than one pointer together, nor can we scale a // We can't add more than one pointer together, nor can we scale a
// pointer (both of which seem meaningless). // pointer (both of which seem meaningless).
if (ResultPtr || AddrMode.Scale != 1) if (ResultPtr || AddrMode.Scale != 1)
return false; return Modified;
ResultPtr = AddrMode.ScaledReg; ResultPtr = AddrMode.ScaledReg;
AddrMode.Scale = 0; AddrMode.Scale = 0;
@ -5031,12 +5034,12 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
Type *ScaledRegTy = AddrMode.ScaledReg->getType(); Type *ScaledRegTy = AddrMode.ScaledReg->getType();
if (cast<IntegerType>(IntPtrTy)->getBitWidth() > if (cast<IntegerType>(IntPtrTy)->getBitWidth() >
cast<IntegerType>(ScaledRegTy)->getBitWidth()) cast<IntegerType>(ScaledRegTy)->getBitWidth())
return false; return Modified;
} }
if (AddrMode.BaseGV) { if (AddrMode.BaseGV) {
if (ResultPtr) if (ResultPtr)
return false; return Modified;
ResultPtr = AddrMode.BaseGV; ResultPtr = AddrMode.BaseGV;
} }
@ -5060,7 +5063,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
!AddrMode.BaseReg && !AddrMode.Scale && !AddrMode.BaseOffs) { !AddrMode.BaseReg && !AddrMode.Scale && !AddrMode.BaseOffs) {
SunkAddr = Constant::getNullValue(Addr->getType()); SunkAddr = Constant::getNullValue(Addr->getType());
} else if (!ResultPtr) { } else if (!ResultPtr) {
return false; return Modified;
} else { } else {
Type *I8PtrTy = Type *I8PtrTy =
Builder.getInt8PtrTy(Addr->getType()->getPointerAddressSpace()); Builder.getInt8PtrTy(Addr->getType()->getPointerAddressSpace());
@ -5145,7 +5148,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
(ScalePtrTy && DL->isNonIntegralPointerType(ScalePtrTy)) || (ScalePtrTy && DL->isNonIntegralPointerType(ScalePtrTy)) ||
(AddrMode.BaseGV && (AddrMode.BaseGV &&
DL->isNonIntegralPointerType(AddrMode.BaseGV->getType()))) DL->isNonIntegralPointerType(AddrMode.BaseGV->getType())))
return false; return Modified;
LLVM_DEBUG(dbgs() << "CGP: SINKING nonlocal addrmode: " << AddrMode LLVM_DEBUG(dbgs() << "CGP: SINKING nonlocal addrmode: " << AddrMode
<< " for " << *MemoryInst << "\n"); << " for " << *MemoryInst << "\n");
@ -5185,7 +5188,7 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr,
Instruction *I = dyn_cast_or_null<Instruction>(Result); Instruction *I = dyn_cast_or_null<Instruction>(Result);
if (I && (Result != AddrMode.BaseReg)) if (I && (Result != AddrMode.BaseReg))
I->eraseFromParent(); I->eraseFromParent();
return false; return Modified;
} }
if (AddrMode.Scale != 1) if (AddrMode.Scale != 1)
V = Builder.CreateMul(V, ConstantInt::get(IntPtrTy, AddrMode.Scale), V = Builder.CreateMul(V, ConstantInt::get(IntPtrTy, AddrMode.Scale),