[GVN] Patch for invalid GVN replacement
authorAlex Gatea <alexgatea@gmail.com>
Fri, 4 Nov 2022 13:28:17 +0000 (14:28 +0100)
committerNikita Popov <npopov@redhat.com>
Fri, 4 Nov 2022 13:28:17 +0000 (14:28 +0100)
commit7d0648cb6c5f3c7377662a1211846f9fe03c474f
tree8aab3d63c167aca8bbdd35df1d723d9951d8030a
parent1fb186198af5f183dde053c1396f899567755d64
[GVN] Patch for invalid GVN replacement

If PRE is performed as part of the main GVN pass (to PRE GEP
operands before processing loads), and it is performed across a
backedge, we will end up adding the new instruction to the leader
table of a block that has not yet been processed. When it will be
processed, GVN will incorrectly assume that the value is already
available, even though it is only available at the end of the
block.

Avoid this by not performing PRE across backedges.

Fixes https://github.com/llvm/llvm-project/issues/58418.

Differential Revision: https://reviews.llvm.org/D136095
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/test/Transforms/GVN/PRE/load-pre-across-backedge.ll [new file with mode: 0644]
llvm/test/Transforms/GVN/PRE/pre-gep-load.ll