[PATCH] D45748: [RISCV] Separate base from offset in lowerGlobalAddress
Alex Bradbury via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 24 07:45:35 PDT 2018
asb added a comment.
What are your thoughts on handling regressions such as those demonstrated in the test case below?
@g = global [128 x i8] zeroinitializer, align 1
define i8* @test() {
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @g, i32 0, i32 125)
}
Before:
lui a0, %hi(g+125)
addi a0, a0, %lo(g+125)
After:
lui a0, %hi(g)
addi a0, a0, %lo(g)
addi a0, a0, 125
It's tempting to have a peephole that converts the final addi to `addi a0, a0, %lo(g+125)` but that's not actually correct as the %hi relocation could be affected by the top bit of the %lo due to sign extension. A peephole might still be a sensible approach, but it would need to transform the lui as well.
You can also note that in the worst case with a large offset you end up with an additional two instructions
@g = global [1048576 x i8] zeroinitializer, align 1
define i8* @test() {
ret i8* getelementptr inbounds ([1048576 x i8], [1048576 x i8]* @g, i32 0, i32 524288)
}
Before:
lui a0, %hi(g)
addi a0, a0, %lo(g)
lui a1, 128
add a0, a0, a1
After:
lui a0, %hi(g+524288)
addi a0, a0, %lo(g+524288)
https://reviews.llvm.org/D45748
More information about the llvm-commits
mailing list