Commit 72a8f8da by Jim Stichnoth

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
parent f12355ec
......@@ -534,7 +534,8 @@ void InstAlloca::dump(const Cfg *Func) const {
dumpDest(Func);
Str << " = alloca i8, i32 ";
getSizeInBytes()->dump(Func);
Str << ", align " << getAlignInBytes();
if (getAlignInBytes())
Str << ", align " << getAlignInBytes();
}
void InstArithmetic::dump(const Cfg *Func) const {
......
......@@ -1118,6 +1118,9 @@ void TargetX8632::lowerAlloca(const InstAlloca *Inst) {
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);
......
......@@ -104,6 +104,19 @@ entry:
; 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment