Currently, when we input !__builtin_isunordered (a, b) && (a != b), gcc
will emit
ucomiss %xmm1, %xmm0
movl $1, %ecx
setp %dl
setnp %al
cmovne %ecx, %edx
andl %edx, %eax
movzbl %al, %eax
In fact,
xorl %eax, %eax
ucomiss %xmm1, %xmm0
setne %al
is better.
gcc/ChangeLog:
* match.pd: Optimize (and ordered non-equal) to
(not (or unordered equal))
gcc/testsuite/ChangeLog:
* gcc.target/i386/optimize_one.c: New test.
(ltgt @0 @0)
(if (!flag_trapping_math || !tree_expr_maybe_nan_p (@0))
{ constant_boolean_node (false, type); }))
+(simplify
+ (bit_and (ordered @0 @1) (ne @0 @1))
+ (bit_not (uneq @0 @1)))
/* x == ~x -> false */
/* x != ~x -> true */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -mfpmath=sse" } */
+/* { dg-final { scan-assembler-times "comi" 1 } } */
+/* { dg-final { scan-assembler-times "set" 1 } } */
+
+int is_ordered_or_nonequal_sh (float a, float b)
+{
+ return !__builtin_isunordered (a, b) && (a != b);
+}