-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[mlir][arith] arith-to-apfloat: Bail on unsupported bitwidth
#170994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
matthias-springer
merged 1 commit into
main
from
users/matthias-springer/apf_unsupported_bitwidth
Dec 7, 2025
Merged
[mlir][arith] arith-to-apfloat: Bail on unsupported bitwidth
#170994
matthias-springer
merged 1 commit into
main
from
users/matthias-springer/apf_unsupported_bitwidth
Dec 7, 2025
+51
−8
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-mlir Author: Matthias Springer (matthias-springer) ChangesBitwidths greater than 64 are not supported by Full diff: https://github.com/llvm/llvm-project/pull/170994.diff 2 Files Affected:
diff --git a/mlir/lib/Conversion/ArithToAPFloat/ArithToAPFloat.cpp b/mlir/lib/Conversion/ArithToAPFloat/ArithToAPFloat.cpp
index 5c68236526b7d..4776ba0f49b94 100644
--- a/mlir/lib/Conversion/ArithToAPFloat/ArithToAPFloat.cpp
+++ b/mlir/lib/Conversion/ArithToAPFloat/ArithToAPFloat.cpp
@@ -102,6 +102,10 @@ struct BinaryArithOpToAPFloatConversion final : OpRewritePattern<OpTy> {
LogicalResult matchAndRewrite(OpTy op,
PatternRewriter &rewriter) const override {
+ if (op.getType().getIntOrFloatBitWidth() > 64)
+ return rewriter.notifyMatchFailure(op,
+ "bitwidth > 64 bits is not supported");
+
// Get APFloat function from runtime library.
FailureOr<FuncOp> fn =
lookupOrCreateBinaryFn(rewriter, symTable, APFloatName);
@@ -148,6 +152,11 @@ struct FpToFpConversion final : OpRewritePattern<OpTy> {
LogicalResult matchAndRewrite(OpTy op,
PatternRewriter &rewriter) const override {
+ if (op.getType().getIntOrFloatBitWidth() > 64 ||
+ op.getOperand().getType().getIntOrFloatBitWidth() > 64)
+ return rewriter.notifyMatchFailure(op,
+ "bitwidth > 64 bits is not supported");
+
// Get APFloat function from runtime library.
auto i32Type = IntegerType::get(symTable->getContext(), 32);
auto i64Type = IntegerType::get(symTable->getContext(), 64);
@@ -195,9 +204,10 @@ struct FpToIntConversion final : OpRewritePattern<OpTy> {
LogicalResult matchAndRewrite(OpTy op,
PatternRewriter &rewriter) const override {
- if (op.getType().getIntOrFloatBitWidth() > 64)
- return rewriter.notifyMatchFailure(
- op, "result type > 64 bits is not supported");
+ if (op.getType().getIntOrFloatBitWidth() > 64 ||
+ op.getOperand().getType().getIntOrFloatBitWidth() > 64)
+ return rewriter.notifyMatchFailure(op,
+ "bitwidth > 64 bits is not supported");
// Get APFloat function from runtime library.
auto i1Type = IntegerType::get(symTable->getContext(), 1);
@@ -252,11 +262,10 @@ struct IntToFpConversion final : OpRewritePattern<OpTy> {
LogicalResult matchAndRewrite(OpTy op,
PatternRewriter &rewriter) const override {
- Location loc = op.getLoc();
- if (op.getIn().getType().getIntOrFloatBitWidth() > 64) {
- return rewriter.notifyMatchFailure(
- loc, "integer bitwidth > 64 is not supported");
- }
+ if (op.getType().getIntOrFloatBitWidth() > 64 ||
+ op.getOperand().getType().getIntOrFloatBitWidth() > 64)
+ return rewriter.notifyMatchFailure(op,
+ "bitwidth > 64 bits is not supported");
// Get APFloat function from runtime library.
auto i1Type = IntegerType::get(symTable->getContext(), 1);
@@ -270,6 +279,7 @@ struct IntToFpConversion final : OpRewritePattern<OpTy> {
rewriter.setInsertionPoint(op);
// Cast operands to 64-bit integers.
+ Location loc = op.getLoc();
auto inIntTy = cast<IntegerType>(op.getOperand().getType());
Value operandBits = op.getOperand();
if (operandBits.getType().getIntOrFloatBitWidth() < 64) {
@@ -317,6 +327,10 @@ struct CmpFOpToAPFloatConversion final : OpRewritePattern<arith::CmpFOp> {
LogicalResult matchAndRewrite(arith::CmpFOp op,
PatternRewriter &rewriter) const override {
+ if (op.getLhs().getType().getIntOrFloatBitWidth() > 64)
+ return rewriter.notifyMatchFailure(op,
+ "bitwidth > 64 bits is not supported");
+
// Get APFloat function from runtime library.
auto i1Type = IntegerType::get(symTable->getContext(), 1);
auto i8Type = IntegerType::get(symTable->getContext(), 8);
@@ -456,6 +470,10 @@ struct NegFOpToAPFloatConversion final : OpRewritePattern<arith::NegFOp> {
LogicalResult matchAndRewrite(arith::NegFOp op,
PatternRewriter &rewriter) const override {
+ if (op.getOperand().getType().getIntOrFloatBitWidth() > 64)
+ return rewriter.notifyMatchFailure(op,
+ "bitwidth > 64 bits is not supported");
+
// Get APFloat function from runtime library.
auto i32Type = IntegerType::get(symTable->getContext(), 32);
auto i64Type = IntegerType::get(symTable->getContext(), 64);
diff --git a/mlir/test/Conversion/ArithToApfloat/arith-to-apfloat.mlir b/mlir/test/Conversion/ArithToApfloat/arith-to-apfloat.mlir
index 950d2cecefa95..ab05edebec71d 100644
--- a/mlir/test/Conversion/ArithToApfloat/arith-to-apfloat.mlir
+++ b/mlir/test/Conversion/ArithToApfloat/arith-to-apfloat.mlir
@@ -263,3 +263,28 @@ func.func @maxnumf(%arg0: f32, %arg1: f32) {
%0 = arith.maxnumf %arg0, %arg1 : f32
return
}
+
+// -----
+
+// CHECK-LABEL: func.func @unsupported_bitwidth
+// CHECK: arith.addf {{.*}} : f128
+// CHECK: arith.negf {{.*}} : f128
+// CHECK: arith.cmpf {{.*}} : f128
+// CHECK: arith.extf {{.*}} : f32 to f128
+// CHECK: arith.truncf {{.*}} : f128 to f32
+// CHECK: arith.fptosi {{.*}} : f128 to i32
+// CHECK: arith.fptosi {{.*}} : f32 to i92
+// CHECK: arith.sitofp {{.*}} : i1 to f128
+// CHECK: arith.sitofp {{.*}} : i92 to f32
+func.func @unsupported_bitwidth(%arg0: f128, %arg1: f128, %arg2: f32) {
+ %0 = arith.addf %arg0, %arg1 : f128
+ %1 = arith.negf %arg0 : f128
+ %2 = arith.cmpf "ult", %arg0, %arg1 : f128
+ %3 = arith.extf %arg2 : f32 to f128
+ %4 = arith.truncf %arg0 : f128 to f32
+ %5 = arith.fptosi %arg0 : f128 to i32
+ %6 = arith.fptosi %arg2 : f32 to i92
+ %7 = arith.sitofp %2 : i1 to f128
+ %8 = arith.sitofp %6 : i92 to f32
+ return
+}
|
makslevental
approved these changes
Dec 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bitwidths greater than 64 are not supported by
arith-to-apfloat.