[llvm] [RISCV] Add a pass to remove ADDI by reassociating to fold into load/store address. (PR #127151)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 18 11:37:22 PST 2025
================
@@ -1167,8 +1167,10 @@ declare void @f(ptr)
define i32 @crash() {
; RV32I-LABEL: crash:
; RV32I: # %bb.0: # %entry
-; RV32I-NEXT: lui a0, %hi(g+401)
-; RV32I-NEXT: lbu a0, %lo(g+401)(a0)
+; RV32I-NEXT: lui a0, %hi(g)
+; RV32I-NEXT: addi a0, a0, %lo(g)
+; RV32I-NEXT: add a0, a0, zero
+; RV32I-NEXT: lbu a0, 401(a0)
----------------
preames wrote:
I just want to note that these legitimately are regressions. We're folding the constant offset into the using load, but before we'd folded it with the lo part of the symbol, and then that into the load. After your change, we still end up needing the add for that (at least, before linker relaxation). It seems like we should be able to undo this, are we missing a generalization somewhere else?
Also, separate issue, but why the heck do we still have the ADD a0, a0, zero here?
https://github.com/llvm/llvm-project/pull/127151
More information about the llvm-commits
mailing list