https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88575
Bug ID: 88575 Summary: gcc got confused by different comparison operators Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: bugzi...@poradnik-webmastera.com Target Milestone: --- 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; } double test2(double a, double b) { if (a < b) return a <= b ? a : b; return 0.0; } [/code] [asm] test(double, double): vcomisd xmm1, xmm0 jnb .L10 vxorpd xmm0, xmm0, xmm0 ret .L10: vminsd xmm0, xmm0, xmm1 ret test2(double, double): vcmpnltsd xmm1, xmm0, xmm1 vxorpd xmm2, xmm2, xmm2 vblendvpd xmm0, xmm0, xmm2, xmm1 ret [/asm]