This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Support LUI+ADDIW in RISCVMergeBaseOffsetOpt::matchLargeOffset.
ClosedPublic

Authored by craig.topper on May 31 2022, 3:51 PM.

Details

Summary

LUI+ADDIW always produces a simm32. This allows us to always
fold it into a global offset.

Diff Detail

Event Timeline

craig.topper created this revision.May 31 2022, 3:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2022, 3:51 PM
craig.topper requested review of this revision.May 31 2022, 3:51 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2022, 3:51 PM

Could this interact badly with the medlow upper address space bound of 0x000000007FFFF7FF?

llvm/test/CodeGen/RISCV/hoist-global-addr-base.ll
53–55

Minor update here?

luismarques accepted this revision.Jun 8 2022, 6:59 AM

Could this interact badly with the medlow upper address space bound of 0x000000007FFFF7FF?

I guess not, while the addiw -> addi change isn't safe to represent any simm32 on RV64, it's going to error out in the linker with out-of-bounds %hi and %lo.

To clarify, I was thinking about whether something like this could happen:

Before (non-folded offset computed with addiw):

lui     a0, 0x80000
addiw   a0, a0, -2047
a0 == 0x000000007ffff801

After (folded, using addi):

lui     a0, 0x80000
addi    a0, a0, -2047
a0 == 0xffffffff7ffff801

LGTM.

This revision is now accepted and ready to land.Jun 8 2022, 6:59 AM
This revision was landed with ongoing or failed builds.Jun 8 2022, 8:20 AM
This revision was automatically updated to reflect the committed changes.