]> granicus.if.org Git - llvm/commit
[InstSimplify] try to eliminate icmp Pred (add nsw X, C1), C2
authorSanjay Patel <spatel@rotateright.com>
Tue, 24 Jan 2017 17:03:24 +0000 (17:03 +0000)
committerSanjay Patel <spatel@rotateright.com>
Tue, 24 Jan 2017 17:03:24 +0000 (17:03 +0000)
commitb44cec60e38233498be3243d37fda50f7eaa4961
tree4a99887627f9dc2a475db26b9189cd12d9bb50e9
parentb117c009b6d9725dcc57f747898eb5ea26dcd6f4
[InstSimplify] try to eliminate icmp Pred (add nsw X, C1), C2

I was surprised to see that we're missing icmp folds based on 'add nsw' in InstCombine,
but we should handle the InstSimplify cases first because that could make the InstCombine
code simpler.

Here are Alive-based proofs for the logic:

Name: add_neg_constant
Pre: C1 < 0 && (C2 > ((1<<(width(C1)-1)) + C1))
%a = add nsw i7 %x, C1
%b = icmp sgt %a, C2
  =>
%b = false

Name: add_pos_constant
Pre: C1 > 0 && (C2 < ((1<<(width(C1)-1)) + C1 - 1))
%a = add nsw i6 %x, C1
%b = icmp slt %a, C2
  =>
%b = false

Name: nuw
Pre: C1 u>= C2
%a = add nuw i11 %x, C1
%b = icmp ult %a, C2
  =>
%b = false

Differential Revision: https://reviews.llvm.org/D29053

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292952 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/InstructionSimplify.cpp
test/Transforms/InstSimplify/icmp-constant.ll