Souper says:
; Function: fn1
%0:i32 = var
%1:i1 = ult 1:i32, %0
%2:i32 = shl %0, 1:i32
%3:i32 = select %1, 0:i32, %2
%4:i1 = ne 1:i32, %3
cand %4 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_696/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%tobool = icmp ugt i32 %0, 1
%shl = shl i32 %0, 1
%.shl = select i1 %tobool, i32 0, i32 %shl
store i32 %.shl, i32* @c, align 4, !tbaa !1
%cmp = icmp ne i32 %.shl, 1
%conv = zext i1 %cmp to i32
store i32 %conv, i32* @b, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_696/foo.c -o reduce_696/foo.bc
C source code:
int a, b, c;
void fn1() {
c = a >> 1 ? 0 : a << 1;
b = c != 1;
}
x86-64 from LLVM:
fn1: # @fn1
movl a(%rip), %eax
leal (%rax,%rax), %ecx
xorl %edx, %edx
cmpl $1, %eax
cmovbel %ecx, %edx
cmpl $1, %edx
movl %edx, c(%rip)
setne %al
movzbl %al, %eax
movl %eax, b(%rip)
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_696/foo.c -S -o -
x86-64 from GCC:
fn1:
movl a(%rip), %edx
xorl %eax, %eax
movl $1, b(%rip)
leal (%rdx,%rdx), %ecx
shrl %edx
cmove %ecx, %eax
movl %eax, c(%rip)
ret
COMMAND: gcc -w -O3 reduce_696/foo.c -S -o -