[GVN] Fix use-after-free in load PRE with select available value (#69314)
authorNikita Popov <npopov@redhat.com>
Thu, 19 Oct 2023 07:08:59 +0000 (09:08 +0200)
committerTobias Hieta <tobias@hieta.se>
Tue, 31 Oct 2023 08:00:10 +0000 (09:00 +0100)
commitc2eab59e622cde6989b5ee923a1f957f3afd7ad5
tree4a92cb5582522b171672bad679be1ac5ada12384
parent586481468a073b342a1d7940cc9f65b762a9a6ce
[GVN] Fix use-after-free in load PRE with select available value (#69314)

replaceValuesPerBlockEntry() only handled simple and coerced load
values, however the load may also be referenced by a select value.

Additionally, I suspect that the previous code might have been incorrect
if a load had an offset, as it always constructed the AvailableValue
from scratch.

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

(cherry picked from commit 7f1733a252cbbad74445bd54dc95aeec52bb3199)
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/test/Transforms/GVN/pr69301.ll [new file with mode: 0644]