[llvm] [PowerPC] Peephole address calculation in TOC memops (PR #76488)
Chen Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Apr 28 00:10:07 PDT 2024
chenzheng1030 wrote:
> > Something useful related to this came up in @stephenpeckham's presentation. Adding an offset to the large code model relocation expressions is not allowed, so I belive we couldn't transform something like
> > ```
> > addis r3, x[TD]@u(2)
> > addi r3, x[TD]@l(r3)
> > ld. r5, 2(r3)
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > to
> > ```
> > addis r3, x[TD]@u(2)
> > ld r5, x[TD]@l + 2)(r3)
> > ```
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > I though I'd comment here now so we won't forget to test this.
>
> ```
> int a = 100;
> int main()
> {
> return a;
> }
> ```
>
> `1.c -S -mcmodel=large -mtocdata -m64`
>
> ```
> .main:
> # %bb.0: # %entry
> li 3, 0
> stw 3, -12(1)
> addis 3, a[TD]@u(2)
> la 3, a[TD]@l(3)
> lwz 3, 0(3)
> extsw 3, 3
> blr
> ```
>
> After manually changing the assembly to:
>
> ```
> .main:
> # %bb.0: # %entry
> li 3, 0
> stw 3, -12(1)
> addis 3, a[TD]@u(2)
> lwz 3, a[TD]@l(3)
> extsw 3, 3
> blr
> ```
>
> It is still able to get good running result.
>
> Do you mean other cases @mandlebug ?
Seems related to https://github.com/llvm/llvm-project/commit/b54579fab6571501f9e82a3e413ad36fd34aaa75
```
addis r3, x[TD]@u(2)
addi r3, x[TD]@l(r3)
ld r5, offset(r3)
```
If the offset is bigger than 8, then the `x[TD]@u(2)` may resolve to different values with/without the `ld(addi)` combination. But this should already be handled with existing code?
https://github.com/llvm/llvm-project/pull/76488
More information about the llvm-commits
mailing list