fix instcombine to only do store sinking when the alignments
authorChris Lattner <sabre@nondot.org>
Mon, 2 Nov 2009 02:06:37 +0000 (02:06 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 2 Nov 2009 02:06:37 +0000 (02:06 +0000)
of the two loads agree.  Propagate that onto the new store.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85772 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/InstructionCombining.cpp
test/Transforms/InstCombine/store.ll

index 07681d15d87634f89b1c881069ee14f5d89f0b2b..ba899bf15bbac73e0866d1f72370a12ccdc010b0 100644 (file)
@@ -11943,9 +11943,11 @@ bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst &SI) {
         return false;
       --BBI;
     }
-    // If this isn't a store, or isn't a store to the same location, bail out.
+    // If this isn't a store, isn't a store to the same location, or if the
+    // alignments differ, bail out.
     OtherStore = dyn_cast<StoreInst>(BBI);
-    if (!OtherStore || OtherStore->getOperand(1) != SI.getOperand(1))
+    if (!OtherStore || OtherStore->getOperand(1) != SI.getOperand(1) ||
+        OtherStore->getAlignment() != SI.getAlignment())
       return false;
   } else {
     // Otherwise, the other block ended with a conditional branch. If one of the
@@ -11960,7 +11962,8 @@ bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst &SI) {
     for (;; --BBI) {
       // Check to see if we find the matching store.
       if ((OtherStore = dyn_cast<StoreInst>(BBI))) {
-        if (OtherStore->getOperand(1) != SI.getOperand(1))
+        if (OtherStore->getOperand(1) != SI.getOperand(1) ||
+            OtherStore->getAlignment() != SI.getAlignment())
           return false;
         break;
       }
@@ -11995,7 +11998,8 @@ bool InstCombiner::SimplifyStoreAtEndOfBlock(StoreInst &SI) {
   // insert it.
   BBI = DestBB->getFirstNonPHI();
   InsertNewInstBefore(new StoreInst(MergedVal, SI.getOperand(1),
-                                    OtherStore->isVolatile()), *BBI);
+                                    OtherStore->isVolatile(),
+                                    SI.getAlignment()), *BBI);
   
   // Nuke the old stores.
   EraseInstFromFunction(SI);
index 54f16213178458043af166c894e87fb0c3c73cc7..314441eb86530bb862e6e8509e89ff31d3ac456d 100644 (file)
@@ -64,3 +64,21 @@ Cont:
 ; CHECK-NEXT:  ret i32 %storemerge
 }
 
+; "if then"
+define void @test5(i1 %C, i32* %P) {
+       store i32 47, i32* %P, align 1
+        br i1 %C, label %Cond, label %Cont
+
+Cond:
+        store i32 -987654321, i32* %P, align 1
+        br label %Cont
+
+Cont:
+       ret void
+; CHECK: @test5
+; CHECK: Cont:
+; CHECK-NEXT:  %storemerge = phi i32
+; CHECK-NEXT:  store i32 %storemerge, i32* %P, align 1
+; CHECK-NEXT:  ret void
+}
+