[PATCH] D38531: Improve clamp recognition in ValueTracking.

Artur Gainullin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 4 01:37:55 PDT 2017


ArturGainullin created this revision.

ValueTracking was recognizing not all variations of clamp. Swapping of
true value and false value of select was added to fix this problem. This
change breaks the canonical form of cmp inside the matchMinMax function,
that is why additional checks for compare predicates is needed. Added
corresponding test cases.

Also there is a reverse transformation for cmp instruction:

  icmp smin(x, PositiveValue), 0 -> icmp x, 0

We should only do this after checking for min/max to prevent infinite
looping caused by a reverse canonicalization of these patterns. That is
why this transformation was moved to place after the mentioned check.
Test case was also added to check that we don't go to infinite loop.


https://reviews.llvm.org/D38531

Files:
  lib/Analysis/ValueTracking.cpp
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  lib/Transforms/InstCombine/InstCombineInternal.h
  test/Transforms/InstCombine/minmax-fold.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38531.117633.patch
Type: text/x-patch
Size: 12913 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171004/56551491/attachment.bin>


More information about the llvm-commits mailing list