mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 11:42:57 +01:00
Be more careful when constant-folding PHI nodes.
llvm-svn: 41998
This commit is contained in:
parent
890c3898e0
commit
fd6ec5cf82
@ -673,6 +673,7 @@ namespace {
|
||||
void dump(DenseMap<BasicBlock*, Value*>& d);
|
||||
bool iterateOnFunction(Function &F);
|
||||
Value* CollapsePhi(PHINode* p);
|
||||
bool isSafeReplacement(PHINode* p, Instruction* inst);
|
||||
};
|
||||
|
||||
char GVN::ID = 0;
|
||||
@ -731,7 +732,8 @@ Value* GVN::CollapsePhi(PHINode* p) {
|
||||
if (constVal) {
|
||||
if (Instruction* inst = dyn_cast<Instruction>(constVal)) {
|
||||
if (DT.dominates(inst, p))
|
||||
return inst;
|
||||
if (isSafeReplacement(p, inst))
|
||||
return inst;
|
||||
} else {
|
||||
return constVal;
|
||||
}
|
||||
@ -740,6 +742,19 @@ Value* GVN::CollapsePhi(PHINode* p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool GVN::isSafeReplacement(PHINode* p, Instruction* inst) {
|
||||
if (!isa<PHINode>(inst))
|
||||
return true;
|
||||
|
||||
for (Instruction::use_iterator UI = p->use_begin(), E = p->use_end();
|
||||
UI != E; ++UI)
|
||||
if (PHINode* use_phi = dyn_cast<PHINode>(UI))
|
||||
if (use_phi->getParent() == inst->getParent())
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// GetValueForBlock - Get the value to use within the specified basic block.
|
||||
/// available values are in Phis.
|
||||
Value *GVN::GetValueForBlock(BasicBlock *BB, LoadInst* orig,
|
||||
|
Loading…
Reference in New Issue
Block a user