This is an archive of the discontinued LLVM Phabricator instance.

[X86AsmBackend] Emit compact unwind for register-sized stacks
ClosedPublic

Authored by bruno on Oct 15 2015, 4:49 PM.

Details

Summary

For stack frames on the size of a register in x86, a code size optimization
emits "push rax/eax" instead of "sub" for stack allocation. For example:

foo:

.cfi_startproc

BB#0:

pushq %rax

Ltmp0:

.cfi_def_cfa_offset 16
...
.cfi_endproc

However, according to this code snippet in X86AsmBackend:

If the amount of the stack allocation is the size of a register, then
we "push" the RAX/EAX register onto the stack instead of adjusting the
stack pointer with a SUB instruction. We don't support the push of the
RAX/EAX register with compact unwind. So we check for that situation
// here.
if ((NumDefCFAOffsets == SavedRegIdx + 1 &&

   StackSize - PrevStackSize == 1) ||
  (Instrs.size() == 1 && NumDefCFAOffsets == 1 && StackSize == 2))
return CU::UNWIND_MODE_DWARF;

we cannot use compact unwind in this function since encoding "push rax/eax"
isn't supported. This looks overzealous since we really don't need to
encode rax/eax here, specially because we don't care about %rax content, i.e.,
there's no .cfi_offset %rax, <offset> being used.

It's also overzealous in the case where there are pushes for callee saved
registers followed by a "push rax/eax" instead of "sub", in which we should
also be able to encode the callee saved regs and everything else using compact
unwind.

This patch removes this restriction, if the approach looks sane I'll include
a testcase for the compact unwind part.

Diff Detail

Repository
rL LLVM

Event Timeline

bruno updated this revision to Diff 37536.Oct 15 2015, 4:49 PM
bruno retitled this revision from to [X86AsmBackend] Emit compact unwind for register-sized stacks.
bruno updated this object.
bruno added a reviewer: kledzik.
bruno set the repository for this revision to rL LLVM.
bruno added subscribers: llvm-commits, jasonmolenda.
t.p.northover accepted this revision.Oct 28 2015, 3:03 PM
t.p.northover edited edge metadata.

Hi Bruno,

Like you, I think this ought to just work. The compact unwind format shouldn't care how we subtracted 4/8 from the stack. I think you should go for it (with a test, as you said).

And sorry it took so long to look at this properly.

Tim.

This revision is now accepted and ready to land.Oct 28 2015, 3:03 PM

Looks like patch was not committed.

This revision was automatically updated to reflect the committed changes.