[PATCH] D113366: [InstCombine] Canonicalize range test idiom

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 7 09:35:53 PST 2021


nikic created this revision.
nikic added reviewers: spatel, lebedev.ri.
Herald added a subscriber: hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

InstCombine converts range tests of the form (X > C1 <https://reviews.llvm.org/C1> && X < C2) or (X < C1 <https://reviews.llvm.org/C1> || X > C2) into checks of the form (X + C3 < C4) or (X + C3 > C4). It is possible to express all range tests in either of these forms (with different choices of constants), but currently neither of them is considered canonical. We may have equivalent range tests using either ult or ugt.

This proposes to canonicalize all range tests to use ult. An alternative would be to canonicalize to either ult or ugt depending on the specific constants involved -- e.g. in practice we currently generate ult for && style ranges and ugt for || style ranges when going through the insertRangeTest() helper. In fact, the "clamp like" fold was relying on this, which is why I had to tweak it to not assume whether inversion is needed based on just the predicate.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D113366

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
  llvm/test/Transforms/InstCombine/2006-12-15-Range-Test.ll
  llvm/test/Transforms/InstCombine/2007-03-21-SignedRangeTest.ll
  llvm/test/Transforms/InstCombine/2008-08-05-And.ll
  llvm/test/Transforms/InstCombine/and-or-icmps.ll
  llvm/test/Transforms/InstCombine/canonicalize-signed-truncation-check.ll
  llvm/test/Transforms/InstCombine/icmp-add.ll
  llvm/test/Transforms/InstCombine/icmp-sub.ll
  llvm/test/Transforms/InstCombine/icmp-topbitssame.ll
  llvm/test/Transforms/InstCombine/load-cmp.ll
  llvm/test/Transforms/InstCombine/or.ll
  llvm/test/Transforms/InstCombine/overflow.ll
  llvm/test/Transforms/InstCombine/smulo.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113366.385352.patch
Type: text/x-patch
Size: 24203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211107/00473e5a/attachment.bin>


More information about the llvm-commits mailing list