Fold ashr-exact into a icmp-ugt.
authorNadav Rotem <nadav256@gmail.com>
Fri, 14 Jan 2022 16:55:10 +0000 (08:55 -0800)
committerNadav Rotem <nadav256@gmail.com>
Fri, 14 Jan 2022 20:58:44 +0000 (12:58 -0800)
commit9551fc57b7e98b27844ef840b13773844c738f92
tree7c660872e9b2376d00d3c11154c42756d43c0a3e
parent7af11989be21df00ad6a510a831ea2425e48fa90
Fold ashr-exact into a icmp-ugt.

This commit optimizes the code sequence:
  icmp-XXX (ashr-exact (X, C_1), C_2).

Instcombine already implements this optimization for sgt, and this
patch adds support to additional predicates. The transformation is legal
for all predicates if the 'exact' flag is set, and to SGE, UGE, SLT, ULT
when the exact flag is not present.

This pattern is found in the std::vector bounds checks code of the at()
method.

Alive2 proof:
https://alive2.llvm.org/ce/z/JT_WL8

Differential Revision: https://reviews.llvm.org/D117252
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-shr-lt-gt.ll
llvm/test/Transforms/InstCombine/icmp-shr.ll