[RISCV] Teach RISCVMergeBaseOffset to merge %lo/%pcrel_lo into load/store after foldi...
authorCraig Topper <craig.topper@sifive.com>
Mon, 1 Aug 2022 22:26:20 +0000 (15:26 -0700)
committerCraig Topper <craig.topper@sifive.com>
Mon, 1 Aug 2022 22:33:21 +0000 (15:33 -0700)
commitda5b1bf5bb0f1c3d7553a286ad50245bb11694b9
tree870e584f2fd8e5240f3d405158d7730dbf68dd27
parentb25b507c779747697eb8ca35509b84451226e27b
[RISCV] Teach RISCVMergeBaseOffset to merge %lo/%pcrel_lo into load/store after folding arithmetic.

It's possible we have:
lui  a0, %hi(sym)
addi a0, %lo(sym)
addi a0, <offset1>
lw a0, <offset2>(a0)

We want to arrive at
lui a0, %hi(sym+offset1+offset2)
lw a0, %lo(sym+offset1+offset2)

We currently fail to do this because we only consider loads/stores
if we didn't find any arithmetic.

This patch splits arithmetic folding and load/store folding into
two separate phases. The load/store folding can no longer assume
the offset in hi/lo is 0 so we must combine the offsets. I've applied
the same simm32 limit that we applied in the arithmetic folding.

Reviewed By: luismarques

Differential Revision: https://reviews.llvm.org/D130931
llvm/lib/Target/RISCV/RISCVMergeBaseOffset.cpp
llvm/test/CodeGen/RISCV/hoist-global-addr-base.ll