[Bug middle-end/88575] gcc got confused by different comparison operators
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88575 Richard Biener changed: What|Removed |Added Keywords||missed-optimization Status|UNCONFIRMED |NEW Last reconfirmed||2019-01-02 CC||rguenth at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #4 from Richard Biener --- Confirmed. Even with -ffast-math on GIMPLE we fail to elide the MIN_EXPR in both functions (test has a_2(D) < b_3(D)). When doing integer operations VRP manages to elide those. Given we have no such thing as value-range propagation for floats the closest we have is DOM/VN registering the conditions and MIN_EXPR VN "failing" to lookup whether a<=b is known. [local count: 1073741825]: if (a_2(D) <= b_3(D)) goto ; [34.00%] else goto ; [66.00%] [local count: 365072220]: _4 = MIN_EXPR ; [local count: 1073741825]: # _1 = PHI <_4(3), 0.0(2)> return _1;
[Bug middle-end/88575] gcc got confused by different comparison operators
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88575 --- Comment #3 from Daniel Fruzynski --- I have tried to compile with -O3 -march=skylake -ffast-math and got this: [asm] test(double, double): vminsd xmm2, xmm0, xmm1 vcmplesdxmm0, xmm0, xmm1 vxorpd xmm1, xmm1, xmm1 vblendvpd xmm0, xmm1, xmm2, xmm0 ret test2(double, double): vminsd xmm2, xmm0, xmm1 vcmpltsdxmm0, xmm0, xmm1 vxorpd xmm1, xmm1, xmm1 vblendvpd xmm0, xmm1, xmm2, xmm0 ret [/asm] And this is for -O3 -march=skylake -funsafe-math-optimizations. As you can see, one instruction was eliminated from test2(). For some reason it was not eliminated from test() function. I checked that -ffinite-math-only present in -ffast-math prevented elimination of this extra instruction. [asm] test(double, double): vminsd xmm2, xmm0, xmm1 vcmplesdxmm0, xmm0, xmm1 vxorpd xmm1, xmm1, xmm1 vblendvpd xmm0, xmm1, xmm2, xmm0 ret test2(double, double): vcmpnltsd xmm1, xmm0, xmm1 vxorpd xmm2, xmm2, xmm2 vblendvpd xmm0, xmm0, xmm2, xmm1 ret [/asm]
[Bug middle-end/88575] gcc got confused by different comparison operators
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88575 --- Comment #2 from Daniel Fruzynski --- Code was compiled with -O3 -march=skylake. I have tried to add -fno-signed-zeros and -fsigned-zeros, and got the same output for both cases.
[Bug middle-end/88575] gcc got confused by different comparison operators
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88575 --- Comment #1 from joseph at codesourcery dot com --- On Sat, 22 Dec 2018, bugzi...@poradnik-webmastera.com wrote: > In test() gcc is not able to determine that for a==b it does not have to > evaluate 2nd comparison and can use value of a if 1st comparison is true. When > operators are swapped like in test2() or are the same, code is optimized. > > [code] > double test(double a, double b) > { > if (a <= b) > return a < b ? a : b; > return 0.0; > } You didn't give compilation options, but if a and b are +0 and -0 in some order, the first comparison is true but b must be returned instead of a (in the absence of -fno-signed-zeros or an option implying it).