Skip to content

Commit 1f93282

Browse files
authored
[MLIR][EmitC] arith-to-emitc: Fix lowering of fptoui (#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 ```
1 parent 8e66344 commit 1f93282

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ class FtoICastOpConversion : public OpConversionPattern<CastOp> {
674674
Type actualResultType = dstType;
675675
if (isa<arith::FPToUIOp>(castOp)) {
676676
actualResultType =
677-
rewriter.getIntegerType(operandType.getIntOrFloatBitWidth(),
677+
rewriter.getIntegerType(dstType.getIntOrFloatBitWidth(),
678678
/*isSigned=*/false);
679679
}
680680

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,10 @@ func.func @arith_float_to_int_cast_ops(%arg0: f32, %arg1: f64) {
587587
// CHECK: emitc.cast %[[CAST0]] : ui32 to i32
588588
%4 = arith.fptoui %arg0 : f32 to i32
589589

590+
// CHECK: %[[CAST0:.*]] = emitc.cast %arg0 : f32 to ui16
591+
// CHECK: emitc.cast %[[CAST0]] : ui16 to i16
592+
%5 = arith.fptoui %arg0 : f32 to i16
593+
590594
return
591595
}
592596

0 commit comments

Comments
 (0)