From: Chris Lattner Date: Tue, 8 Jul 2008 17:18:32 +0000 (+0000) Subject: Fix PR2496, a really nasty bug which involved sinking volatile loads X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=710429645ac0327dbe83ceab040fe04d2cfff605;p=oota-llvm.git Fix PR2496, a really nasty bug which involved sinking volatile loads into phis. This is actually the same bug as PR2262 / 2008-04-29-VolatileLoadDontMerge.ll, but I missed checking the first predecessor for multiple successors. Testcase here: InstCombine/2008-07-08-VolatileLoadMerge.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53240 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 8bc909196af..f8ad98c5170 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -9354,6 +9354,14 @@ Instruction *InstCombiner::FoldPHIArgOpIntoPHI(PHINode &PN) { if (LI->getParent() != PN.getIncomingBlock(0) || !isSafeToSinkLoad(LI)) return 0; + + // If the PHI is of volatile loads and the load block has multiple + // successors, sinking it would remove a load of the volatile value from + // the path through the other successor. + if (isVolatile && + LI->getParent()->getTerminator()->getNumSuccessors() != 1) + return 0; + } else if (isa(FirstInst)) { if (FirstInst->getNumOperands() == 2) return FoldPHIArgBinOpIntoPHI(PN); @@ -9380,9 +9388,9 @@ Instruction *InstCombiner::FoldPHIArgOpIntoPHI(PHINode &PN) { !isSafeToSinkLoad(LI)) return 0; - // If the PHI is volatile and its block has multiple successors, sinking - // it would remove a load of the volatile value from the path through the - // other successor. + // If the PHI is of volatile loads and the load block has multiple + // successors, sinking it would remove a load of the volatile value from + // the path through the other successor. if (isVolatile && LI->getParent()->getTerminator()->getNumSuccessors() != 1) return 0;