llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[InstCombine] missed fold x % y == x to x < y

Open Andarwinux opened this issue 4 months ago • 1 comments

found from https://github.com/gcc-mirror/gcc/commit/7ebe4eb29d8fc0167f98705b53b4fddb28f0cffb

int foo (unsigned int x, unsigned int y) { return x % y == x; }
foo:
        mov     eax, edi
        xor     edx, edx
        div     esi
        xor     eax, eax
        cmp     edx, edi
        sete    al
        ret

should be:

int bar (unsigned int x, unsigned int y) { return x < y; }
bar:
        xor     eax, eax
        cmp     edi, esi
        setb    al
        ret

https://godbolt.org/z/njWGvMvfj https://alive2.llvm.org/ce/z/3ryQaE

Andarwinux avatar Aug 06 '26 12:08 Andarwinux

Hi, I'd like to work on this issue. Could you assign it to me?

ChrisLee02 avatar Aug 06 '26 14:08 ChrisLee02