https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102540
--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think the GCC 12 IL would require tracking equivalences on parts of
registers,
in this case that _2 is equal to the low part of a.0_1. That is, one would
need to extend what CCP does with bit propagation to include equivalences.
There's also the if ((long)unsigned-var != 0) -> if (unsigned-var != 0)
transform that could save us here but we have that guarded with
single_use () and the converted value is used after the branching
but not the source so we'd have increased register pressure.
I do not see a good way to fix this issue, slightly altering the testcase to
do the undesired transform on the source level
static long a;
static unsigned b;
void foo(void);
int main() {
long c, e;
b = a;
c = (unsigned)a;
e = c ? 2 / (c + 1) : 0;
if (e && !b)
foo();
a = 0;
}
causes the issue to appear also with GCC 11.