Skip to content

x86 optimization: Missed merging comparison of isunordered() and islessgreater() #157874

@Explorer09

Description

@Explorer09
#include <limits.h> #include <math.h> #include <stdlib.h> int func(double x, double y) { if (isunordered(x, y)) return INT_MIN; if (islessgreater(x, y)) return x > y ? 1 : -1; return 0; }

https://godbolt.org/z/fPxT3qfPG

x86-64 clang 21.1.0 with -Os option produces:

func:  ucomisd xmm0, xmm1  jp .LBB0_1  ucomisd xmm0, xmm1  je .LBB0_3  seta al  movzx eax, al  lea eax, [2*rax - 1]  ret .LBB0_3:  xor eax, eax  ret .LBB0_1:  mov eax, -2147483648  ret

Note the duplicate UCOMISD instructions.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions