gollvm: revise previous alignment-related changes

In CL 234337 some of the alloca creation helpers in the bridge were
changed to specify an explicit alignment value. In a couple of places
getPrefTypeAlign was used, which should have been getABITypeAlign
instead. This patch fixes this up.

Change-Id: I5ef5962514b469d0152a12b48232d40c7f94ddc4
Reviewed-on: https://go-review.googlesource.com/c/gollvm/+/235238
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: eric fang <eric.fang@arm.com>
diff --git a/bridge/go-llvm-bfunction.cpp b/bridge/go-llvm-bfunction.cpp
index 55cdb9e..5d1f78d 100644
--- a/bridge/go-llvm-bfunction.cpp
+++ b/bridge/go-llvm-bfunction.cpp
@@ -79,7 +79,7 @@
 {
   llvm::Instruction *insBefore = nullptr;
   TypeManager *tm = abiOracle_->tm();
-  llvm::Align aaAlign = tm->datalayout()->getPrefTypeAlign(typ);
+  llvm::Align aaAlign = tm->datalayout()->getABITypeAlign(typ);
   llvm::Value *aaSize = nullptr;
   llvm::Instruction *inst = new llvm::AllocaInst(typ, 0, aaSize, aaAlign,
                                                  name, insBefore);
@@ -298,7 +298,7 @@
   TypeManager *tm = abiOracle_->tm();
   llvm::Type *lltype = btype->type();
   llvm::Instruction *insBefore = nullptr;
-  llvm::Align aaAlign = tm->datalayout()->getPrefTypeAlign(lltype);
+  llvm::Align aaAlign = tm->datalayout()->getABITypeAlign(lltype);
   llvm::Value *aaSize = nullptr;
   llvm::Instruction *inst = new llvm::AllocaInst(lltype, 0, aaSize, aaAlign,
                                                  name, insBefore);
diff --git a/bridge/go-llvm-bnode.cpp b/bridge/go-llvm-bnode.cpp
index 589a881..13d47ac 100644
--- a/bridge/go-llvm-bnode.cpp
+++ b/bridge/go-llvm-bnode.cpp
@@ -522,7 +522,7 @@
   assert(varType);
   llvm::Type *typ = varType->type();
   llvm::Instruction *insBefore = nullptr;
-  llvm::Align aaAlign = tm->datalayout()->getPrefTypeAlign(typ);
+  llvm::Align aaAlign = tm->datalayout()->getABITypeAlign(typ);
   llvm::Value *aaSize = nullptr;
   llvm::Instruction *inst = new llvm::AllocaInst(typ, 0, aaSize, aaAlign,
                                                  name, insBefore);
diff --git a/bridge/go-llvm-typemanager.cpp b/bridge/go-llvm-typemanager.cpp
index 2f5199d..7c346aa 100644
--- a/bridge/go-llvm-typemanager.cpp
+++ b/bridge/go-llvm-typemanager.cpp
@@ -1848,7 +1848,7 @@
   // Now create struct type itself.  Q: should this be
   // getTypeAllocSize here instead of getTypeSizeInBits?
   uint64_t sizeInBits = datalayout_->getTypeSizeInBits(bst->type());
-  uint32_t alignInBits = datalayout_->getPrefTypeAlignment(bst->type());
+  uint32_t alignInBits = datalayout_->getABITypeAlignment(bst->type());
   llvm::DIType *derivedFrom = nullptr;
   llvm::DICompositeType *dist =
       dibuilder.createStructType(scope, typToString(bst),
@@ -1976,7 +1976,7 @@
       uint64_t arElems = bat->nelSize();
       uint64_t arSize = datalayout_->getTypeSizeInBits(bat->type());
       uint64_t arAlign =
-          datalayout_->getPrefTypeAlignment(bat->elemType()->type());
+          datalayout_->getABITypeAlignment(bat->elemType()->type());
       llvm::SmallVector<llvm::Metadata *, 1> subscripts;
       subscripts.push_back(dibuilder.getOrCreateSubrange(0, arElems));
       llvm::DINodeArray subsAr = dibuilder.getOrCreateArray(subscripts);
diff --git a/bridge/go-llvm.cpp b/bridge/go-llvm.cpp
index 1872f86..7dbe0cd 100644
--- a/bridge/go-llvm.cpp
+++ b/bridge/go-llvm.cpp
@@ -3596,7 +3596,7 @@
   // Create temporary into which caught result will be stored
   std::string tag(be_->namegen("ehtmp"));
   llvm::Instruction *insBefore = nullptr;
-  llvm::Align aaAlign = be_->datalayout().getPrefTypeAlign(eht);
+  llvm::Align aaAlign = be_->datalayout().getABITypeAlign(eht);
   llvm::Value *aaSize = nullptr;
   llvm::Instruction *ai = new llvm::AllocaInst(eht, 0, aaSize, aaAlign,
                                                tag, insBefore);
diff --git a/unittests/BackendCore/BackendExprTests.cpp b/unittests/BackendCore/BackendExprTests.cpp
index 892547c..54b37da 100644
--- a/unittests/BackendCore/BackendExprTests.cpp
+++ b/unittests/BackendCore/BackendExprTests.cpp
@@ -496,11 +496,11 @@
     define void @foo(i8* nest %nest.0) #0 {
   entry:
     %tmp.3 = alloca { double, double }, align 8
-    %tmp.2 = alloca { float, float }, align 8
-    %tmp.1 = alloca { float, float }, align 8
+    %tmp.2 = alloca { float, float }, align 4
+    %tmp.1 = alloca { float, float }, align 4
     %tmp.0 = alloca { double, double }, align 8
-    %a = alloca { float, float }, align 8
-    %b = alloca { float, float }, align 8
+    %a = alloca { float, float }, align 4
+    %b = alloca { float, float }, align 4
     %x = alloca { double, double }, align 8
     %y = alloca { double, double }, align 8
     %cast.0 = bitcast { float, float }* %a to i8*
@@ -1458,8 +1458,8 @@
     define void @foo({ [16 x i32], i32 }* sret %sret.formal.0, i8* nest %nest.0, { [16 x i32], i32 }* byval %p0, i32 %p1) #0 {
   entry:
     %p1.addr = alloca i32, align 4
-    %a = alloca { [16 x i32], i32 }, align 8
-    %tmpv.0 = alloca { [16 x i32], i32 }, align 8
+    %a = alloca { [16 x i32], i32 }, align 4
+    %tmpv.0 = alloca { [16 x i32], i32 }, align 4
     store i32 %p1, i32* %p1.addr, align 4
     %p1.ld.0 = load i32, i32* %p1.addr, align 4
     %icmp.0 = icmp slt i32 %p1.ld.0, 7
@@ -1533,8 +1533,8 @@
     define void @foo({ [16 x i32], i32 }* sret %sret.formal.0, i8* nest %nest.0, { [16 x i32], i32 }* %p0, i32 %p1) #0 {
   entry:
     %p1.addr = alloca i32, align 4
-    %a = alloca { [16 x i32], i32 }, align 8
-    %tmpv.0 = alloca { [16 x i32], i32 }, align 8
+    %a = alloca { [16 x i32], i32 }, align 4
+    %tmpv.0 = alloca { [16 x i32], i32 }, align 4
     store i32 %p1, i32* %p1.addr, align 4
     %p1.ld.0 = load i32, i32* %p1.addr, align 4
     %icmp.0 = icmp slt i32 %p1.ld.0, 7
diff --git a/unittests/BackendCore/BackendStmtTests.cpp b/unittests/BackendCore/BackendStmtTests.cpp
index 96ed5c5..5bd959e 100644
--- a/unittests/BackendCore/BackendStmtTests.cpp
+++ b/unittests/BackendCore/BackendStmtTests.cpp
@@ -702,8 +702,8 @@
     %ehtmp.0 = alloca { i8*, i32 }, align 8
     %x = alloca i64, align 8
     %y = alloca i8, align 1
-    %sret.actual.0 = alloca { i8, i8 }, align 8
-    %sret.actual.1 = alloca { i8, i8 }, align 8
+    %sret.actual.0 = alloca { i8, i8 }, align 1
+    %sret.actual.1 = alloca { i8, i8 }, align 1
     %finvar.0 = alloca i8, align 1
     store i64 0, i64* %x, align 8
     store i8 0, i8* %y, align 1
diff --git a/unittests/BackendCore/BackendVarTests.cpp b/unittests/BackendCore/BackendVarTests.cpp
index 29f18e1..93b9908 100644
--- a/unittests/BackendCore/BackendVarTests.cpp
+++ b/unittests/BackendCore/BackendVarTests.cpp
@@ -537,7 +537,7 @@
     define void @foo(i8* nest %nest.0) #0 {
   entry:
     %x = alloca i32, align 4
-    %y = alloca { i32, i32 }, align 8
+    %y = alloca { i32, i32 }, align 4
     %0 = bitcast i32* %x to i8*
     call void @llvm.lifetime.start.p0i8(i64 4, i8* %0)
     %1 = bitcast { i32, i32 }* %y to i8*
@@ -683,7 +683,7 @@
   DECLARE_EXPECTED_OUTPUT(exp, R"RAW_RESULT(
     define void @foo(i8* nest %nest.0) #0 {
   entry:
-    %localemptys2f = alloca { {}, {} }, align 8
+    %localemptys2f = alloca { {}, {} }, align 1
     %localemptyintar = alloca [0 x i32], align 4
     ret void
   }