Index: include/llvm/Transforms/Utils/PredicateInfo.h =================================================================== --- include/llvm/Transforms/Utils/PredicateInfo.h +++ include/llvm/Transforms/Utils/PredicateInfo.h @@ -209,7 +209,7 @@ iplist AllInfos; public: - PredicateInfo(Function &, DominatorTree &, AssumptionCache &); + PredicateInfo(Function &, DominatorTree &, AssumptionCache &, bool = false); ~PredicateInfo(); void verifyPredicateInfo() const; @@ -228,6 +228,7 @@ private: void buildPredicateInfo(); + void removeSSACopies(); void processAssume(IntrinsicInst *, BasicBlock *, SmallPtrSetImpl &); void processBranch(BranchInst *, BasicBlock *, SmallPtrSetImpl &); void processSwitch(SwitchInst *, BasicBlock *, SmallPtrSetImpl &); @@ -246,6 +247,7 @@ DominatorTree &DT; AssumptionCache ∾ OrderedInstructions OI; + bool RemoveSSACopies; // This maps from copy operands to Predicate Info. Note that it does not own // the Predicate Info, they belong to the ValueInfo structs in the ValueInfos // vector. Index: lib/Transforms/Utils/PredicateInfo.cpp =================================================================== --- lib/Transforms/Utils/PredicateInfo.cpp +++ lib/Transforms/Utils/PredicateInfo.cpp @@ -478,6 +478,19 @@ renameUses(OpsToRename); } +// Remove all SSA copies from function F. +void PredicateInfo::removeSSACopies() { + for (DenseMap::iterator + I = PredicateMap.begin(), + E = PredicateMap.end(); + I != E; ++I) { + IntrinsicInst *Copy = + const_cast(cast(I->first)); + Copy->replaceAllUsesWith(Copy->getReturnedArgOperand()); + Copy->eraseFromParent(); + } +} + // Given the renaming stack, make all the operands currently on the stack real // by inserting them into the IR. Return the last operation's value. Value *PredicateInfo::materializeStack(unsigned int &Counter, @@ -689,14 +702,18 @@ } PredicateInfo::PredicateInfo(Function &F, DominatorTree &DT, - AssumptionCache &AC) + AssumptionCache &AC, bool RemoveCopies) : F(F), DT(DT), AC(AC), OI(&DT) { // Push an empty operand info so that we can detect 0 as not finding one ValueInfos.resize(1); buildPredicateInfo(); + RemoveSSACopies = RemoveCopies; } -PredicateInfo::~PredicateInfo() {} +PredicateInfo::~PredicateInfo() { + if (RemoveSSACopies) + removeSSACopies(); +} void PredicateInfo::verifyPredicateInfo() const {}