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

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 19 22:13:24 PST 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)))) &&
+        match(Arg1, m_APInt(C2)) && SI->hasOneUse()) {
----------------
XChy wrote:

```suggestion
        match(Arg1, m_APInt(C2))) {
```

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


More information about the llvm-commits mailing list