https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129188
Bug ID: 129188
Summary: [15/16/17 Regression] wrong code for long double ==/!=
with NaN under -mavx10.2 -mapxf
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: lin1.hu at intel dot com
Target Milestone: ---
PR126676 (r17-3196, r16-9523) fixed the ICE for XFmode EQ/NE in APX ccmp
chains, but they still test only ZF and treat NaNs as equal.
$ cat t.c
__attribute__ ((noipa)) int
f1 (long double a, long double b, int x)
{
return x > 0 && a == b;
}
__attribute__ ((noipa)) int
f2 (long double a, long double b, int x)
{
return x > 0 && a != b;
}
int
main (void)
{
volatile long double n = __builtin_nanl ("");
if (f1 (n, 1.0L, 1) != 0)
__builtin_abort ();
if (f2 (n, 1.0L, 1) != 1)
__builtin_abort ();
return 0;
}
$ gcc -O2 -mavx10.2 -mapxf t.c && sde -dmr -- ./a.out # aborts
$ gcc -O2 -mavx10.2 t.c && sde -dmr -- ./a.out # ok
$ gcc -O2 -mapxf t.c && sde -dmr -- ./a.out # ok
f1 at -O2 -mavx10.2 -mapxf:
fldt 8(%rsp)
fldt 24(%rsp)
fucomip %st(1), %st
fstp %st(0)
ctestel {dfv=sf, of, zf} %edi, %edi
setzug %al
ret
Under TARGET_AVX10_2, ix86_fp_compare_code_to_integer maps CCFP EQ/NE to
CC EQ/NE (ZF only) without a mode check, so ix86_gen_ccmp_first accepts
XFmode EQ/NE and ix86_gen_ccmp_next uses "e" for CCFP EQ. That mapping is
correct for VCOMX/VUCOMX, but since PR126676 XFmode no longer uses
UNSPEC_OPTCOMX and the first compare is fucomip, which sets ZF=PF=CF=1 for
unordered operands.Without ccmp, ix86_fp_comparison_operator_xf rejects XFmode
EQ/NE, so emit_store_flag splits a == b into ORDERED && UNEQ (setnp + cmovne),
and NaN is handled correctly.