Set load/store alignment when doing ABI coercions.
 - Currently, this is producing poor code, but we prefer correctness
   to performance for now. Eventually we should be able to generally
   avoid having to set the alignment when we control the alignment of
   the alloca.

 - This knocks out 33/1000 failures on my single argument ABI tests,
   down to 22/1000 and 18 of these appear to be gcc bugs. Woot.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64001 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 9c4472e..fbc421c 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -959,7 +959,10 @@
   if (SrcSize == DstSize) {
     llvm::Value *Casted =
       CGF.Builder.CreateBitCast(SrcPtr, llvm::PointerType::getUnqual(Ty));
-    return CGF.Builder.CreateLoad(Casted);
+    llvm::LoadInst *Load = CGF.Builder.CreateLoad(Casted);
+    // FIXME: Use better alignment / avoid requiring aligned load.
+    Load->setAlignment(1);
+    return Load;
   } else {
     assert(SrcSize < DstSize && "Coercion is losing source bits!");
 
@@ -968,7 +971,10 @@
     llvm::Value *Tmp = CGF.CreateTempAlloca(Ty);
     llvm::Value *Casted = 
       CGF.Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(SrcTy));
-    CGF.Builder.CreateStore(CGF.Builder.CreateLoad(SrcPtr), Casted);
+    llvm::StoreInst *Store = 
+      CGF.Builder.CreateStore(CGF.Builder.CreateLoad(SrcPtr), Casted);
+    // FIXME: Use better alignment / avoid requiring aligned store.
+    Store->setAlignment(1);
     return CGF.Builder.CreateLoad(Tmp);
   }
 }
@@ -992,7 +998,8 @@
   if (SrcSize == DstSize) {
     llvm::Value *Casted =
       CGF.Builder.CreateBitCast(DstPtr, llvm::PointerType::getUnqual(SrcTy));
-    CGF.Builder.CreateStore(Src, Casted);
+    // FIXME: Use better alignment / avoid requiring aligned store.
+    CGF.Builder.CreateStore(Src, Casted)->setAlignment(1);
   } else {
     assert(SrcSize > DstSize && "Coercion is missing bits!");
     
@@ -1002,7 +1009,10 @@
     CGF.Builder.CreateStore(Src, Tmp);
     llvm::Value *Casted = 
       CGF.Builder.CreateBitCast(Tmp, llvm::PointerType::getUnqual(DstTy));
-    CGF.Builder.CreateStore(CGF.Builder.CreateLoad(Casted), DstPtr);
+    llvm::LoadInst *Load = CGF.Builder.CreateLoad(Casted);
+    // FIXME: Use better alignment / avoid requiring aligned load.
+    Load->setAlignment(1);
+    CGF.Builder.CreateStore(Load, DstPtr);
   }
 }