Souper says:
; Function: main
%0:i32 = var
%1:i1 = ne 0:i32, %0
%2:i32 = select %1, %0, 1:i32
%3:i1 = eq 0:i32, %2
cand %3 0:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_97/foo.bc
LLVM says:
define i32 @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%tobool = icmp ne i32 %0, 0
%. = select i1 %tobool, i32 %0, i32 1
ret i32 %.
}
define i32 @main() #1 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%tobool.i = icmp ne i32 %0, 0
%..i = select i1 %tobool.i, i32 %0, i32 1
%tobool = icmp eq i32 %..i, 0
br i1 %tobool, label %for.cond.preheader, label %for.cond1.preheader.split
for.cond.preheader: ; preds = %entry
br label %for.cond
for.cond: ; preds = %for.cond.preheader, %for.cond
br label %for.cond
for.cond1.preheader.split: ; preds = %entry
store i32 %..i, i32* @b, align 4, !tbaa !1
br label %for.cond1
for.cond1: ; preds = %for.cond1.preheader.split, %for.cond1
br label %for.cond1
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_97/foo.c -o reduce_97/foo.bc
C source code:
int a, b;
int fn1() { return a ?: 1; }
int main() {
for (;;) {
b = fn1();
if (b)
for (;;)
;
}
}
x86-64 from LLVM:
fn1: # @fn1
movl a(%rip), %ecx
testl %ecx, %ecx
movl $1, %eax
cmovnel %ecx, %eax
retq
main: # @main
movl a(%rip), %ecx
testl %ecx, %ecx
movl $1, %eax
cmovnel %ecx, %eax
testl %eax, %eax
je .LBB1_1
movl %eax, b(%rip)
.LBB1_3: # %for.cond1
jmp .LBB1_3
.LBB1_1: # %for.cond
jmp .LBB1_1
.Ltmp1:
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_97/foo.c -S -o -
x86-64 from GCC:
fn1:
movl a(%rip), %edx
movl $1, %eax
testl %edx, %edx
cmovne %edx, %eax
ret
main:
.LFB1:
movl a(%rip), %edx
movl $1, %eax
testl %edx, %edx
cmovne %edx, %eax
movl %eax, b(%rip)
.L6:
jmp .L6
.LFE1:
COMMAND: gcc -w -O3 reduce_97/foo.c -S -o -