[PATCH] D49007: [PowerPC] Add a peephole post RA to transform the inst that fed by add

Nemanja Ivanovic via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 11 11:54:34 PDT 2018


nemanjai requested changes to this revision.
nemanjai added a comment.
This revision now requires changes to proceed.

This needs to be beefed up to account for the two unsafe situations I outlined in the comment.



================
Comment at: llvm/lib/Target/PowerPC/PPCInstrInfo.cpp:2383
+  // try to convert it.
+  if (HasImmForm && transformToImmFormFedByAdd(MI, III, ForwardingOperand, *DefMI))
+    return true;
----------------
I just realized that this is not safe. There needs to be a check that the register being forwarded to the user isn't clobbered between `DefMI` and `MI`.

Example:

```
addis r5, r2, .LCPI0_0 at toc@ha
addi r4, r5, .LCPI0_0 at toc@l
lfdx f3, 0, r4
```
is safe to transform to
```
addis r5, r2, .LCPI0_0 at toc@ha
lfd f3, .LCPI0_0 at toc@l(r5)
```

However,
```
addis r6, r2, .LCPI0_1 at toc@ha
addis r5, r2, .LCPI0_0 at toc@ha
addi r4, r5, .LCPI0_0 at toc@l
addi r5, r6, .LCPI0_1 at toc@l
lfdx f3, 0, r4
```
is not safe to transform to
```
addis r6, r2, .LCPI0_1 at toc@ha
addis r5, r2, .LCPI0_0 at toc@ha
addi r5, r6, .LCPI0_1 at toc@l
lfd f3, .LCPI0_0 at toc@l(r5)
```
because `r5` that's being forwarded is already clobbered.
Furthermore, we can't even transform
```
addis r4, r2, .LCPI0_0 at toc@ha
addi r4, r4, .LCPI0_0 at toc@l
lfdx f3, 0, r4
```
into
```
addis r4, r2, .LCPI0_0 at toc@ha
addi r4, r4, .LCPI0_0 at toc@l
lfd f3, .LCPI0_0 at toc@l(r4)
```
(i.e. we can only transform this case if we're sure that `addi r4, r4, .LCPI0_0 at toc@l` will be deleted).


https://reviews.llvm.org/D49007





More information about the llvm-commits mailing list