[InstCombine] Optimize icmp of inc/dec at RHS
authorMichael Liao <michael.liao@intel.com>
Mon, 19 Oct 2015 22:08:14 +0000 (22:08 +0000)
committerMichael Liao <michael.liao@intel.com>
Mon, 19 Oct 2015 22:08:14 +0000 (22:08 +0000)
commit2949a6ae049a27a52053318ab29ab8d2775cc320
treeb358a51299857ed570c686a417cee24c0dd9c383
parentf792618d1c05c8f152a9901937529b101730b774
[InstCombine] Optimize icmp of inc/dec at RHS

Allow LLVM to optimize the sequence like the following:

  %inc = add nsw i32 %i, 1
  %cmp = icmp slt %n, %inc

into:

  %cmp = icmp sle i32 %n, %i

The case is not handled previously due to the complexity of compuation of %n.
Hence, LLVM cannot swap operands of icmp accordingly.

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