[llvm] [InstCombine] Fold usub_sat((sub nuw C1, A), C2) to usub_sat(C1 - C2, A) or 0 (PR #82280)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 10 08:08:11 PDT 2024


================
@@ -2139,6 +2139,23 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
       }
     }
 
+    // usub_sat((sub nuw C1, A), C2) -> usub_sat(C1 - C2, A) if C2 u< C1
+    // usub_sat((sub nuw C1, A), C2) -> 0 otherwise
+    const APInt *C1, *C2;
+    Value *A;
+    if (IID == Intrinsic::usub_sat &&
+        match(Arg0, m_OneUse(m_NUWSub(m_APInt(C1), m_Value(A)))) &&
----------------
nikic wrote:

I think we can drop this m_OneUse as well. We'll get the same number of instructions, but smaller dependence distance.

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


More information about the llvm-commits mailing list