Skip to content

Commit ddb67d2

Browse files
committed
Early exit with rounding mode
1 parent ce6db11 commit ddb67d2

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,12 @@ class FpCastOpConversion : public OpConversionPattern<CastOp> {
748748
if (!emitc::isSupportedFloatType(operandType))
749749
return rewriter.notifyMatchFailure(castOp,
750750
"unsupported cast source type");
751+
if (auto roundingModeOp =
752+
dyn_cast<arith::ArithRoundingModeInterface>(*castOp)) {
753+
// Only supporting default rounding mode as of now.
754+
if (roundingModeOp.getRoundingModeAttr())
755+
return rewriter.notifyMatchFailure(castOp, "unsupported rounding mode");
756+
}
751757

752758
Type dstType = this->getTypeConverter()->convertType(castOp.getType());
753759
if (!dstType)

mlir/test/Conversion/ArithToEmitC/arith-to-emitc-unsupported.mlir

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,3 +149,11 @@ func.func @arith_remui_vector(%arg0: vector<5xi32>, %arg1: vector<5xi32>) -> vec
149149
%divui = arith.remui %arg0, %arg1 : vector<5xi32>
150150
return %divui: vector<5xi32>
151151
}
152+
153+
// -----
154+
155+
func.func @arith_truncf(%arg0: f64) -> f32 {
156+
// expected-error @+1 {{failed to legalize operation 'arith.truncf'}}
157+
%truncd = arith.truncf %arg0 to_nearest_away : f64 to f32
158+
return %truncd : f32
159+
}

mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,4 +764,4 @@ func.func @arith_truncf(%arg0: f64) -> f16 {
764764
%truncd1 = arith.truncf %truncd0 : f32 to f16
765765

766766
return %truncd1 : f16
767-
}
767+
}

0 commit comments

Comments
 (0)