Don't drop the alignment on a memcpy intrinsic when producing a store. This is
only a missed optimization opportunity if the store is over-aligned, but a
miscompile if the store's new type has a higher natural alignment than the
memcpy did. Fixes PR13920!


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164641 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/SROA.cpp b/lib/Transforms/Scalar/SROA.cpp
index 1b3e8f9..04e350c 100644
--- a/lib/Transforms/Scalar/SROA.cpp
+++ b/lib/Transforms/Scalar/SROA.cpp
@@ -2272,8 +2272,9 @@
                                     getName(".insert"));
     }
 
-    Value *Store = IRB.CreateStore(Src, DstPtr, II.isVolatile());
-    (void)Store;
+    StoreInst *Store = cast<StoreInst>(IRB.CreateStore(Src, DstPtr,
+                                                       II.isVolatile()));
+    Store->setAlignment(II.getAlignment());
     DEBUG(dbgs() << "          to: " << *Store << "\n");
     return !II.isVolatile();
   }