Souper says:
; Function: fn1
%0:i32 = var
%1:i32 = var
%2:i32 = xor %0, %1
%3:i32 = xor 2147483648:i32, %0, %1
%4:i32 = and %2, %3
%5:i1 = slt %4, 0:i32
cand %5 0:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_602/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%1 = load i32* @b, align 4, !tbaa !1
%xor = xor i32 %1, %0
%neg = xor i32 %0, -2147483648
%xor1 = xor i32 %neg, %1
%and = and i32 %xor, %xor1
%cmp = icmp slt i32 %and, 0
%and.lobit = lshr i32 %and, 31
%conv. = select i1 %cmp, i32 %and.lobit, i32 0
store i32 %conv., i32* @c, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_602/foo.c -o reduce_602/foo.bc
C source code:
int a, b, c;
void fn1() { c = ((a ^ b) & (a ^ ~b)) < 0 ?: 0; }
x86-64 from LLVM:
fn1: # @fn1
movl b(%rip), %eax
xorl a(%rip), %eax
movl %eax, %ecx
notl %ecx
andl %eax, %eax
andl %ecx, %eax
shrl $31, %eax
movl %eax, c(%rip)
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_602/foo.c -S -o -
x86-64 from GCC:
fn1:
movl b(%rip), %ecx
movl a(%rip), %edx
movl %ecx, %eax
notl %eax
xorl %edx, %eax
xorl %ecx, %edx
andl %edx, %eax
shrl $31, %eax
movl %eax, c(%rip)
ret
COMMAND: gcc -w -O3 reduce_602/foo.c -S -o -