Here is an attempt to resolve a P1 regression, where due to threading
changes we no longer optimize
bool foo(int i) {
while (i == 4)
i += 2;
return i;
}
to just return i != 0; by enhancing the phiopt value_replacement
optimization. Normally it will optimize x != cst1 ? x : cst1 to x.
Here we extend it to also optimize x != cst1 ? x : cst2 to x if
it (phi result) has a single immediate use which is a comparison
with some INTEGER_CST cst3 and we can prove that we don't care
whether x is cst1 or cst2 because both compare the same against cst3.
2022-04-11 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/104639
* tree-ssa-phiopt.cc: Include tree-ssa-propagate.h.
(value_replacement): Optimize (x != cst1 ? x : cst2) != cst3
into x != cst3.
* gcc.dg/tree-ssa/pr104639-1.c: New test.
* gcc.dg/tree-ssa/pr104639-2.c: New test.