Souper says:
; Function: fn1
%0:i32 = var
%1:i32 = var
%2:i32 = and %0, %1
%3:i1 = slt %2, 0:i32
pc %3 1:i1
%4:i32 = subnsw 0:i32, %0
%5:i1 = slt %1, %4
cand %5 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_228/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%1 = load i32* @b, align 4
%2 = and i32 %1, %0
%3 = icmp slt i32 %2, 0
br i1 %3, label %land.rhs, label %land.end
land.rhs: ; preds = %entry
%sub = sub nsw i32 0, %1
%cmp2 = icmp slt i32 %0, %sub
br label %land.end
land.end: ; preds = %land.rhs, %entry
%4 = phi i1 [ false, %entry ], [ %cmp2, %land.rhs ]
%land.ext = zext i1 %4 to i32
store i32 %land.ext, i32* @c, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_228/foo.c -o reduce_228/foo.bc
C source code:
int a, b, c;
void fn1() { c = a < 0 && b < 0 && a < -b; }
x86-64 from LLVM:
fn1: # @fn1
movl a(%rip), %eax
movl b(%rip), %ecx
testl %eax, %ecx
js .LBB0_2
xorl %eax, %eax
jmp .LBB0_3
.LBB0_2: # %land.rhs
negl %ecx
cmpl %ecx, %eax
setl %al
.LBB0_3: # %land.end
movzbl %al, %eax
movl %eax, c(%rip)
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_228/foo.c -S -o -
x86-64 from GCC:
fn1:
movl a(%rip), %edx
xorl %eax, %eax
testl %edx, %edx
js .L5
movl %eax, c(%rip)
ret
.L5:
movl b(%rip), %eax
shrl $31, %eax
movl %eax, c(%rip)
ret
COMMAND: gcc -w -O3 reduce_228/foo.c -S -o -