Skip to content

a ne/eq (a ne/eq 0) pattern is not simplified #65073

Closed
@k-arrows

Description

@k-arrows

Such a simple pattern may already be mentioned in some existing issues, but I couldn't find a duplicate. (If there is, please feel free to close this issue as duplicate.)

https://godbolt.org/z/rvEaKjE4E

bool f1(int a)
{
    return a != (a == 0);
}

bool f2(int a)
{
    return a != (a != 0);
}

bool f3(int a)
{
    return a == (a == 0);
}

bool f4(int a)
{
    return a == (a != 0);
}

GCC

f1(int):
        mov     eax, 1
        ret
f2(int):
        cmp     edi, 1
        seta    al
        ret
f3(int):
        xor     eax, eax
        ret
f4(int):
        cmp     edi, 1
        setbe   al
        ret

Clang

f1(int):                                 # @f1(int)
        xor     eax, eax
        test    edi, edi
        sete    al
        cmp     eax, edi
        setne   al
        ret
f2(int):                                 # @f2(int)
        xor     eax, eax
        test    edi, edi
        setne   al
        cmp     eax, edi
        setne   al
        ret
f3(int):                                 # @f3(int)
        xor     eax, eax
        test    edi, edi
        sete    al
        cmp     eax, edi
        sete    al
        ret
f4(int):                                 # @f4(int)
        xor     eax, eax
        test    edi, edi
        setne   al
        cmp     eax, edi
        sete    al
        ret

FYI
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110293

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions