This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Restructure MOVi32imm expansion to not do pointless instructions
ClosedPublic

Authored by john.brawn on Jul 11 2023, 3:43 AM.

Details

Summary

The expansion of the various MOVi32imm pseudo-instructions works by splitting the operand into components (either halfwords or bytes) and emitting instructions to combine those components into the final result. When the operand is an immediate with some components being zero this can result in pointless instructions that just add zero.

Avoid this by restructuring things so that a separate function handles splitting the operand into components, then don't emit the component if it is a zero immediate. This is straightforward for movw/movt, where we just don't emit the movt if it's zero, but the thumb1 expansion using mov/add/lsl is more complex, as even when we don't emit a given byte we still need to get the shift correct.

Diff Detail

Event Timeline

john.brawn created this revision.Jul 11 2023, 3:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2023, 3:43 AM
john.brawn requested review of this revision.Jul 11 2023, 3:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2023, 3:43 AM
stuij accepted this revision.Jul 11 2023, 8:34 AM

very nice :) LGTM, except for inline nit.

llvm/test/CodeGen/ARM/execute-only.ll
162

just a quality of life change to help people reading the test cases, could you replace these base 10 values with their hex literal counterparts:

so:
ret i32 u0x11223344

etc.. for the ones below.

This revision is now accepted and ready to land.Jul 11 2023, 8:34 AM
This revision was landed with ongoing or failed builds.Jul 12 2023, 3:49 AM
This revision was automatically updated to reflect the committed changes.
chapuni added inline comments.
llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
1049

Lsl is used only here in -Asserts.

john.brawn added inline comments.Jul 12 2023, 8:55 AM
llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
1049
Caslyn added a subscriber: Caslyn.Jul 12 2023, 10:22 AM
Caslyn added inline comments.
llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
1172

Hello - this assert is firing on Fuchsia clang builders, filed https://github.com/llvm/llvm-project/issues/63831 with error output example and reproducer.

Does tMOVi32imm with a zero immediate work correctly?

Caslyn added inline comments.Jul 12 2023, 2:39 PM
llvm/lib/Target/ARM/ARMExpandPseudoInsts.cpp
1172

Awaiting response from the author, I've submitted a revert for this change https://reviews.llvm.org/D155122.

D155301 replaces uses of TransferImpOps with copyImplicitOps, meaning the patch here can be changed to using copyImplicitOps instead of asserting.

Re-committed now that D155301 has been committed.