Souper says:
; Function: fn1
%0:i32 = var
%1:i1 = ne 0:i32, %0
%2:i32 = select %1, %0, 1:i32
%3:i1 = eq 0:i32, %2
cand %3 0:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_198/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%tobool = icmp ne i32 %0, 0
%. = select i1 %tobool, i32 %0, i32 1
store i32 %., i32* @b, align 4, !tbaa !1
%tobool1 = icmp eq i32 %., 0
br i1 %tobool1, label %for.end.split, label %for.cond.preheader
for.cond.preheader: ; preds = %entry
br label %for.cond
for.cond: ; preds = %for.cond.preheader, %for.cond
br label %for.cond
for.end.split: ; preds = %entry
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_198/foo.c -o reduce_198/foo.bc
C source code:
int a, b;
void fn1() {
b = a ?: 1;
for (; b;)
;
}
x86-64 from LLVM:
fn1: # @fn1
movl a(%rip), %eax
testl %eax, %eax
movl $1, %ecx
cmovnel %eax, %ecx
testl %ecx, %ecx
movl %ecx, b(%rip)
je .LBB0_2
.LBB0_1: # %for.cond
jmp .LBB0_1
.LBB0_2: # %for.end.split
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_198/foo.c -S -o -
x86-64 from GCC:
fn1:
movl a(%rip), %edx
movl $1, %eax
testl %edx, %edx
cmovne %edx, %eax
movl %eax, b(%rip)
.L3:
jmp .L3
COMMAND: gcc -w -O3 reduce_198/foo.c -S -o -