Souper says:
; Function: fn2
%0:i32 = var
%1:i32 = ashr 4294955978:i32, %0
%2:i1 = slt %1, 1:i32
cand %2 1:i1
COMMAND: /home/regehr/souper/build/souper -stp-path=/usr/local/bin/stp reduce_744/foo.bc
LLVM says:
define void @fn2() #0 {
entry:
%0 = load i32* @a, align 4, !tbaa !1
%shr.i = ashr i32 -11318, %0
%cmp.i = icmp slt i32 %shr.i, 1
%conv2.i = zext i1 %cmp.i to i32
store i32 %conv2.i, i32* @a, align 4, !tbaa !1
ret void
}
define void @fn1(i64 %p1) #0 {
entry:
%conv = trunc i64 %p1 to i32
%sext = shl i32 %conv, 16
%conv1 = ashr exact i32 %sext, 16
%0 = load i32* @a, align 4, !tbaa !1
%shr = ashr i32 %conv1, %0
%cmp = icmp slt i32 %shr, 1
%conv2 = zext i1 %cmp to i32
store i32 %conv2, i32* @a, align 4, !tbaa !1
ret void
}
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -c -w -emit-llvm -O3 reduce_744/foo.c -o reduce_744/foo.bc
C source code:
int a;
void fn1(unsigned long long);
void fn2() { fn1(54218); }
void fn1(unsigned long long p1) {
short b = p1;
a = b >> a < 1;
}
x86-64 from LLVM:
fn2: # @fn2
movb a(%rip), %cl
movl $-11318, %eax # imm = 0xFFFFFFFFFFFFD3CA
sarl %cl, %eax
testl %eax, %eax
setle %al
movzbl %al, %eax
movl %eax, a(%rip)
retq
fn1: # @fn1
movswl %di, %eax
movb a(%rip), %cl
sarl %cl, %eax
testl %eax, %eax
setle %al
movzbl %al, %eax
movl %eax, a(%rip)
retq
.Ltmp1:
COMMAND: /home/regehr/souper/third_party/llvm/Debug/bin/clang -w -O3 reduce_744/foo.c -S -o -
x86-64 from GCC:
fn2:
movl a(%rip), %ecx
movl $-11318, %eax
sarl %cl, %eax
testl %eax, %eax
setle %al
movzbl %al, %eax
movl %eax, a(%rip)
ret
fn1:
.LFB1:
movl a(%rip), %ecx
movswl %di, %edi
xorl %eax, %eax
sarl %cl, %edi
testl %edi, %edi
setle %al
movl %eax, a(%rip)
ret
.LFE1:
COMMAND: gcc -w -O3 reduce_744/foo.c -S -o -