Souper says:
; Function: fn2
%0:i32 = var
%1:i1 = eq 0:i32, %0
%2:i32 = zext %1
%3:i32 = udiv 1:i32, %2
%4:i1 = eq 0:i32, %3
cand %4 0:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_380/foo.bc
LLVM says:
define void @fn2() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%cmp = icmp eq i32 %0, 0
%conv = zext i1 %cmp to i32
%div.i = udiv i32 1, %conv
store i32 %div.i, i32* @c, align 4, !tbaa !1
%tobool.i = icmp eq i32 %div.i, 0
br i1 %tobool.i, label %fn1.exit, label %if.then.i
if.then.i: ; preds = %entry
store i32 0, i32* @b, align 4, !tbaa !1
br label %fn1.exit
fn1.exit: ; preds = %entry, %if.then.i
ret void
}
define void @fn1(i32 %p1) #0 {
entry:
%div = sdiv i32 1, %p1
store i32 %div, i32* @c, align 4, !tbaa !1
%tobool = icmp eq i32 %div, 0
br i1 %tobool, label %if.end, label %if.then
if.then: ; preds = %entry
store i32 0, i32* @b, align 4, !tbaa !1
br label %if.end
if.end: ; preds = %entry, %if.then
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_380/foo.c -o reduce_380/foo.bc
C source code:
int a, b, c;
void fn1();
void fn2() { fn1(0 == a); }
void fn1(p1) {
c = 1 / p1;
if (c)
b = 0;
}
x86-64 from LLVM:
fn2: # @fn2
cmpl $0, a(%rip)
sete %al
movzbl %al, %ecx
movl $1, %eax
xorl %edx, %edx
divl %ecx
testl %eax, %eax
movl %eax, c(%rip)
je .LBB0_2
movl $0, b(%rip)
.LBB0_2: # %fn1.exit
retq
fn1: # @fn1
movl $1, %eax
xorl %edx, %edx
idivl %edi
testl %eax, %eax
movl %eax, c(%rip)
je .LBB1_2
movl $0, b(%rip)
.LBB1_2: # %if.end
retq
.Ltmp1:
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_380/foo.c -S -o -
x86-64 from GCC:
fn2:
movl a(%rip), %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $1, %eax
sete %cl
cltd
idivl %ecx
testl %eax, %eax
movl %eax, c(%rip)
je .L1
movl $0, b(%rip)
.L1:
rep ret
fn1:
.LFB1:
movl $1, %eax
cltd
idivl %edi
testl %eax, %eax
movl %eax, c(%rip)
je .L7
movl $0, b(%rip)
.L7:
rep ret
.LFE1:
COMMAND: gcc -w -O3 reduce_380/foo.c -S -o -