https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112985
--- Comment #1 from chenglulu <chenglulu at loongson dot cn> --- (In reply to Xi Ruoyao from comment #0) > /* { dg-do compile } */ > /* { dg-options "-O2 -ffast-math -fdump-tree-gimple" } */ > > int > short_circuit (float *a) > { > float t1x = a[0]; > float t2x = a[1]; > float t1y = a[2]; > float t2y = a[3]; > float t1z = a[4]; > float t2z = a[5]; > > if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y > < t1z) > return 0; > > return 1; > } > > on LoongArch it produces something like: > > _1 = t1x > t2y; > _2 = t2x < t1y; > _3 = _1 | _2; > if (_3 != 0) goto <D.2205>; else goto <D.2207>; > <D.2207>: > _4 = t1x > t2z; > _5 = t2x < t1z; > _6 = _4 | _5; > if (_6 != 0) goto <D.2205>; else goto <D.2208>; > <D.2208>: > _7 = t1y > t2z; > _8 = t2y < t1z; > _9 = _7 | _8; > if (_9 != 0) goto <D.2205>; else goto <D.2206>; > <D.2205>: > D.2209 = 0; > > but it's better to produce 6 if (per > https://gcc.gnu.org/pipermail/gcc-patches/2023-December/640313.html it will > produce a 1.8% improvement in SPECCPU 2017 fprate). > > One obvious issue is LoongArch cost model for FP comparison is incorrect > (PR112936) but even if I set the cost of floating-point comparison to 5000 > the gimple still produces 3 if with non-shorted comparisons. I agree that the code should generate logic similar to a fixed point: slt $r17,$r15,$r14 slt $r13,$r16,$r12 or $r13,$r13,$r17 bstrpick.w $r13,$r13,7,0 bnez $r13,.L3