[PATCH] InstCombine: constant comparison involving ashr is wrongly simplified (PR20945).

Andrea Di Biagio Andrea_DiBiagio at sn.scee.net
Tue Sep 16 12:58:09 PDT 2014


Hi Duncan,

Here is an updated patch which I think/hope addresses all your comments.

There is one main difference with respect to what you suggested (see below)

> Then change this to:
>
>     if (!IsNegative && AP1.ugt(AP2))
>       // Right-shifting won't increase the magnitude.
>       return getConstant(false);
>

That check should also take into account the case where 'IsAShr' is false, AP2 is negative and AP1 is positive.
Otherwise, it would have failed for the following case:

{code}
define i1 @foo(i8 %a) {
  %shr = lshr exact i8 -128, %a
  %cmp = icmp eq i8 %shr, 1
  ret i1 %cmp
}
{code}

Please let me know what you think.
Thanks,
Andrea

http://reviews.llvm.org/D5356

Files:
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  test/Transforms/InstCombine/icmp-shr.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D5356.13759.patch
Type: text/x-patch
Size: 3009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140916/d83b6ff3/attachment.bin>


More information about the llvm-commits mailing list