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'd move the assert next to the insertBefore call, as that's the only place where this matters.