[InstCombine] Add optimization to prevent poison from being propagated.
authorhyeongyu kim <gusrb406@snu.ac.kr>
Sun, 11 Jul 2021 02:45:32 +0000 (11:45 +0900)
committerJuneyoung Lee <aqjune@gmail.com>
Sun, 11 Jul 2021 03:40:43 +0000 (12:40 +0900)
commit1a5f4cbe1bd62e6624cbb77dad0d363addd1b324
tree1a4059fc1c81a6194b5118ecaad1adf4fc5ca9a6
parent09cdcf09b54d328fc0a247b3a0f351d2610e928f
[InstCombine] Add optimization to prevent poison from being propagated.

In D104569, Freeze was inserted just before br to solve the `branching on undef` miscompilation problem.
But value analysis was being disturbed by added freeze.

```
v = load ptr
cond = freeze(icmp (and v, const), const')
br cond, ...
```
The case in which value analysis disturbed is as above.
By changing freeze to add immediately after load, value analysis will be successful again.

```
v = load ptr
freeze(icmp (and v, const), const')
=>
v = load ptr
v' = freeze v
icmp (and v', const), const'
```
In this patch, I propose the above optimization.
With this patch, the poison will not spread as the freeze is performed early.

Reviewed By: nikic, lebedev.ri

Differential Revision: https://reviews.llvm.org/D105392
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/freeze.ll