[llvm] [SCCP] Simplify [us]cmp(X, Y) into X - Y (PR #144717)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 19 12:38:36 PDT 2025


================
@@ -245,11 +247,45 @@ static Value *simplifyInstruction(SCCPSolver &Solver,
   const APInt *RHSC;
   // Remove masking operations.
   if (match(&Inst, m_And(m_Value(X), m_LowBitMask(RHSC)))) {
-    ConstantRange LRange = GetRange(Inst.getOperand(0));
+    ConstantRange LRange = GetRange(X);
     if (LRange.getUnsignedMax().ule(*RHSC))
       return X;
   }
 
+  // Check if we can simplify [us]cmp(X, Y) to X - Y.
+  if (auto *Cmp = dyn_cast<CmpIntrinsic>(&Inst)) {
+    Intrinsic::ID IID = Cmp->getIntrinsicID();
+    Value *LHS = Cmp->getOperand(0);
+    Value *RHS = Cmp->getOperand(1);
+    unsigned BitWidth = LHS->getType()->getScalarSizeInBits();
+    // Bail out on 1-bit comparisons.
+    // if (BitWidth == 1)
+    //   return nullptr;
----------------
nikic wrote:

Should not be commented?

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


More information about the llvm-commits mailing list