Souper says:
; Function: fn1
%0:i32 = var
%1:i32 = srem 1:i32, %0
%2:i32 = and 32768:i32, %1
%3:i1 = ne 0:i32, %2
cand %3 0:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_495/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%rem = srem i32 1, %0
%conv = trunc i32 %rem to i16
store i16 %conv, i16* @b, align 2, !tbaa !5
%sext.mask = and i32 %rem, 32768
%cmp = icmp ne i32 %sext.mask, 0
%1 = lshr i32 %rem, 15
%sext.lobit = and i32 %1, 1
%conv2. = select i1 %cmp, i32 %sext.lobit, i32 0
store i32 %conv2., i32* @c, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_495/foo.c -o reduce_495/foo.bc
C source code:
int a, c;
short b;
void fn1() {
c = 1 % a;
b = c;
c = b < 0 ?: 0;
}
x86-64 from LLVM:
fn1: # @fn1
movl $1, %eax
xorl %edx, %edx
idivl a(%rip)
movw %dx, b(%rip)
movl %edx, %eax
andl $32768, %eax # imm = 0x8000
shrl $15, %eax
shrl $15, %edx
andl $1, %edx
testl %eax, %eax
cmovel %eax, %edx
movl %edx, c(%rip)
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_495/foo.c -S -o -
x86-64 from GCC:
fn1:
movl $1, %eax
cltd
idivl a(%rip)
movswl %dx, %eax
movw %dx, b(%rip)
shrl $31, %eax
movl %eax, c(%rip)
ret
COMMAND: gcc -w -O3 reduce_495/foo.c -S -o -