[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 09:09:50 PDT 2025
    
    
  
================
@@ -245,11 +245,46 @@ 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;
   }
 
+  if (auto *II = dyn_cast<IntrinsicInst>(&Inst)) {
+    Intrinsic::ID IID = II->getIntrinsicID();
+    // Check if we can simplify [us]cmp(X, Y) to X - Y.
+    if (IID == Intrinsic::scmp || IID == Intrinsic::ucmp) {
+      Value *LHS = II->getOperand(0);
+      Value *RHS = II->getOperand(1);
+      unsigned BitWidth = LHS->getType()->getScalarSizeInBits();
----------------
nikic wrote:
Can you please add a test using i1 operands? The transform is incorrect in that case.
https://github.com/llvm/llvm-project/pull/144717
    
    
More information about the llvm-commits
mailing list