================
@@ -3185,6 +3185,71 @@ OpFoldResult cir::NotOp::fold(FoldAdaptor adaptor) {
return {};
}
+//===----------------------------------------------------------------------===//
+// AddOp & SubOp
+//===----------------------------------------------------------------------===//
+
+// Constant-fold integer add/sub. Honors nsw/nuw by folding to poison on the
+// corresponding overflow, and folds saturated arithmetic by clamping.
+static OpFoldResult foldAddSubConst(mlir::Type ty, const APInt &lhs,
+ const APInt &rhs, bool isSub, bool nsw,
+ bool nuw, bool sat) {
+ bool isSigned = mlir::cast<cir::IntType>(ty).isSigned();
+ if (sat) {
+ APInt res = isSub ? (isSigned ? lhs.ssub_sat(rhs) : lhs.usub_sat(rhs))
+ : (isSigned ? lhs.sadd_sat(rhs) : lhs.uadd_sat(rhs));
+ return cir::IntAttr::get(ty, res);
+ }
+
+ bool poison = false;
+ if (nsw) {
----------------
prometheusfma-llvm wrote:
Thanks for taking a look. What about fixups added in the recent commit? Does
that look fine?
https://github.com/llvm/llvm-project/pull/218398
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits