[PATCH] D131776: [GVN] Fix miscompile shown in github issue #57025

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 12 07:22:51 PDT 2022


bjope added inline comments.


================
Comment at: llvm/test/Transforms/GVN/memdep-unknown-deadblocks.ll:49
 ; CHECK-GVN:       store.done:
-; CHECK-GVN-NEXT:    [[VALUE:%.*]] = phi i16 [ 42, [[STORE_IDX_I]] ], [ [[VALUE2]], [[STORE_IDX_0]] ]
 ; CHECK-GVN-NEXT:    br label [[WHILE_BODY:%.*]]
----------------
This was almost correct.
It would have been correct if this phi looked like this instead:
```
[[VALUE:%.*]] = phi i16 [ 42, [[STORE_IDX_I]] ], [ [[7]], [[STORE_IDX_0]] ]
```
and then the load in `while.end` can be eliminated. And then we also would get rid of `VALUE2` and `DEAD`.

But my fix here is not aiming at optimizing this kind of scenario, just to avoid the miscompile we see today.
Current fix makes the result look just like if we would have had

```
%j = phi i16 [ %i, %store.done ], [ poison, %while.body ]
```
instead of
```
%j = phi i16 [ %i, %store.done ], [ 0, %while.body ]
```
already in the input. Which would have triggered an early remove of that phi in GVN iteration 0. So it does not seem like GVN would eliminate the load by adding a phi in `store.done` even if cleaning up some of the "stupid" things in the IR such as the dead load and the phi related to the unconditional cond branch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131776/new/

https://reviews.llvm.org/D131776



More information about the llvm-commits mailing list