[llvm] [InstCombine] Fold `icmp pred X + K, Y -> icmp pred2 X, Y` if both X and Y is divisible by K (PR #147130)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 5 00:32:35 PDT 2025


================
@@ -5120,6 +5120,15 @@ static Instruction *foldICmpXorXX(ICmpInst &I, const SimplifyQuery &Q,
   return nullptr;
 }
 
+/// Return true if X is a multiple of C.
+/// TODO: Handle non-power-of-2 factors.
+static bool isMultipleOf(Value *X, const APInt &C, const SimplifyQuery &Q) {
+  if (!C.isPowerOf2())
+    return false;
+
+  return MaskedValueIsZero(X, C - 1, Q);
----------------
nikic wrote:

Add a fast-path for C == 1, which does not require KnownBits?

https://github.com/llvm/llvm-project/pull/147130


More information about the llvm-commits mailing list