Souper says:
; Function: main
%0:i32 = var
%1:i1 = eq 0:i32, %0
pc %1 0:i1
%2:i32 = var
%3:i1 = ne 0:i32, %2
%4:i32 = zext %3
%5:i32 = select %3, %4, %0
%6:i1 = eq 0:i32, %5
cand %6 0:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_500/foo.bc
LLVM says:
define i32 @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%tobool = icmp eq i32 %0, 0
br i1 %tobool, label %land.end, label %land.rhs
land.rhs: ; preds = %entry
%1 = load i32* @b, align 4, !tbaa !1
%tobool1 = icmp ne i32 %1, 0
br label %land.end
land.end: ; preds = %entry, %land.rhs
%2 = phi i1 [ false, %entry ], [ %tobool1, %land.rhs ]
%land.ext = zext i1 %2 to i32
%cond = select i1 %2, i32 %land.ext, i32 %0
ret i32 %cond
}
define i32 @main() #1 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%tobool.i.i = icmp eq i32 %0, 0
%1 = load i32* @b, align 4, !tbaa !1
%tobool1.i.i = icmp ne i32 %1, 0
br i1 %tobool.i.i, label %fn1.exit.us.i.preheader, label %fn1.exit.i.preheader
fn1.exit.us.i.preheader: ; preds = %entry
br label %fn1.exit.us.i
fn1.exit.i.preheader: ; preds = %entry
%land.ext.i.i = zext i1 %tobool1.i.i to i32
%cond.i.i = select i1 %tobool1.i.i, i32 %land.ext.i.i, i32 %0
%tobool.i = icmp eq i32 %cond.i.i, 0
br i1 %tobool.i, label %fn1.exit.i.preheader2, label %for.cond1.i.preheader
for.cond1.i.preheader: ; preds = %fn1.exit.i.preheader
br label %for.cond1.i
fn1.exit.i.preheader2: ; preds = %fn1.exit.i.preheader
br label %fn1.exit.i
fn1.exit.us.i: ; preds = %fn1.exit.us.i.preheader, %fn1.exit.us.i
br label %fn1.exit.us.i
fn1.exit.i: ; preds = %fn1.exit.i.preheader2, %fn1.exit.i
br label %fn1.exit.i
for.cond1.i: ; preds = %for.cond1.i.preheader, %for.cond1.i
br label %for.cond1.i
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_500/foo.c -o reduce_500/foo.bc
C source code:
int a, b;
int fn1() { return a && b ?: a; }
static int fn2() {
for (;;)
if (fn1())
for (;;)
;
}
int main() {
fn2();
for (;;)
;
}
x86-64 from LLVM:
fn1: # @fn1
movl a(%rip), %eax
testl %eax, %eax
je .LBB0_1
cmpl $0, b(%rip)
setne %cl
jmp .LBB0_3
.LBB0_1:
xorl %ecx, %ecx
.LBB0_3: # %land.end
movzbl %cl, %ecx
testb %cl, %cl
cmovnel %ecx, %eax
retq
main: # @main
movl a(%rip), %eax
testl %eax, %eax
je .LBB1_4
movl b(%rip), %ecx
testl %ecx, %ecx
setne %cl
movzbl %cl, %ecx
cmovnel %ecx, %eax
testl %eax, %eax
je .LBB1_2
.LBB1_3: # %for.cond1.i
jmp .LBB1_3
.LBB1_4: # %fn1.exit.us.i
jmp .LBB1_4
.LBB1_2: # %fn1.exit.i
jmp .LBB1_2
.Ltmp1:
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_500/foo.c -S -o -
x86-64 from GCC:
fn1:
movl a(%rip), %edx
xorl %eax, %eax
testl %edx, %edx
je .L2
movl b(%rip), %ecx
movb $1, %al
testl %ecx, %ecx
cmove %edx, %eax
.L2:
rep ret
main:
.LFB2:
movl a(%rip), %eax
testl %eax, %eax
jne .L8
.L9:
jmp .L9
.L8:
.L10:
jmp .L10
.LFE2:
COMMAND: gcc -w -O3 reduce_500/foo.c -S -o -