Skip to content

Commit fd6c0c9

Browse files
committed
test
1 parent 26a0962 commit fd6c0c9

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

llvm/include/llvm/Transforms/Utils/PredicateInfo.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252

5353
#include "llvm/ADT/DenseMap.h"
5454
#include "llvm/ADT/SmallSet.h"
55+
#include "llvm/ADT/SmallVector.h"
5556
#include "llvm/IR/Instructions.h"
5657
#include "llvm/IR/PassManager.h"
5758
#include "llvm/IR/ValueHandle.h"
@@ -186,6 +187,9 @@ class PredicateInfo {
186187
const PredicateBase *getPredicateInfoFor(const Value *V) const {
187188
return PredicateMap.lookup(V);
188189
}
190+
const SmallVector<WeakVH> &getInsertedSSACopies() const {
191+
return InsertedSSACopies;
192+
}
189193

190194
protected:
191195
// Used by PredicateInfo annotater, dumpers, and wrapper pass.
@@ -199,6 +203,7 @@ class PredicateInfo {
199203
// the Predicate Info, they belong to the ValueInfo structs in the ValueInfos
200204
// vector.
201205
DenseMap<const Value *, const PredicateBase *> PredicateMap;
206+
SmallVector<WeakVH> InsertedSSACopies;
202207
};
203208

204209
/// Printer pass for \c PredicateInfo.

llvm/lib/Transforms/Utils/PredicateInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ Value *PredicateInfoBuilder::materializeStack(unsigned int &Counter,
524524
BitCastInst *PIC = CreateSSACopy(getBranchTerminator(ValInfo), Op,
525525
Op->getName() + "." + Twine(Counter++));
526526
PI.PredicateMap.insert({PIC, ValInfo});
527+
PI.InsertedSSACopies.push_back(PIC);
527528
Result.Def = PIC;
528529
} else {
529530
auto *PAssume = dyn_cast<PredicateAssume>(ValInfo);
@@ -533,6 +534,7 @@ Value *PredicateInfoBuilder::materializeStack(unsigned int &Counter,
533534
// directly before it, assume(i1 true) is not a useful fact.
534535
BitCastInst *PIC = CreateSSACopy(PAssume->AssumeInst->getNextNode(), Op);
535536
PI.PredicateMap.insert({PIC, ValInfo});
537+
PI.InsertedSSACopies.push_back(PIC);
536538
Result.Def = PIC;
537539
}
538540
}

llvm/lib/Transforms/Utils/SCCPSolver.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/Analysis/ValueTracking.h"
2222
#include "llvm/IR/IRBuilder.h"
2323
#include "llvm/IR/InstVisitor.h"
24+
#include "llvm/IR/Instructions.h"
2425
#include "llvm/IR/NoFolder.h"
2526
#include "llvm/IR/PatternMatch.h"
2627
#include "llvm/Support/Casting.h"
@@ -775,18 +776,12 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
775776
if (It == FnPredicateInfo.end())
776777
return;
777778

778-
for (BasicBlock &BB : F) {
779-
for (Instruction &Inst : llvm::make_early_inc_range(BB)) {
780-
if (auto *BC = dyn_cast<BitCastInst>(&Inst)) {
781-
if (BC->getType() == BC->getOperand(0)->getType()) {
782-
if (It->second->getPredicateInfoFor(&Inst)) {
783-
Value *Op = BC->getOperand(0);
784-
Inst.replaceAllUsesWith(Op);
785-
Inst.eraseFromParent();
786-
}
787-
}
788-
}
789-
}
779+
for (auto &SSACopy : It->second->getInsertedSSACopies()) {
780+
auto *BC = cast_or_null<Instruction>(SSACopy);
781+
if (!BC)
782+
continue;
783+
BC->replaceAllUsesWith(BC->getOperand(0));
784+
BC->eraseFromParent();
790785
}
791786
}
792787

0 commit comments

Comments
 (0)