diff options
author | Chris Lattner <sabre@nondot.org> | 2008-04-29 17:13:43 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-04-29 17:13:43 +0000 |
commit | 9233c124c9dc0dd965504547e8852fcdf891aecd (patch) | |
tree | 1fd68beaec5f3ea891ccd8d4c46258b450b85f23 /llvm/lib/Transforms | |
parent | a8197366db6f6304cb9bfeb8d0ca9a1b9e30860d (diff) | |
download | bcm5719-llvm-9233c124c9dc0dd965504547e8852fcdf891aecd.tar.gz bcm5719-llvm-9233c124c9dc0dd965504547e8852fcdf891aecd.zip |
fix a subtle volatile handling bug.
llvm-svn: 50428
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index c707e6ee670..86aca073abc 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -9432,16 +9432,21 @@ Instruction *InstCombiner::FoldPHIArgOpIntoPHI(PHINode &PN) { // Insert and return the new operation. if (CastInst* FirstCI = dyn_cast<CastInst>(FirstInst)) return CastInst::create(FirstCI->getOpcode(), PhiVal, PN.getType()); - else if (isa<LoadInst>(FirstInst)) - return new LoadInst(PhiVal, "", isVolatile); - else if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(FirstInst)) + if (BinaryOperator *BinOp = dyn_cast<BinaryOperator>(FirstInst)) return BinaryOperator::create(BinOp->getOpcode(), PhiVal, ConstantOp); - else if (CmpInst *CIOp = dyn_cast<CmpInst>(FirstInst)) + if (CmpInst *CIOp = dyn_cast<CmpInst>(FirstInst)) return CmpInst::create(CIOp->getOpcode(), CIOp->getPredicate(), PhiVal, ConstantOp); - else - assert(0 && "Unknown operation"); - return 0; + assert(isa<LoadInst>(FirstInst) && "Unknown operation"); + + // If this was a volatile load that we are merging, make sure to loop through + // and mark all the input loads as non-volatile. If we don't do this, we will + // insert a new volatile load and the old ones will not be deletable. + if (isVolatile) + for (unsigned i = 0, e = PN.getNumIncomingValues(); i != e; ++i) + cast<LoadInst>(PN.getIncomingValue(i))->setVolatile(false); + + return new LoadInst(PhiVal, "", isVolatile); } /// DeadPHICycle - Return true if this PHI node is only used by a PHI node cycle |