Souper says:
; Function: fn1
%0:i32 = var
%1:i32 = srem %0, 7:i32
%2:i16 = trunc %1
%3:i1 = slt 9:i16, %2
cand %3 0:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_436/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%rem = srem i32 %0, 7
%conv = trunc i32 %rem to i16
store i16 %conv, i16* @c, align 2, !tbaa !5
%cmp = icmp sgt i16 %conv, 9
%conv2 = zext i1 %cmp to i32
store i32 %conv2, i32* @b, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_436/foo.c -o reduce_436/foo.bc
C source code:
int a, b;
short c;
void fn1() {
c = a % 7;
b = c >= 10;
}
x86-64 from LLVM:
fn1: # @fn1
movslq a(%rip), %rax
imulq $-1840700269, %rax, %rcx # imm = 0xFFFFFFFF92492493
shrq $32, %rcx
addl %eax, %ecx
movl %ecx, %edx
shrl $31, %edx
shrl $2, %ecx
addl %edx, %ecx
imull $7, %ecx, %ecx
subl %ecx, %eax
cwtl
cmpl $9, %eax
movw %ax, c(%rip)
setg %al
movzbl %al, %eax
movl %eax, b(%rip)
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_436/foo.c -S -o -
x86-64 from GCC:
fn1:
movl a(%rip), %ecx
movl $-1840700269, %edx
movl $0, b(%rip)
movl %ecx, %eax
imull %edx
movl %ecx, %eax
sarl $31, %eax
addl %ecx, %edx
sarl $2, %edx
subl %eax, %edx
leal 0(,%rdx,8), %eax
subl %edx, %eax
subl %eax, %ecx
movw %cx, c(%rip)
ret
COMMAND: gcc -w -O3 reduce_436/foo.c -S -o -