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.
I think it would be good to have a comment explaining why we don't do this iff the OrigOpInst has other uses.
We could just change them all to use OrigFI first. Why do we want to not do this?