[Mlir-commits] [llvm] [mlir] Add usub_cond and usub_sat operations to atomicrmw (PR #105568)

Jay Foad llvmlistbot at llvm.org
Thu Aug 22 03:17:21 PDT 2024


================
@@ -95,6 +95,17 @@ Value *llvm::buildAtomicRMWValue(AtomicRMWInst::BinOp Op,
     Value *Or = Builder.CreateOr(CmpEq0, CmpOldGtVal);
     return Builder.CreateSelect(Or, Val, Dec, "new");
   }
+  case AtomicRMWInst::USubCond: {
+    Value *Cmp = Builder.CreateICmpUGE(Loaded, Val);
+    Value *Sub = Builder.CreateSub(Loaded, Val);
+    return Builder.CreateSelect(Cmp, Sub, Val, "new");
+  }
+  case AtomicRMWInst::USubSat: {
+    Constant *Zero = ConstantInt::get(Loaded->getType(), 0);
+    Value *Cmp = Builder.CreateICmpUGE(Loaded, Val);
+    Value *Sub = Builder.CreateSub(Loaded, Val);
+    return Builder.CreateSelect(Cmp, Sub, Zero, "new");
----------------
jayfoad wrote:

Could you do this instead?
```suggestion
    return Builder.CreateIntrinsic(Intrinsic::usub_sat, Loaded->getType(), {Loaded, Val}, nullptr, "new");
```

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


More information about the Mlir-commits mailing list