[llvm] [SCCP] Remove masking operations (PR #142736)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 4 00:48:19 PDT 2025


================
@@ -157,6 +162,15 @@ static bool refineInstruction(SCCPSolver &Solver,
                           GEPNoWrapFlags::noUnsignedWrap());
       Changed = true;
     }
+  } else if (match(&Inst, m_And(m_Value(X), m_LowBitMask(RHSC)))) {
+    ConstantRange LRange = GetRange(Inst.getOperand(0));
+    if (!LRange.getUnsignedMax().ule(*RHSC))
+      return false;
+
+    Inst.replaceAllUsesWith(X);
+    Inst.eraseFromParent();
+    ++InstRemovedStat;
+    Changed = true;
----------------
nikic wrote:

This doesn't really fit with the other "refine" transforms, which all infer flags. I'd probably handle it outside this function, but no strong opinion.

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


More information about the llvm-commits mailing list