This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Fix an immediate out of range for large realignments on Windows
ClosedPublic

Authored by mstorsjo on Jul 17 2023, 5:26 AM.

Details

Summary

This fixes https://github.com/llvm/llvm-project/issues/63701.

Not sure if there's any more elegant way to do this at this level;
this seems to fix the issue at least.

(Should the MI operand registers be marked with more flags, as killed etc?)

Diff Detail

Event Timeline

mstorsjo created this revision.Jul 17 2023, 5:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 5:26 AM
mstorsjo requested review of this revision.Jul 17 2023, 5:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 17 2023, 5:26 AM
efriedma accepted this revision.Jul 17 2023, 8:16 AM

LGTM

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
1748

You could stick a kill flag on x16 here, I guess, although it doesn't matter much this late in the pipeline.

Probably we should stick a FrameSetup flag on the add (for both cases).

1753

If we care, for constants up to 1<<23, we can use a shifted immediate. ("add sp, sp, #1, lsl #12" etc.) But probably not worth bothering.

This revision is now accepted and ready to land.Jul 17 2023, 8:16 AM
mstorsjo added inline comments.Jul 18 2023, 12:19 AM
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
1748

Thanks, will do.

1753

Yeah, but that doesn't work if the immediate contains bit set both below and above the 12 bit boundary; the constants here are like 0x1ff0, so it's still 0x1, lsl #12 combined with 0xff0.

mstorsjo updated this revision to Diff 541352.Jul 18 2023, 12:28 AM

Added some kill/define flags for registers, and missing FrameSetup flags.

Will push later.

mstorsjo added inline comments.Jul 18 2023, 8:29 AM
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
1748

SP wasn’t a valid register for ADDXrr here, as shown by the bots with expensive checks enabled.

I tried grepping around to see what instruction name I should use here instead, but didn’t have any luck.

Is it possible to get some dump of what instruction names it uses internally if I assemble the desired instruction from a .s file, or does that not pass through those layers at all?

mstorsjo reopened this revision.Jul 18 2023, 8:29 AM
This revision is now accepted and ready to land.Jul 18 2023, 8:29 AM
efriedma added inline comments.Jul 18 2023, 9:36 AM
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
1748
$ echo "add x16, sp, x16" | llvm-mc -show-inst -triple=aarch64
        .text
        add     x16, sp, x16                    // <MCInst #1439 ADDXrx64
                                        //  <MCOperand Reg:235>
                                        //  <MCOperand Reg:6>
                                        //  <MCOperand Reg:235>
                                        //  <MCOperand Imm:24>>

This is an MCInst, not a MachineInstr, but should be enough to get the idea. The immediate is an extend (i.e. the instruction is actually "add x16, sp, x16, uxtx #0").

mstorsjo updated this revision to Diff 541708.Jul 18 2023, 1:33 PM

Updated to use ADDXrx64 which works properly for SP, fixing the tests when expensive checks are enabled, and also fixing the actually encoded instruction.

This revision was landed with ongoing or failed builds.Jul 19 2023, 1:20 AM
This revision was automatically updated to reflect the committed changes.