This is an archive of the discontinued LLVM Phabricator instance.

ARM: fix Thumb2 CodeGen for ldrex with folded frame-index
ClosedPublic

Authored by t.p.northover on Sep 5 2018, 3:44 AM.

Details

Summary

As reported in https://llvm.org/PR38828, Thumb2 ldrex instructions accessing local variables are not being handled correctly. In release builds this results in bad code, in debug builds an assertion.

The issue is that the t2LDREX and t2STREX instructions are marked with AddrModeNone, but rewriteT2FrameIndex relies on knowing the addressing-mode so that it can fold a stack offset into the instruction. This patch adds a new addressing-mode to handle the situation and applies it to the relevant instructions.

Neither the byte/half/dword forms, nor any ARM variant is affected because they do not allow an offset to the base register.

Diff Detail

Repository
rL LLVM

Event Timeline

t.p.northover created this revision.Sep 5 2018, 3:44 AM

Do you need to update estimateRSStackSizeLimit?

Bother, yes I do. That's going to be fun to write a test for so it'll probably have to wait until tomorrow.

Added the addressing-mode to ARMFrameLowering. The only other place that uses them appears to be optional (for an efficiency gain), so I skipped that.

efriedma added inline comments.Sep 6 2018, 12:09 PM
llvm/lib/Target/ARM/ARMFrameLowering.cpp
1519

I'm not sure I understand why AddrModeT2_i12 needs special handling, but AddrModeT2_ldrex doesn't; I think they have a similar restriction that they only support positive offsets?

t.p.northover added inline comments.Sep 6 2018, 2:40 PM
llvm/lib/Target/ARM/ARMFrameLowering.cpp
1519

The rewriteT2FrameIndex code has special cases to convert between i12 and i8 addressing-modes by switching between add/sub (see Thumb2InstrInfo.cpp:576). That means that even though the notional limit for something that's i12 is 12 bits, it may end up in an instruction with an 8-bit limit -- hence the case below.

There's no such toggle for an ldrex.

efriedma accepted this revision.Sep 6 2018, 2:42 PM

LGTM

llvm/lib/Target/ARM/ARMFrameLowering.cpp
1519

I guess it's fine, then.

This revision is now accepted and ready to land.Sep 6 2018, 2:42 PM
t.p.northover closed this revision.Sep 7 2018, 5:19 AM

Thanks. Committed as r341642.