This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Fold addiw from (add X, (addiw (lui C1, C2))) into load/store address
ClosedPublic

Authored by craig.topper on Apr 29 2022, 12:42 PM.

Details

Summary

This is a followup to D124231.

We can fold the ADDIW in this pattern if we can prove that LUI+ADDI
would have produced the same result as LUI+ADDIW.

This pattern occurs because constant materialization prefers LUI+ADDIW
for all simm32 immediates. Only immediates in the range
0x7ffff800-0x7fffffff require an ADDIW. Other simm32 immediates
work with LUI+ADDI.

Diff Detail

Event Timeline

craig.topper created this revision.Apr 29 2022, 12:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2022, 12:42 PM
craig.topper requested review of this revision.Apr 29 2022, 12:42 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2022, 12:42 PM
asb accepted this revision.May 11 2022, 5:35 AM

Nice improvement - thanks. Might be worth adding an explicit test case for where an lui+addiw is generated but the addiw can't be converted to an addi.

This revision is now accepted and ready to land.May 11 2022, 5:35 AM
This revision was landed with ongoing or failed builds.May 11 2022, 12:47 PM
This revision was automatically updated to reflect the committed changes.