Souper says:
; Function: fn1
%0:i32 = var
%1:i1 = slt 0:i32, %0
pc %1 1:i1
%2:i32 = var
%3:i1 = ne 0:i32, %2
%4:i1 = slt %2, %0
%5:i1 = or %3, %4
cand %5 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_22/foo.bc
LLVM says:
define void @fn1() #0 {
entry:
%0 = load i32* @b, align 4, !tbaa !1
%cmp1 = icmp sgt i32 %0, 0
%a.promoted = load i32* @a, align 4
br i1 %cmp1, label %entry.split.us, label %entry.entry.split_crit_edge
entry.entry.split_crit_edge: ; preds = %entry
%cmp2 = icmp slt i32 %a.promoted, %0
%lor.ext = zext i1 %cmp2 to i32
%lor.ext. = select i1 %cmp2, i32 %lor.ext, i32 0
br label %for.end
entry.split.us: ; preds = %entry
%tobool.us = icmp ne i32 %a.promoted, 0
%cmp2.us = icmp slt i32 %a.promoted, %0
%.cmp2.us = or i1 %tobool.us, %cmp2.us
%lor.ext.us = zext i1 %.cmp2.us to i32
%lor.ext..us = select i1 %.cmp2.us, i32 %lor.ext.us, i32 0
br label %for.end
for.end: ; preds = %entry.split.us, %entry.entry.split_crit_edge
%lor.ext..lcssa = phi i32 [ %lor.ext., %entry.entry.split_crit_edge ], [ %lor.ext..us, %entry.split.us ]
store i32 %lor.ext..lcssa, i32* @a, align 4
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_22/foo.c -o reduce_22/foo.bc
C source code:
int a, b;
void fn1() {
int c = 0;
for (; c >= 0; c--)
a = b > 0 && a || a < b ?: 0;
}
x86-64 from LLVM:
fn1: # @fn1
movl b(%rip), %eax
testl %eax, %eax
movl a(%rip), %ecx
jle .LBB0_1
testl %ecx, %ecx
setne %dl
cmpl %eax, %ecx
setl %al
xorl %ecx, %ecx
orb %dl, %al
movzbl %al, %eax
cmovel %ecx, %eax
movl %eax, a(%rip)
retq
.LBB0_1: # %entry.entry.split_crit_edge
xorl %edx, %edx
cmpl %eax, %ecx
setl %al
movzbl %al, %eax
cmovgel %edx, %eax
movl %eax, a(%rip)
retq
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_22/foo.c -S -o -
x86-64 from GCC:
fn1:
movl b(%rip), %eax
movl a(%rip), %edx
testl %eax, %eax
jle .L4
movl a(%rip), %edx
testl %edx, %edx
je .L5
movl $1, %eax
movl %eax, a(%rip)
ret
.L5:
xorl %edx, %edx
.L4:
cmpl %eax, %edx
setl %al
movzbl %al, %eax
movl %eax, a(%rip)
ret
COMMAND: gcc -w -O3 reduce_22/foo.c -S -o -