Souper says:
; Function: fn1
%0:i32 = var
%1:i1 = ne 0:i32, %0
%2:i32 = var
%3:i1 = slt 4294967295:i32, %2
%4:i1 = and %1, %3
pc %4 1:i1
%5:i1 = slt %2, 0:i32
cand %5 0:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_701/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @b, align 4, !tbaa !1
%tobool = icmp ne i32 %0, 0
%1 = load i32* @a, align 4
%cmp = icmp sgt i32 %1, -1
%or.cond = and i1 %tobool, %cmp
br i1 %or.cond, label %for.inc.preheader, label %if.end
for.inc.preheader: ; preds = %entry
%2 = icmp slt i32 %1, 0
%.op = add i32 %1, -1
%3 = select i1 %2, i32 %.op, i32 -1
store i32 %3, i32* @a, align 4, !tbaa !1
br label %if.end
if.end: ; preds = %for.inc.preheader, %entry
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_701/foo.c -o reduce_701/foo.bc
C source code:
int a, b;
void fn1() {
if (b)
for (; a >= 0; a = a - 1)
;
}
x86-64 from LLVM:
fn1: # @fn1
cmpl $0, b(%rip)
je .LBB0_3
movl a(%rip), %eax
testl %eax, %eax
js .LBB0_3
leal -1(%rax), %ecx
testl %eax, %eax
movl $-1, %eax
cmovsl %ecx, %eax
movl %eax, a(%rip)
.LBB0_3: # %if.end
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_701/foo.c -S -o -
x86-64 from GCC:
fn1:
movl b(%rip), %edx
testl %edx, %edx
je .L1
movl a(%rip), %eax
testl %eax, %eax
js .L1
movl $-1, a(%rip)
.L1:
rep ret
COMMAND: gcc -w -O3 reduce_701/foo.c -S -o -