https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113265
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu.org
Status|UNCONFIRMED |NEW
Ever confirmed|0 |1
Keywords| |missed-optimization
Last reconfirmed| |2024-01-09
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
We're somehow expanding -b as x - b. That's done by forwprop seeing
<bb 2> :
x.0_1 = x;
a_8 = b_7(D) - x.0_1;
y = 0;
y.1_2 = y;
_3 = a_8 + y.1_2;
_4 = -a_8;
_5 = _3 / _4;
z = _5;
this transform is done irrespectively of whether the non-negated expression
is still used (its a 1:1 replacement, though unary to binary). We're
thn missing folding of
a_8 = b_7(D) - x.0_1;
_4 = x.0_1 - b_7(D);
_5 = a_8 / _4;
failing to realize this is a_8 / -a_8.
Reduced testcase which isn't optimized by GCC 7 either:
int z;
void func(int a, int b){
z=(a-b)/-(a-b);
}
void func1(int a, int b){
z=(a-b)/(b-a);
}