Souper says:
; Function: fn1
%0:i32 = var
%1:i64 = sext %0
%2:i64 = and 9223372036854775808:i64, %1
%3:i64 = addnsw 18446744073709551611:i64, %2
%4:i1 = slt %3, 0:i64
cand %4 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_165/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%conv = sext i32 %0 to i64
%and = and i64 %conv, -9223372036854775808
%sub = add nsw i64 %and, -5
%cmp = icmp slt i64 %sub, 0
%sub.lobit = lshr i64 %sub, 63
%1 = trunc i64 %sub.lobit to i32
%conv1. = select i1 %cmp, i32 %1, i32 0
store i32 %conv1., i32* @b, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_165/foo.c -o reduce_165/foo.bc
C source code:
int a, b;
void fn1() { b = (a & ~9223372036854775807LL) - 5 < 0 ?: 0; }
x86-64 from LLVM:
fn1: # @fn1
movslq a(%rip), %rax
movabsq $-9223372036854775808, %rcx # imm = 0x8000000000000000
andq %rax, %rcx
addq $-5, %rcx
shrq $63, %rcx
andl %ecx, %ecx
movl %ecx, b(%rip)
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_165/foo.c -S -o -
x86-64 from GCC:
fn1:
movslq a(%rip), %rax
movabsq $-9223372036854775808, %rdx
andq %rdx, %rax
cmpq $4, %rax
setle %al
movzbl %al, %eax
movl %eax, b(%rip)
ret
COMMAND: gcc -w -O3 reduce_165/foo.c -S -o -