Skip to content

Commit eb5759f

Browse files
address comments
1 parent d9db8f9 commit eb5759f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

mlir/lib/Conversion/ArithToAPFloat/ArithToAPFloat.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,8 @@ struct FpToFpConversion final : OpRewritePattern<OpTy> {
159159
Location loc = op.getLoc();
160160
auto inFloatTy = cast<FloatType>(op.getOperand().getType());
161161
auto inIntWType = rewriter.getIntegerType(inFloatTy.getWidth());
162-
auto int64Type = rewriter.getI64Type();
163162
Value operandBits = arith::ExtUIOp::create(
164-
rewriter, loc, int64Type,
163+
rewriter, loc, i64Type,
165164
arith::BitcastOp::create(rewriter, loc, inIntWType, op.getOperand()));
166165

167166
// Call APFloat function.
@@ -194,6 +193,10 @@ struct FpToIntConversion final : OpRewritePattern<OpTy> {
194193

195194
LogicalResult matchAndRewrite(OpTy op,
196195
PatternRewriter &rewriter) const override {
196+
if (op.getType().getIntOrFloatBitWidth() > 64)
197+
return rewriter.notifyMatchFailure(
198+
op, "result type > 64 bits is not supported");
199+
197200
// Get APFloat function from runtime library.
198201
auto i1Type = IntegerType::get(symTable->getContext(), 1);
199202
auto i32Type = IntegerType::get(symTable->getContext(), 32);
@@ -209,9 +212,8 @@ struct FpToIntConversion final : OpRewritePattern<OpTy> {
209212
Location loc = op.getLoc();
210213
auto inFloatTy = cast<FloatType>(op.getOperand().getType());
211214
auto inIntWType = rewriter.getIntegerType(inFloatTy.getWidth());
212-
auto int64Type = rewriter.getI64Type();
213215
Value operandBits = arith::ExtUIOp::create(
214-
rewriter, loc, int64Type,
216+
rewriter, loc, i64Type,
215217
arith::BitcastOp::create(rewriter, loc, inIntWType, op.getOperand()));
216218

217219
// Call APFloat function.

mlir/lib/ExecutionEngine/APFloatWrappers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ MLIR_APFLOAT_WRAPPERS_EXPORT uint64_t _mlir_apfloat_convert_to_int(
113113
bool isExact;
114114
// TODO: Custom rounding modes are not supported yet.
115115
val.convertToInteger(result, llvm::RoundingMode::NearestTiesToEven, &isExact);
116+
// This function always returns uint64_t, regardless of the desired result
117+
// width. It does not matter whether we zero-extend or sign-extend the APSInt
118+
// to 64 bits because the generated IR in arith-to-apfloat will truncate the
119+
// result to the desired result width.
116120
return result.getZExtValue();
117121
}
118122
}

0 commit comments

Comments
 (0)