Hi,
This patch implements optimization mentioned in
http://www.cs.utah.edu/~regehr/souper/output_6.html
where we know that when comparing with a constant whose trailing zero's are less than trailing zero's of LHS, it will never be equal.
C test case :
int a, b;
void fn1() { b = a * ~1 == 1; }
gcc output (X86):
fn1:
movl $0, b(%rip)
ret
LLVM output before patch(X86) at O2 optimization :
fn1: # @fn1
movl a(%rip), %eax
addl %eax, %eax
cmpl $-1, %eax
sete %al
movzbl %al, %eax
movl %eax, b(%rip)
retq
LLVM Output after patch (X86) at O2 optimization:
fn1:
movl $0, b(%rip)
retq
Added test case for the same.
TODO : Generalize this for all constants, currently implemented for comparing with 1.
Please help in reviewing the patch.