Reapply "[GVN] Prevent LoadPRE from hoisting across instructions that don't pass...
authorMax Kazantsev <max.kazantsev@azul.com>
Tue, 31 Oct 2017 05:07:56 +0000 (05:07 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Tue, 31 Oct 2017 05:07:56 +0000 (05:07 +0000)
commit488ec975bb418cc3fd230a9acdfdb1effc61670e
tree19232c65efdc198fc14d64e2f2728f5826a2bf10
parent39a8dbff8760adfa55942c61d6e75dd432d30875
Reapply "[GVN] Prevent LoadPRE from hoisting across instructions that don't pass control flow to successors"

This patch fixes the miscompile that happens when PRE hoists loads across guards and
other instructions that don't always pass control flow to their successors. PRE is now prohibited
to hoist across such instructions because there is no guarantee that the load standing after such
instruction is still valid before such instruction. For example, a load from under a guard may be
invalid before the guard in the following case:
  int array[LEN];
  ...
  guard(0 <= index && index < LEN);
  use(array[index]);

Differential Revision: https://reviews.llvm.org/D37460

llvm-svn: 316975
llvm/include/llvm/Transforms/Scalar/GVN.h
llvm/lib/Transforms/Scalar/GVN.cpp
llvm/test/Transforms/GVN/PRE/2017-10-16-LoadPRECrash.ll
llvm/test/Transforms/GVN/PRE/pre-load-guards.ll [new file with mode: 0644]
llvm/test/Transforms/GVN/PRE/pre-load-implicit-cf-updates.ll [new file with mode: 0644]
llvm/test/Transforms/GVN/PRE/pre-load.ll