[InstCombine] Transform A & (L - 1) u< L --> L != 0
authorSanjoy Das <sanjoy@playingwithpointers.com>
Thu, 20 Aug 2015 22:31:55 +0000 (22:31 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Thu, 20 Aug 2015 22:31:55 +0000 (22:31 +0000)
commitba3890260570dfae3eeec8b064d0e9a8d7470e75
treec5eeae1d1289187a684c5e6683f8885bf86ce8b9
parent9cd73adba00afbd76eb686252ff4d6a4c69ebce2
[InstCombine] Transform A & (L - 1) u< L --> L != 0

Summary:
This transform is never a pessimization at the IR level (since it
replaces an `icmp` with another), and has potentiall payoffs:

 1. It may make the `icmp` fold away or become loop invariant.
 2. It may make the `A & (L - 1)` computation dead.

This shows up in Java, in range checks generated by array accesses of
the form `a[i & (a.length - 1)]`.

Reviewers: reames, majnemer

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D12210

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245635 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp.ll