Open davidbolvansky opened 5 years ago
The fold from the last comment regressed in main because it's not poison-safe.
int test(int x, int n) { if (x) return n * x;
return 0;
}
Clang: test(int, int): # @test(int, int) mov eax, esi imul eax, edi test edi, edi cmove eax, edi ret
GCC: _Z4testii: mov eax, edi imul eax, esi ret
Extended Description
Hello,
int f2(int x, int y, int z) { int tmp = y--; if (tmp x > x y) return 1; return 0; }
Current codegen: f2(int, int, int): # @f2(int, int, int) lea ecx, [rsi - 1] imul esi, edi imul ecx, edi xor eax, eax cmp esi, ecx setg al ret
GCC: f2(int, int, int): xor eax, eax test edi, edi setg al ret
///////////////////// int f2(int x, int y, int z) { if ((y-1) x > x y) return 1; return 0; }
f2(int, int, int): # @f2(int, int, int) lea ecx, [rsi - 1] imul ecx, edi imul esi, edi xor eax, eax cmp ecx, esi setg al ret
GCC: f2(int, int, int): mov eax, edi shr eax, 31 ret
For unsigned case - Clang: f2(unsigned int, unsigned int, unsigned int): # @f2(unsigned int, unsigned int, unsigned int) lea ecx, [rsi - 1] imul ecx, edi imul esi, edi xor eax, eax cmp ecx, esi seta al ret
GCC (one multiplication is eliminated): f2(unsigned int, unsigned int, unsigned int): sub esi, 1 xor eax, eax imul esi, edi add esi, edi setc al ret