Souper says:
; Function: fn1
%0:i32 = var
%1:i1 = eq 0:i32, %0
%2:i32 = addnsw 1:i32, %0
%3:i32 = select %1, %2, 0:i32
%4:i1 = slt %3, 2:i32
cand %4 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_187/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
store i32 0, i32* @a, align 4, !tbaa !1
br label %for.body
for.body: ; preds = %entry, %for.body
%storemerge1 = phi i32 [ 0, %entry ], [ %inc., %for.body ]
%tobool = icmp eq i32 %storemerge1, 0
%inc = add nsw i32 %storemerge1, 1
%inc. = select i1 %tobool, i32 %inc, i32 0
%cmp = icmp slt i32 %inc., 2
br i1 %cmp, label %for.body, label %for.end
for.end: ; preds = %for.body
%inc..lcssa = phi i32 [ %inc., %for.body ]
store i32 %inc..lcssa, i32* @a, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_187/foo.c -o reduce_187/foo.bc
C source code:
int a;
void fn1() {
lbl_2195:
for (a = 0; a <= 1; ++a)
if (a)
goto lbl_2195;
}
x86-64 from LLVM:
fn1: # @fn1
movl $0, a(%rip)
xorl %eax, %eax
xorl %ecx, %ecx
.LBB0_1: # %for.body
testl %ecx, %ecx
leal 1(%rcx), %ecx
cmovnel %eax, %ecx
cmpl $2, %ecx
jl .LBB0_1
movl %ecx, a(%rip)
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_187/foo.c -S -o -
x86-64 from GCC:
fn1:
.L2:
.L3:
jmp .L3
COMMAND: gcc -w -O3 reduce_187/foo.c -S -o -