[PATCH] D130039: [InstCombine] Improve folding of mul + icmp

Alexander Shaposhnikov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 13:49:07 PDT 2022


alexander-shaposhnikov created this revision.
alexander-shaposhnikov added reviewers: nikic, craig.topper.
alexander-shaposhnikov created this object with visibility "All Users".
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
alexander-shaposhnikov requested review of this revision.
Herald added a project: LLVM.

This diffs adds folds for patterns like X * A < B where A, B are constants and "mul" has either "nsw" or "nuw". 
(to address https://github.com/llvm/llvm-project/issues/56563).

Let's assume that A is positive.  
X * A < B is equivalent to X < (rational) B/A, since X is an integer the right hand side can be replaced with 
the upper rounding of B/A.
X  * A <= B is equivalent to X <= (rational) B/A, since X is an integer the right hand side can be replaced with 
the lower rounding of B/A.

Alive proofs for the tests:
1/ https://alive2.llvm.org/ce/z/T-ngQD
2/ https://alive2.llvm.org/ce/z/8TV5hH
3/ https://alive2.llvm.org/ce/z/twC7Fn
4/ https://alive2.llvm.org/ce/z/gHsUUc
5/ https://alive2.llvm.org/ce/z/6G93_U
6/ https://alive2.llvm.org/ce/z/9fDMMJ
7/ https://alive2.llvm.org/ce/z/Bjz1rp
8/ https://alive2.llvm.org/ce/z/P-y54i
9/ https://alive2.llvm.org/ce/z/qMV98P
10/ https://alive2.llvm.org/ce/z/ypF6nG
11/ https://alive2.llvm.org/ce/z/TWeCML


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130039

Files:
  llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
  llvm/test/Analysis/ValueTracking/known-power-of-two-urem.ll
  llvm/test/Transforms/InstCombine/icmp-mul.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130039.445612.patch
Type: text/x-patch
Size: 6673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220718/f13cf9d5/attachment.bin>


More information about the llvm-commits mailing list