Fix PR2496, a really nasty bug which involved sinking volatile loads
authorChris Lattner <sabre@nondot.org>
Tue, 8 Jul 2008 17:18:32 +0000 (17:18 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 8 Jul 2008 17:18:32 +0000 (17:18 +0000)
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

lib/Transforms/Scalar/InstructionCombining.cpp

index 8bc909196af6ef4065b76b2375ecb48159c916c1..f8ad98c5170a9c58f18b1bf8e9e67971181f030e 100644 (file)
@@ -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<GetElementPtrInst>(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;