Souper says:
; Function: fn2
%0:i32 = var
%1:i1 = slt 0:i32, %0
%2:i32 = zext %1
%3:i32 = or 4:i32, %2
%4:i32 = sub 0:i32, %3
%5:i1 = slt %4, 0:i32
cand %5 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_111/foo.bc
LLVM says:
define i32 @fn1(i32 %p1) #0 {
entry:
%cmp = icmp slt i32 %p1, 0
%p1.lobit = lshr i32 %p1, 31
%conv. = select i1 %cmp, i32 %p1.lobit, i32 0
ret i32 %conv.
}
define void @fn2() #1 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%cmp = icmp sgt i32 %0, 0
%conv1 = zext i1 %cmp to i32
%xor3 = or i32 %conv1, 4
%sub = sub i32 0, %xor3
%cmp.i = icmp slt i32 %sub, 0
%p1.lobit.i = lshr i32 %sub, 31
%conv..i = select i1 %cmp.i, i32 %p1.lobit.i, i32 0
store i32 %conv..i, i32* @b, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_111/foo.c -o reduce_111/foo.bc
C source code:
int a, b;
int fn1(p1) { return p1 < 0 ?: 0; }
void fn2() { b = fn1(-(4L ^ a > 0)); }
x86-64 from LLVM:
fn1: # @fn1
andl %edi, %edi
shrl $31, %edi
movl %edi, %eax
retq
fn2: # @fn2
cmpl $0, a(%rip)
setg %al
movzbl %al, %eax
orl $4, %eax
negl %eax
andl %eax, %eax
shrl $31, %eax
movl %eax, b(%rip)
retq
.Ltmp1:
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_111/foo.c -S -o -
x86-64 from GCC:
fn1:
movl %edi, %eax
shrl $31, %eax
ret
fn2:
.LFB1:
movl $1, b(%rip)
ret
.LFE1:
COMMAND: gcc -w -O3 reduce_111/foo.c -S -o -