Subzero: Make sure alloca with align=0 is handled correctly.
1. Modify dump() to match LLVM.
2. If it weren't for minimum stack alignment, the alignment code would be broken, so add a test in case the alignment code changes.
BUG= none
R=jvoung@chromium.org, kschimpf@google.com
Review URL: https://codereview.chromium.org/557533003
diff --git a/src/IceInst.cpp b/src/IceInst.cpp
index cfcaad3..43291ce 100644
--- a/src/IceInst.cpp
+++ b/src/IceInst.cpp
@@ -534,7 +534,8 @@
dumpDest(Func);
Str << " = alloca i8, i32 ";
getSizeInBytes()->dump(Func);
- Str << ", align " << getAlignInBytes();
+ if (getAlignInBytes())
+ Str << ", align " << getAlignInBytes();
}
void InstArithmetic::dump(const Cfg *Func) const {
diff --git a/src/IceTargetLoweringX8632.cpp b/src/IceTargetLoweringX8632.cpp
index 756508e..c3a6e4d 100644
--- a/src/IceTargetLoweringX8632.cpp
+++ b/src/IceTargetLoweringX8632.cpp
@@ -1118,6 +1118,9 @@
Operand *TotalSize = legalize(Inst->getSizeInBytes());
Variable *Dest = Inst->getDest();
uint32_t AlignmentParam = Inst->getAlignInBytes();
+ // For default align=0, set it to the real value 1, to avoid any
+ // bit-manipulation problems below.
+ AlignmentParam = std::max(AlignmentParam, 1u);
// LLVM enforces power of 2 alignment.
assert((AlignmentParam & (AlignmentParam - 1)) == 0);
diff --git a/tests_lit/llvm2ice_tests/alloc.ll b/tests_lit/llvm2ice_tests/alloc.ll
index 80bba30..d690a19 100644
--- a/tests_lit/llvm2ice_tests/alloc.ll
+++ b/tests_lit/llvm2ice_tests/alloc.ll
@@ -104,6 +104,19 @@
; CHECK: mov dword ptr [esp], eax
; CHECK: call f2
+; Test alloca with default (0) alignment.
+define void @align0(i32 %n) {
+entry:
+ %array = alloca i8, i32 %n
+ %__2 = ptrtoint i8* %array to i32
+ call void @f2(i32 %__2)
+ ret void
+}
+; CHECK-LABEL: align0
+; CHECK: add [[REG:.*]], 15
+; CHECK: and [[REG]], -16
+; CHECK: sub esp, [[REG]]
+
define void @f2(i32 %ignored) {
entry:
ret void