The Freeze is added to Cond in fixing the miscomputation of loop unswitch(D106041).
However, more sinks are generated in Instcombine by Freeze that added in D106041.
Below is a situation where D106041 is not applied(bug exists in LU).
If D106041 is not applied, load(ptr) will not sink after InstCombine is performed.
v = load(ptr) cond = icmp eq(v, 0) br body body: br(cond, ..., ...) => v = load(ptr) br body body: cond = icmp eq(v, 0) br(cond, ..., ...)
But when we add the Freeze to Cond(to fix LU), load(ptr) is sink to body block.
And this is not the intended situation.
v = load(ptr) cond = icmp eq(v, 0) cond.fr = freeze(cond) br body body: br(cond.fr, ..., ...) => br body body: v = load(ptr) v.fr = freeze(v) cond = icmp eq(v, 0) br(cond, ..., ...)
Once this patch is applied, the load will not sink, but only Freeze and icmp will sink as below.
v = load(ptr) cond = icmp eq(v, 0) cond.fr = freeze(cond) br body body: br(cond.fr, ..., ...) => v = load(ptr) br body body: v.fr = freeze(v) cond = icmp eq(v, 0) br(cond, ..., ...)
clang-format: please reformat the code