Index: llvm/lib/CodeGen/CodeGenPrepare.cpp =================================================================== --- llvm/lib/CodeGen/CodeGenPrepare.cpp +++ llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -2821,6 +2821,9 @@ /// Undo all the changes made after the given point. void rollback(ConstRestorationPt Point); + /// Returns true if any action was applied since the given point. + bool changed(ConstRestorationPt Point); + /// Get the current restoration point. ConstRestorationPt getRestorationPoint() const; @@ -2937,6 +2940,11 @@ } } +bool TypePromotionTransaction::changed( + TypePromotionTransaction::ConstRestorationPt Point) { + return !Actions.empty() && Point != Actions.back().get(); +} + namespace { /// A helper class for matching addressing modes. @@ -4952,7 +4960,6 @@ TPT.rollback(LastKnownGood); return false; } - TPT.commit(); // Get the combined AddrMode (or the only AddrMode, if we only had one). ExtAddrMode AddrMode = AddrModes.getAddrMode(); @@ -4966,7 +4973,7 @@ })) { LLVM_DEBUG(dbgs() << "CGP: Found local addrmode: " << AddrMode << "\n"); - return false; + return TPT.changed(LastKnownGood); } // Insert this computation right after this user. Since our caller is @@ -5006,8 +5013,9 @@ if (AddrMode.Scale && AddrMode.ScaledReg->getType()->isPointerTy()) { // We can't add more than one pointer together, nor can we scale a // pointer (both of which seem meaningless). - if (ResultPtr || AddrMode.Scale != 1) - return false; + if (ResultPtr || AddrMode.Scale != 1) { + return TPT.changed(LastKnownGood); + } ResultPtr = AddrMode.ScaledReg; AddrMode.Scale = 0; @@ -5023,13 +5031,15 @@ if (AddrMode.Scale) { Type *ScaledRegTy = AddrMode.ScaledReg->getType(); if (cast(IntPtrTy)->getBitWidth() > - cast(ScaledRegTy)->getBitWidth()) - return false; + cast(ScaledRegTy)->getBitWidth()) { + return TPT.changed(LastKnownGood); + } } if (AddrMode.BaseGV) { - if (ResultPtr) - return false; + if (ResultPtr) { + return TPT.changed(LastKnownGood); + } ResultPtr = AddrMode.BaseGV; } @@ -5053,7 +5063,7 @@ !AddrMode.BaseReg && !AddrMode.Scale && !AddrMode.BaseOffs) { SunkAddr = Constant::getNullValue(Addr->getType()); } else if (!ResultPtr) { - return false; + return TPT.changed(LastKnownGood); } else { Type *I8PtrTy = Builder.getInt8PtrTy(Addr->getType()->getPointerAddressSpace()); @@ -5137,8 +5147,9 @@ (BasePtrTy && DL->isNonIntegralPointerType(BasePtrTy)) || (ScalePtrTy && DL->isNonIntegralPointerType(ScalePtrTy)) || (AddrMode.BaseGV && - DL->isNonIntegralPointerType(AddrMode.BaseGV->getType()))) - return false; + DL->isNonIntegralPointerType(AddrMode.BaseGV->getType()))) { + return TPT.changed(LastKnownGood); + } LLVM_DEBUG(dbgs() << "CGP: SINKING nonlocal addrmode: " << AddrMode << " for " << *MemoryInst << "\n"); @@ -5178,7 +5189,7 @@ Instruction *I = dyn_cast_or_null(Result); if (I && (Result != AddrMode.BaseReg)) I->eraseFromParent(); - return false; + return TPT.changed(LastKnownGood); } if (AddrMode.Scale != 1) V = Builder.CreateMul(V, ConstantInt::get(IntPtrTy, AddrMode.Scale), @@ -5236,6 +5247,8 @@ SunkAddrs.clear(); } } + + TPT.commit(); ++NumMemoryInsts; return true; }