[Mlir-commits] [mlir] [mlir][llvm dialect] Verify element type of nested types (PR #148975)
Tobias Gysi
llvmlistbot at llvm.org
Tue Jul 15 23:31:30 PDT 2025
================
@@ -3242,24 +3246,42 @@ LogicalResult LLVM::ConstantOp::verify() {
return emitOpError() << "does not support target extension type.";
}
+ // Check that an attribute whose element type has floating point semantics
+ // `attributeFloatSemantics` is compatible with a type whose element type
+ // is `constantElementType`.
+ //
+ // Requirement is that either
+ // 1) They have identical floating point types.
+ // 2) `constantElementType` is an integer type of the same width as the float
+ // attribute. This is to support builtin MLIR float types without LLVM
+ // equivalents, see comments in getLLVMConstant for more details.
+ auto verifyFloatSemantics =
+ [this](const llvm::fltSemantics &attributeFloatSemantics,
+ Type constantElementType) -> LogicalResult {
+ if (auto floatType = dyn_cast<FloatType>(constantElementType)) {
+ if (&floatType.getFloatSemantics() != &attributeFloatSemantics) {
+ return emitOpError()
+ << "attribute and type have different float semantics";
+ }
+ return success();
+ }
+ unsigned floatWidth = APFloat::getSizeInBits(attributeFloatSemantics);
+ if (isa<IntegerType>(constantElementType)) {
+ if (!constantElementType.isInteger(floatWidth)) {
+ return emitOpError() << "expected integer type of width " << floatWidth;
+ }
----------------
gysit wrote:
```suggestion
if (!constantElementType.isInteger(floatWidth))
return emitOpError() << "expected integer type of width " << floatWidth;
```
nit: for single line ifs we usually drop the braces
https://github.com/llvm/llvm-project/pull/148975
More information about the Mlir-commits
mailing list