https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112985
Bug ID: 112985
Summary: LOGICAL_OP_NON_SHORT_CIRCUIT unconditionally execute
comparison even if it's very expensive
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: xry111 at gcc dot gnu.org
Target Milestone: ---
/* { 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.