]> granicus.if.org Git - llvm/commit
[InstCombine] optimize unsigned icmp of increment
authorSanjay Patel <spatel@rotateright.com>
Fri, 13 Jan 2017 23:25:46 +0000 (23:25 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 13 Jan 2017 23:25:46 +0000 (23:25 +0000)
commit3d039197d7b28c113aab45bd42a5040e11a20d31
treed765a22268edd5a9cc63001e55800f933dafbc7a
parentb5ead7c450de20242c1d0828dfa6cbd999ce2b4c
[InstCombine] optimize unsigned icmp of increment

Allows LLVM to optimize sequences like the following:

%add = add nuw i32 %x, 1
%cmp = icmp ugt i32 %add, %y

Into:

%cmp = icmp uge i32 %x, %y

Previously, only signed comparisons were being handled.

Decrements could also be handled, but 'sub nuw %x, 1' is currently canonicalized to
'add %x, -1' in InstCombineAddSub, losing the nuw flag. Removing that canonicalization
seems like it might have far-reaching ramifications so I kept this simple for now.

Patch by Matti Niemenmaa!

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

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