[clang] [CIR] Fold constant add and sub operations (PR #218398)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 25 17:49:01 PDT 2026
================
@@ -2941,22 +2941,27 @@ mlir::LogicalResult cir::FuncOp::verify() {
// AddOp / SubOp
//===----------------------------------------------------------------------===//
-// The integer-only type constraint on these ops makes the nsw/nuw/sat flag
-// type checks unnecessary. Only the mutual-exclusivity between nsw/nuw and
-// sat needs to be verified.
+static LogicalResult verifyAddSubFlags(Operation *op, Type type, bool nsw,
+ bool nuw, bool sat) {
+ if ((nsw && nuw) || (sat && (nsw || nuw)))
----------------
andykaylor wrote:
This seems reasonable for CIR, but the nsw and nuw flags are most definitely not mutually exclusive in LLVM IR. The fact that CIR has signed types (and not a signless type) changes the situation a bit. The checks below would be sufficient to sort that out.
I'm concerned that we're going to find that we need both flags somewhere to match existing behavior, but maybe we won't need that until lowering to a different dialect. I think the case where it comes up in classic codegen has to do with a target-specific offset calculation, which would be abstracted in CIR.
@bcardosolopes What do you think?
https://github.com/llvm/llvm-project/pull/218398
More information about the cfe-commits
mailing list