[Mlir-commits] [mlir] [MLIR][EmitC] arith-to-emitc: Fix lowering of fptoui (PR #118504)
Matthias Gehre
llvmlistbot at llvm.org
Tue Dec 3 07:51:17 PST 2024
https://github.com/mgehre-amd created https://github.com/llvm/llvm-project/pull/118504
`arith.fptoui %arg0 : f32 to i16` was lowered to
```
%0 = emitc.cast %arg0 : f32 to ui32
emitc.cast %0 : ui32 to i16
```
and is now lowered to
```
%0 = emitc.cast %arg0 : f32 to ui16
emitc.cast %0 : ui16 to i16
```
>From e71e5c23e003cd435ad1457bb5326201f6a7d7ba Mon Sep 17 00:00:00 2001
From: Matthias Gehre <matthias.gehre at amd.com>
Date: Fri, 29 Nov 2024 16:24:22 +0100
Subject: [PATCH] arith-to-emitc: Fix lowering of fptoui
`arith.fptoui %arg0 : f32 to i16` was lowered to
```
%0 = emitc.cast %arg0 : f32 to ui32
emitc.cast %0 : ui32 to i16
```
and is now lowered to
```
%0 = emitc.cast %arg0 : f32 to ui16
emitc.cast %0 : ui16 to i16
```
---
mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp | 2 +-
mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
index 50384d9a08e5d9..ccbc1669b7a92a 100644
--- a/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
+++ b/mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
@@ -674,7 +674,7 @@ class FtoICastOpConversion : public OpConversionPattern<CastOp> {
Type actualResultType = dstType;
if (isa<arith::FPToUIOp>(castOp)) {
actualResultType =
- rewriter.getIntegerType(operandType.getIntOrFloatBitWidth(),
+ rewriter.getIntegerType(dstType.getIntOrFloatBitWidth(),
/*isSigned=*/false);
}
diff --git a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
index afd1198ede0f76..1728c3a2557e07 100644
--- a/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
+++ b/mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
@@ -587,6 +587,10 @@ func.func @arith_float_to_int_cast_ops(%arg0: f32, %arg1: f64) {
// CHECK: emitc.cast %[[CAST0]] : ui32 to i32
%4 = arith.fptoui %arg0 : f32 to i32
+ // CHECK: %[[CAST0:.*]] = emitc.cast %arg0 : f32 to ui16
+ // CHECK: emitc.cast %[[CAST0]] : ui16 to i16
+ %5 = arith.fptoui %arg0 : f32 to i16
+
return
}
More information about the Mlir-commits
mailing list