[PATCH] [InstCombineCompares] Added shl optimization for the instruction - icmp ugt/ult/uge/ule (shl Const2, A), Const1

Ankur Garg ankur29.garg at samsung.com
Thu Nov 6 03:12:39 PST 2014


Hi David,
Thanks for reviewing the patch.
I have made the changes to correct the error you pointed out.

There are two cases:
Const 1 < Const 2
In this case i have added separate if else for the cases you have mentioned. So, this case is correct now.
Const 1 > Const 2
In this case, if Const 2 has some trailing zeros, that means it can be made zero by left shifting by an amount less than its bit width. In such cases, after the transformation, expression will involve two comparisons. For example:

%shl = shl i32 76, %a
 %cmp = icmp ugt i32 %shl, 108
 ret i1 %cmp
here %a should be greater than 0 and less than 31
So, this transformation is infact increasing the number of operations required. After the transformation this would become: 
and (icmp ugt i32 A, 0), (icmp ult i32 A, 31)
This involves 3 operations (greater than the earlier 2).
So, I haven't included transformations for such cases as it is not leading to optimization.
Please suggest any other way to do this, if possible.
Please review the updated revision.

Thanks.

http://reviews.llvm.org/D6131

Files:
  lib/Transforms/InstCombine/InstCombine.h
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  test/Transforms/InstCombine/icmp.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D6131.15849.patch
Type: text/x-patch
Size: 9617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141106/78c0de2f/attachment.bin>


More information about the llvm-commits mailing list