[Mlir-commits] [mlir] [mlir][arith][NFC] Make AtomicRMWKind switches exhaustive (PR #214622)
曾鈜寬 Tseng Hung Kuan
llvmlistbot at llvm.org
Sun Aug 9 05:52:51 PDT 2026
https://github.com/Tim096 updated https://github.com/llvm/llvm-project/pull/214622
>From d3cedcc87cee8420f78ae7c5e1abf84e27734822 Mon Sep 17 00:00:00 2001
From: Hung-Kuan Tseng <p76091014 at gs.ncku.edu.tw>
Date: Fri, 7 Aug 2026 11:32:55 +0800
Subject: [PATCH] [mlir][arith][NFC] Make AtomicRMWKind switches exhaustive
The only kind getIdentityValueAttr and getReductionOp leave unhandled is
`assign`, which is not a reduction: it has no identity element and no
corresponding binary operation, so their "TODO: Add remaining reduction
operations" can never be finished.
Handle it explicitly and drop the default label, so -Wswitch flags any
kind added later. The diagnostic moves below the switch, leaving
behavior unchanged.
---
mlir/lib/Dialect/Arith/IR/ArithOps.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index ff6a5d4a0c29a..fc50284fc8a94 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -3131,11 +3131,11 @@ TypedAttr mlir::arith::getIdentityValueAttr(AtomicRMWKind kind, Type resultType,
return builder.getIntegerAttr(resultType, 1);
case AtomicRMWKind::mulf:
return builder.getFloatAttr(resultType, 1);
- // TODO: Add remaining reduction operations.
- default:
- (void)emitOptionalError(loc, "Reduction operation type not supported");
+ // `assign` is not a reduction and has no identity element.
+ case AtomicRMWKind::assign:
break;
}
+ (void)emitOptionalError(loc, "Reduction operation type not supported");
return nullptr;
}
@@ -3226,11 +3226,11 @@ Value mlir::arith::getReductionOp(AtomicRMWKind op, OpBuilder &builder,
return arith::AndIOp::create(builder, loc, lhs, rhs);
case AtomicRMWKind::xori:
return arith::XOrIOp::create(builder, loc, lhs, rhs);
- // TODO: Add remaining reduction operations.
- default:
- (void)emitOptionalError(loc, "Reduction operation type not supported");
+ // `assign` is not a reduction and has no corresponding binary operation.
+ case AtomicRMWKind::assign:
break;
}
+ (void)emitOptionalError(loc, "Reduction operation type not supported");
return nullptr;
}
More information about the Mlir-commits
mailing list