[llvm] [InstCombine] Fold converted urem to 0 if there's no overlapping bits (PR #71528)

via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 7 09:56:56 PST 2023


================
@@ -2662,6 +2662,16 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
   if (sinkNotIntoOtherHandOfLogicalOp(I))
     return &I;
 
+  // (x << N) & (add (x << M), -1) --> 0, where x is known to be a non-zero
+  // power of 2 and M <= N.
+  const APInt *Shift1, *Shift2;
+  if (match(&I, m_c_And(m_OneUse(m_Shl(m_Value(X), m_APInt(Shift1))),
+                        m_OneUse(m_Add(m_Shl(m_Value(Y), m_APInt(Shift2)),
----------------
goldsteinn wrote:

You don't need these OneUse checks. This fold won't create more insts.

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


More information about the llvm-commits mailing list