Souper says:
; Function: fn1
%0:i32 = var
%1:i32 = srem 1:i32, %0
%2:i32 = lshr %1, 1:i32
%3:i1 = ne 0:i32, %2
cand %3 0:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_537/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%rem = srem i32 1, %0
%shr1 = lshr i32 %rem, 1
%tobool = icmp ne i32 %shr1, 0
%shr. = select i1 %tobool, i32 %shr1, i32 1
store i32 %shr., i32* @a, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_537/foo.c -o reduce_537/foo.bc
C source code:
int a;
void fn1() { a = 1 % a >> 1 ?: 1; }
x86-64 from LLVM:
fn1: # @fn1
movl $1, %ecx
movl $1, %eax
xorl %edx, %edx
idivl a(%rip)
shrl %edx
cmovel %ecx, %edx
movl %edx, a(%rip)
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_537/foo.c -S -o -
x86-64 from GCC:
fn1:
movl $1, %ecx
movl %ecx, %eax
cltd
idivl a(%rip)
sarl %edx
cmovne %edx, %ecx
movl %ecx, a(%rip)
ret
COMMAND: gcc -w -O3 reduce_537/foo.c -S -o -