[PATCH] D19341: Add micro-optimization for 'icmp slt (or A, B), A' to instsimplify.

Nick Lewycky via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 20 14:24:40 PDT 2016


nlewycky created this revision.
nlewycky added a subscriber: llvm-commits.
nlewycky set the repository for this revision to rL LLVM.

Add optimization for 'icmp slt (or A, B), A' and some related idioms based on knowledge of the sign bit for A and B.

No matter what value you OR in to A, the result of (or A, B) is going to be UGE A. When A and B are positive, it's SGE too. If A is negative, OR'ing a value into it can't make it positive, but can increase its value closer to -1, therefore (or A, B) is SGE A. Working through all possible combinations produces this truth table:

```
A is
+, -, +/-
F  F   F   +    B is
T  F   ?   -
?  F   ?   +/-
```

The related optimizations are flipping the 'slt' for 'sge' which always NOTs the result (if the result is known), and swapping the LHS and RHS while swapping the comparison predicate.

There are more idioms left to implement (aren't there always!) but I've stopped here because any more would risk becoming unreasonable for reviewers.

Repository:
  rL LLVM

http://reviews.llvm.org/D19341

Files:
  include/llvm/Analysis/ValueTracking.h
  lib/Analysis/InstructionSimplify.cpp
  lib/Analysis/ValueTracking.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19341.54418.patch
Type: text/x-patch
Size: 4552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160420/14203aa6/attachment.bin>


More information about the llvm-commits mailing list