Souper says:
; Function: main
%0:i32 = var
%1:i1 = eq 0:i32, %0
pc %1 1:i1
%2:i32 = addnsw 1:i32, %0
%3:i1 = slt %2, 2:i32
cand %3 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_763/foo.bc
LLVM says:
define i32 @main() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%dec4 = add nsw i32 %0, -1
store i32 %dec4, i32* @a, align 4, !tbaa !1
%cmp25 = icmp slt i32 %0, 3
br i1 %cmp25, label %for.body.preheader, label %for.cond1.preheader
for.body.preheader: ; preds = %entry
br label %for.body
for.cond1.preheader.loopexit: ; preds = %lbl_8.loopexit, %for.cond
br label %for.cond1.preheader
for.cond1.preheader: ; preds = %for.cond1.preheader.loopexit, %entry
br label %for.cond1
lbl_8.loopexit: ; preds = %for.body
%dec = add nsw i32 %1, -1
store i32 %dec, i32* @a, align 4, !tbaa !1
%cmp2 = icmp slt i32 %1, 3
br i1 %cmp2, label %for.body.backedge, label %for.cond1.preheader.loopexit
for.cond: ; preds = %for.body
store i32 %inc, i32* @a, align 4, !tbaa !1
%cmp = icmp slt i32 %inc, 2
br i1 %cmp, label %for.body.backedge, label %for.cond1.preheader.loopexit
for.body.backedge: ; preds = %for.cond, %lbl_8.loopexit
%.be = phi i32 [ %inc, %for.cond ], [ %dec, %lbl_8.loopexit ]
br label %for.body
for.body: ; preds = %for.body.backedge, %for.body.preheader
%1 = phi i32 [ %dec4, %for.body.preheader ], [ %.be, %for.body.backedge ]
%tobool = icmp eq i32 %1, 0
%inc = add nsw i32 %1, 1
br i1 %tobool, label %for.cond, label %lbl_8.loopexit
for.cond1: ; preds = %for.cond1.preheader, %for.cond1
br label %for.cond1
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_763/foo.c -o reduce_763/foo.bc
C source code:
int a;
int main() {
lbl_8:
--a;
for (; a <= 1; a++)
if (a)
goto lbl_8;
for (;;)
;
}
x86-64 from LLVM:
main: # @main
movl a(%rip), %ecx
leal -1(%rcx), %eax
cmpl $3, %ecx
movl %eax, a(%rip)
jge .LBB0_4
.LBB0_2: # %for.body
testl %eax, %eax
jne .LBB0_3
incl %eax
movl %eax, a(%rip)
cmpl $1, %eax
jle .LBB0_2
jmp .LBB0_4
.LBB0_3: # %lbl_8.loopexit
cmpl $3, %eax
leal -1(%rax), %eax
movl %eax, a(%rip)
jl .LBB0_2
.LBB0_4: # %for.cond1
jmp .LBB0_4
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_763/foo.c -S -o -
x86-64 from GCC:
main:
.L2:
movl a(%rip), %edx
movl $1, %ecx
jmp .L3
.L9:
testl %eax, %eax
cmove %ecx, %eax
movl %eax, %edx
.L3:
leal -1(%rdx), %eax
cmpl $1, %eax
jle .L9
movl %edx, a(%rip)
.L7:
jmp .L7
COMMAND: gcc -w -O3 reduce_763/foo.c -S -o -