This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Fix creation of invalid instructions with XZR register
ClosedPublic

Authored by dmgreen on Feb 7 2023, 12:56 AM.

Details

Summary

A combination of GlobalISel and MachineCombiner can end up creating SUB xrz, (MOVI -2105098) instructions which have not been constant folded. The AArch64MIPeepholeOpt pass will then attempt to create ADD xzr, 513, lsl 12, which is not a valid instruction. This adds a bail out of the transform if the register is xzr/wzr.

Diff Detail

Event Timeline

dmgreen created this revision.Feb 7 2023, 12:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2023, 12:56 AM
dmgreen requested review of this revision.Feb 7 2023, 12:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 7 2023, 12:56 AM
red1bluelost accepted this revision.Feb 7 2023, 12:05 PM

LGTM , interesting catch

This revision is now accepted and ready to land.Feb 7 2023, 12:05 PM
efriedma added inline comments.Feb 7 2023, 12:15 PM
llvm/lib/Target/AArch64/AArch64MIPeepholeOpt.cpp
326

Is the transform assuming that the immediate is on the RHS (operand index 2)? If so, could you update the comment describing the transform to note that explicitly? Otherwise, it isn't really clear why operand index 1 is special.

dmgreen added inline comments.Feb 8 2023, 4:11 AM
llvm/lib/Target/AArch64/AArch64MIPeepholeOpt.cpp
326

Yep that could do with a better comment. Will do, thanks.