Souper says:
; Function: fn1
%0:i32 = var
%1:i32 = subnsw 1:i32, %0
%2:i1 = ne %0, %1
cand %2 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_341/foo.bc
LLVM says:
define i32 @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%sub = sub nsw i32 1, %0
%xor = xor i32 %sub, %0
%tobool = icmp ne i32 %sub, %0
%xor. = select i1 %tobool, i32 %xor, i32 1
ret i32 %xor.
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_341/foo.c -o reduce_341/foo.bc
C source code:
int a;
int fn1() { return 1 - a ^ a ?: 1; }
x86-64 from LLVM:
fn1: # @fn1
movl a(%rip), %ecx
movl $1, %edx
movl $1, %esi
subl %ecx, %esi
movl %esi, %eax
xorl %ecx, %eax
cmpl %ecx, %esi
cmovel %edx, %eax
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_341/foo.c -S -o -
x86-64 from GCC:
fn1:
movl a(%rip), %edx
movl $1, %eax
movl %eax, %ecx
subl %edx, %ecx
xorl %ecx, %edx
cmovne %edx, %eax
ret
COMMAND: gcc -w -O3 reduce_341/foo.c -S -o -