1- // RUN: mlir-opt %s --convert-arith-to-apfloat -split-input-file | FileCheck %s
1+ // RUN: mlir-opt %s --convert-arith-to-apfloat -split-input-file -verify-diagnostics | FileCheck %s
22
3- // CHECK-LABEL: func.func private @_mlir_apfloat_add (i32, i64, i64) -> i64
3+ // CHECK-LABEL: func.func private @__mlir_apfloat_add (i32, i64, i64) -> i64
44
55// CHECK-LABEL: func.func @foo() -> f8E4M3FN {
66// CHECK: %[[CONSTANT_0:.*]] = arith.constant 2.250000e+00 : f8E4M3FN
77// CHECK: return %[[CONSTANT_0]] : f8E4M3FN
88// CHECK: }
99
10+ // CHECK-LABEL: func.func @bar() -> f6E3M2FN {
11+ // CHECK: %[[CONSTANT_0:.*]] = arith.constant 3.000000e+00 : f6E3M2FN
12+ // CHECK: return %[[CONSTANT_0]] : f6E3M2FN
13+ // CHECK: }
14+
15+ // Illustrate that both f8E4M3FN and f6E3M2FN calling the same __mlir_apfloat_add is fine
16+ // because each gets its own semantics enum and gets bitcast/extui/trunci to its own width.
1017// CHECK-LABEL: func.func @full_example() {
11- // CHECK: %[[cst:.*]] = arith.constant 1.375000e+00 : f8E4M3FN
12- // CHECK: %[[rhs:.*]] = call @foo() : () -> f8E4M3FN
13- // CHECK: %[[lhs_casted:.*]] = arith.bitcast %[[cst]] : f8E4M3FN to i8
14- // CHECK: %[[lhs_ext:.*]] = arith.extui %[[lhs_casted]] : i8 to i64
15- // CHECK: %[[rhs_casted:.*]] = arith.bitcast %[[rhs]] : f8E4M3FN to i8
16- // CHECK: %[[rhs_ext:.*]] = arith.extui %[[rhs_casted]] : i8 to i64
17- // CHECK: %[[c10_i32:.*]] = arith.constant 10 : i32
18- // CHECK: %[[res:.*]] = call @_mlir_apfloat_add(%[[c10_i32]], %[[lhs_ext]], %[[rhs_ext]]) : (i32, i64, i64) -> i64
19- // CHECK: %[[res_trunc:.*]] = arith.trunci %[[res]] : i64 to i8
20- // CHECK: %[[res_casted:.*]] = arith.bitcast %[[res_trunc]] : i8 to f8E4M3FN
21- // CHECK: vector.print %[[res_casted]] : f8E4M3FN
18+ // CHECK: %[[CONSTANT_0:.*]] = arith.constant 1.375000e+00 : f8E4M3FN
19+ // CHECK: %[[VAL_0:.*]] = call @foo() : () -> f8E4M3FN
20+ // CHECK: %[[BITCAST_0:.*]] = arith.bitcast %[[CONSTANT_0]] : f8E4M3FN to i8
21+ // CHECK: %[[EXTUI_0:.*]] = arith.extui %[[BITCAST_0]] : i8 to i64
22+ // CHECK: %[[BITCAST_1:.*]] = arith.bitcast %[[VAL_0]] : f8E4M3FN to i8
23+ // CHECK: %[[EXTUI_1:.*]] = arith.extui %[[BITCAST_1]] : i8 to i64
24+ // // fltSemantics semantics for f8E4M3FN
25+ // CHECK: %[[CONSTANT_1:.*]] = arith.constant 10 : i32
26+ // CHECK: %[[VAL_1:.*]] = call @__mlir_apfloat_add(%[[CONSTANT_1]], %[[EXTUI_0]], %[[EXTUI_1]]) : (i32, i64, i64) -> i64
27+ // CHECK: %[[TRUNCI_0:.*]] = arith.trunci %[[VAL_1]] : i64 to i8
28+ // CHECK: %[[BITCAST_2:.*]] = arith.bitcast %[[TRUNCI_0]] : i8 to f8E4M3FN
29+ // CHECK: vector.print %[[BITCAST_2]] : f8E4M3FN
30+
31+ // CHECK: %[[CONSTANT_2:.*]] = arith.constant 2.500000e+00 : f6E3M2FN
32+ // CHECK: %[[VAL_2:.*]] = call @bar() : () -> f6E3M2FN
33+ // CHECK: %[[BITCAST_3:.*]] = arith.bitcast %[[CONSTANT_2]] : f6E3M2FN to i6
34+ // CHECK: %[[EXTUI_2:.*]] = arith.extui %[[BITCAST_3]] : i6 to i64
35+ // CHECK: %[[BITCAST_4:.*]] = arith.bitcast %[[VAL_2]] : f6E3M2FN to i6
36+ // CHECK: %[[EXTUI_3:.*]] = arith.extui %[[BITCAST_4]] : i6 to i64
37+ // // fltSemantics semantics for f6E3M2FN
38+ // CHECK: %[[CONSTANT_3:.*]] = arith.constant 16 : i32
39+ // CHECK: %[[VAL_3:.*]] = call @__mlir_apfloat_add(%[[CONSTANT_3]], %[[EXTUI_2]], %[[EXTUI_3]]) : (i32, i64, i64) -> i64
40+ // CHECK: %[[TRUNCI_1:.*]] = arith.trunci %[[VAL_3]] : i64 to i6
41+ // CHECK: %[[BITCAST_5:.*]] = arith.bitcast %[[TRUNCI_1]] : i6 to f6E3M2FN
42+ // CHECK: vector.print %[[BITCAST_5]] : f6E3M2FN
2243// CHECK: return
2344// CHECK: }
2445
@@ -28,60 +49,79 @@ func.func @foo() -> f8E4M3FN {
2849 return %cst : f8E4M3FN
2950}
3051
52+ func.func @bar () -> f6E3M2FN {
53+ %cst = arith.constant 3.2 : f6E3M2FN
54+ return %cst : f6E3M2FN
55+ }
56+
3157func.func @full_example () {
3258 %a = arith.constant 1.4 : f8E4M3FN
3359 %b = func.call @foo () : () -> (f8E4M3FN )
3460 %c = arith.addf %a , %b : f8E4M3FN
35-
3661 vector.print %c : f8E4M3FN
62+
63+ %d = arith.constant 2.4 : f6E3M2FN
64+ %e = func.call @bar () : () -> (f6E3M2FN )
65+ %f = arith.addf %d , %e : f6E3M2FN
66+ vector.print %f : f6E3M2FN
3767 return
3868}
3969
4070// -----
4171
42- // CHECK: func.func private @_mlir_apfloat_add (i32, i64, i64) -> i64
72+ // CHECK: func.func private @__mlir_apfloat_add (i32, i64, i64) -> i64
4373// CHECK: %[[sem:.*]] = arith.constant 18 : i32
44- // CHECK: call @_mlir_apfloat_add(%[[sem]], %{{.*}}, %{{.*}}) : (i32, i64, i64) -> i64
74+ // CHECK: call @__mlir_apfloat_add(%[[sem]], %{{.*}}, %{{.*}}) : (i32, i64, i64) -> i64
75+ func.func @addf (%arg0: f4E2M1FN , %arg1: f4E2M1FN ) {
76+ %0 = arith.addf %arg0 , %arg1 : f4E2M1FN
77+ return
78+ }
79+
80+ // -----
81+
82+ // Test decl collision (different type)
83+ // expected-error@+1{{matched function '__mlir_apfloat_add' but with different type: '(i32, i32, f32) -> index' (expected '(i32, i64, i64) -> i64')}}
84+ func.func private @__mlir_apfloat_add (i32 , i32 , f32 ) -> index
4585func.func @addf (%arg0: f4E2M1FN , %arg1: f4E2M1FN ) {
4686 %0 = arith.addf %arg0 , %arg1 : f4E2M1FN
4787 return
4888}
4989
5090// -----
5191
52- // CHECK: func.func private @_mlir_apfloat_subtract (i32, i64, i64) -> i64
92+ // CHECK: func.func private @__mlir_apfloat_subtract (i32, i64, i64) -> i64
5393// CHECK: %[[sem:.*]] = arith.constant 18 : i32
54- // CHECK: call @_mlir_apfloat_subtract (%[[sem]], %{{.*}}, %{{.*}}) : (i32, i64, i64) -> i64
94+ // CHECK: call @__mlir_apfloat_subtract (%[[sem]], %{{.*}}, %{{.*}}) : (i32, i64, i64) -> i64
5595func.func @subf (%arg0: f4E2M1FN , %arg1: f4E2M1FN ) {
5696 %0 = arith.subf %arg0 , %arg1 : f4E2M1FN
5797 return
5898}
5999
60100// -----
61101
62- // CHECK: func.func private @_mlir_apfloat_multiply (i32, i64, i64) -> i64
102+ // CHECK: func.func private @__mlir_apfloat_multiply (i32, i64, i64) -> i64
63103// CHECK: %[[sem:.*]] = arith.constant 18 : i32
64- // CHECK: call @_mlir_apfloat_multiply (%[[sem]], %{{.*}}, %{{.*}}) : (i32, i64, i64) -> i64
104+ // CHECK: call @__mlir_apfloat_multiply (%[[sem]], %{{.*}}, %{{.*}}) : (i32, i64, i64) -> i64
65105func.func @subf (%arg0: f4E2M1FN , %arg1: f4E2M1FN ) {
66106 %0 = arith.mulf %arg0 , %arg1 : f4E2M1FN
67107 return
68108}
69109
70110// -----
71111
72- // CHECK: func.func private @_mlir_apfloat_divide (i32, i64, i64) -> i64
112+ // CHECK: func.func private @__mlir_apfloat_divide (i32, i64, i64) -> i64
73113// CHECK: %[[sem:.*]] = arith.constant 18 : i32
74- // CHECK: call @_mlir_apfloat_divide (%[[sem]], %{{.*}}, %{{.*}}) : (i32, i64, i64) -> i64
114+ // CHECK: call @__mlir_apfloat_divide (%[[sem]], %{{.*}}, %{{.*}}) : (i32, i64, i64) -> i64
75115func.func @subf (%arg0: f4E2M1FN , %arg1: f4E2M1FN ) {
76116 %0 = arith.divf %arg0 , %arg1 : f4E2M1FN
77117 return
78118}
79119
80120// -----
81121
82- // CHECK: func.func private @_mlir_apfloat_remainder (i32, i64, i64) -> i64
122+ // CHECK: func.func private @__mlir_apfloat_remainder (i32, i64, i64) -> i64
83123// CHECK: %[[sem:.*]] = arith.constant 18 : i32
84- // CHECK: call @_mlir_apfloat_remainder (%[[sem]], %{{.*}}, %{{.*}}) : (i32, i64, i64) -> i64
124+ // CHECK: call @__mlir_apfloat_remainder (%[[sem]], %{{.*}}, %{{.*}}) : (i32, i64, i64) -> i64
85125func.func @remf (%arg0: f4E2M1FN , %arg1: f4E2M1FN ) {
86126 %0 = arith.remf %arg0 , %arg1 : f4E2M1FN
87127 return
0 commit comments