Souper says:
; Function: fn1
%0:i32 = var
%1:i32 = subnsw 2147483647:i32, %0
%2:i1 = slt %1, 0:i32
cand %2 0:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_146/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%sub = sub nsw i32 2147483647, %0
%cmp = icmp slt i32 %sub, 0
%sub.lobit = lshr i32 %sub, 31
store i32 %sub.lobit, i32* @c, align 4, !tbaa !1
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
%1 = load i32* @b, align 4, !tbaa !1
%dec = add nsw i32 %1, -1
store i32 %dec, i32* @b, align 4, !tbaa !1
br label %if.end
if.end: ; preds = %if.then, %entry
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_146/foo.c -o reduce_146/foo.bc
C source code:
int a, b, c;
void fn1() {
c = 0 > 2147483647 - a;
if (c)
b--;
}
x86-64 from LLVM:
fn1: # @fn1
movl a(%rip), %eax
movl $2147483647, %ecx # imm = 0x7FFFFFFF
movl $2147483647, %edx # imm = 0x7FFFFFFF
subl %eax, %edx
shrl $31, %edx
cmpl %eax, %ecx
movl %edx, c(%rip)
jns .LBB0_2
decl b(%rip)
.LBB0_2: # %if.end
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_146/foo.c -S -o -
x86-64 from GCC:
fn1:
movl $2147483647, %eax
subl a(%rip), %eax
shrl $31, %eax
testl %eax, %eax
movl %eax, c(%rip)
je .L1
subl $1, b(%rip)
.L1:
rep ret
COMMAND: gcc -w -O3 reduce_146/foo.c -S -o -