This is an archive of the discontinued LLVM Phabricator instance.

AArch64: materialize large stack offset into xzr correctly.
ClosedPublic

Authored by t.p.northover on Apr 22 2020, 6:28 AM.

Details

Reviewers
ostannard
Summary

When a stack offset was too big to materialize in a single instruction, we were trying to do it in stages:

adds xD, sp, #imm
adds xD, xD, #imm

Unfortunately, if xD is xzr then the second instruction (adds xzr, xzr, #imm) doesn't exist and wouldn't do what was needed if it did. Instead we can use a temporary register for all but the last addition.

Diff Detail

Event Timeline

t.p.northover created this revision.Apr 22 2020, 6:28 AM
ostannard added inline comments.
llvm/test/CodeGen/AArch64/large-stack-cmp.ll
5

If two adds are being emitted we should test for both of them, and it would be good to test the immediate values too.

Actually, if the destination is XZR, the adds won't have any effect, so surely we don't need to emit any instructions? Could we just early-return without emitting anything if DestReg == XZR?

chill added a subscriber: chill.Apr 22 2020, 8:36 AM
t.p.northover marked 2 inline comments as done.Apr 23 2020, 6:48 AM

Actually, if the destination is XZR, the adds won't have any effect, so surely we don't need to emit any instructions? Could we just early-return without emitting anything if DestReg == XZR?

The operation is actually a comparison so the nzcv produced is live. And since the code is needed anyway I'd be inclined to let generic DCE handle the non-flag-setting variant.

llvm/test/CodeGen/AArch64/large-stack-cmp.ll
5

cmn is the canonical alias for adds when the destination is xzr, so we already are.

t.p.northover marked an inline comment as done.May 6 2020, 2:39 AM

Ping.

This revision is now accepted and ready to land.May 21 2020, 5:09 AM
t.p.northover closed this revision.Jun 1 2020, 2:00 AM

Thanks. Pushed as dace8224f38a.