Souper says:
; Function: fn2
%0:i32 = var
%1:i32 = sdiv %0, 0:i32
%2:i1 = ne 0:i32, %1
cand %2 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_569/foo.bc
LLVM says:
define void @fn2() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%div.i = sdiv i32 %0, 0
%tobool.i = icmp ne i32 %div.i, 0
%div..i = select i1 %tobool.i, i32 %div.i, i32 1
store i32 %div..i, i32* @b, align 4, !tbaa !1
ret void
}
define void @fn1(i32 %p1) #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%div = sdiv i32 %0, %p1
%tobool = icmp ne i32 %div, 0
%div. = select i1 %tobool, i32 %div, i32 1
store i32 %div., i32* @b, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_569/foo.c -o reduce_569/foo.bc
C source code:
int a, b;
void fn1();
void fn2() { fn1(); }
void fn1(p1) { b = a / p1 ?: 1; }
x86-64 from LLVM:
fn2: # @fn2
movl a(%rip), %eax
xorl %ecx, %ecx
cltd
idivl %ecx
testl %eax, %eax
movl $1, %ecx
cmovnel %eax, %ecx
movl %ecx, b(%rip)
retq
fn1: # @fn1
movl a(%rip), %eax
cltd
idivl %edi
testl %eax, %eax
movl $1, %ecx
cmovnel %eax, %ecx
movl %ecx, b(%rip)
retq
.Ltmp1:
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_569/foo.c -S -o -
x86-64 from GCC:
fn2:
movl a(%rip), %eax
xorl %ecx, %ecx
cltd
idivl %ecx
movb $1, %cl
testl %eax, %eax
cmovne %eax, %ecx
movl %ecx, b(%rip)
ret
fn1:
.LFB1:
movl a(%rip), %eax
movl $1, %ecx
cltd
idivl %edi
testl %eax, %eax
cmovne %eax, %ecx
movl %ecx, b(%rip)
ret
.LFE1:
COMMAND: gcc -w -O3 reduce_569/foo.c -S -o -