[llvm] [PowerPC] Peephole address calculation in TOC memops (PR #76488)

Chen Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 27 23:25:21 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?


https://github.com/llvm/llvm-project/pull/76488


More information about the llvm-commits mailing list