diff options
author | Chris Lattner <sabre@nondot.org> | 2004-10-17 21:22:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-10-17 21:22:38 +0000 |
commit | c30bda7540de573c887e00bb76ac78d85f56acd4 (patch) | |
tree | 7e13ebecba61f21d58e3bef7e82fa99f2e695d15 /lib/Transforms/Scalar/InstructionCombining.cpp | |
parent | 665825e58e5db038d5f3360b07282e21748a7189 (diff) |
hasConstantValue will soon return instructions that don't dominate the PHI node,
so prepare for this.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@17095 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Scalar/InstructionCombining.cpp')
-rw-r--r-- | lib/Transforms/Scalar/InstructionCombining.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 6aef136cf5..784e80429d 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -3364,7 +3364,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { } AddUsersToWorkList(*Caller); } else { - NV = Constant::getNullValue(Caller->getType()); + NV = UndefValue::get(Caller->getType()); } } @@ -3380,9 +3380,23 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) { // PHINode simplification // Instruction *InstCombiner::visitPHINode(PHINode &PN) { - // FIXME: hasConstantValue should ignore undef values! - if (Value *V = hasConstantValue(&PN)) - return ReplaceInstUsesWith(PN, V); + if (Value *V = hasConstantValue(&PN)) { + // If V is an instruction, we have to be certain that it dominates PN. + // However, because we don't have dom info, we can't do a perfect job. + if (Instruction *I = dyn_cast<Instruction>(V)) { + // We know that the instruction dominates the PHI if there are no undef + // values coming in. + for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) + if (isa<UndefValue>(PN.getIncomingValue(i))) { + std::cerr << "HAD TO DISABLE PHI ELIM IN IC!\n"; + V = 0; + break; + } + } + + if (V) + return ReplaceInstUsesWith(PN, V); + } // If the only user of this instruction is a cast instruction, and all of the // incoming values are constants, change this PHI to merge together the casted |