Souper says:
; Function: fn1
%0:i32 = var
%1:i32 = lshr %0, 31:i32
%2:i32 = xor 1:i32, %1
%3:i32 = udiv 2:i32, %2
%4:i1 = ne 0:i32, %3
cand %4 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_540/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%.lobit = lshr i32 %0, 31
%.lobit.not = xor i32 %.lobit, 1
%div = udiv i32 2, %.lobit.not
%cmp1 = icmp ne i32 %div, 0
%conv2 = zext i1 %cmp1 to i32
store i32 %conv2, i32* @b, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_540/foo.c -o reduce_540/foo.bc
C source code:
int a, b;
void fn1() { b = 2 / (a >= 0) >= 1; }
x86-64 from LLVM:
fn1: # @fn1
movl a(%rip), %ecx
shrl $31, %ecx
xorl $1, %ecx
movl $2, %eax
xorl %edx, %edx
divl %ecx
testl %eax, %eax
setne %al
movzbl %al, %eax
movl %eax, b(%rip)
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_540/foo.c -S -o -
x86-64 from GCC:
fn1:
movl a(%rip), %edx
movl $1, %eax
testl %edx, %edx
jns .L2
movb $2, %al
xorl %ecx, %ecx
cltd
idivl %ecx
testl %eax, %eax
setne %al
movzbl %al, %eax
.L2:
movl %eax, b(%rip)
ret
COMMAND: gcc -w -O3 reduce_540/foo.c -S -o -