@@ -3031,6 +3031,143 @@ func.func @mulsi_extended_i0() -> (i0, i0) {
3031
3031
return %mulsi_extended#0 , %mulsi_extended#1 : i0 , i0
3032
3032
}
3033
3033
3034
+ // CHECK-LABEL: @sequences_fastmath_contract
3035
+ // CHECK-SAME: ([[ARG0:%.+]]: bf16)
3036
+ // CHECK: [[EXTF:%.+]] = arith.extf [[ARG0]]
3037
+ // CHECK: [[ABSF:%.+]] = math.absf [[EXTF]]
3038
+ // CHECK: [[SIN:%.+]] = math.sin [[ABSF]]
3039
+ // CHECK: [[TRUNCF:%.+]] = arith.truncf [[SIN]]
3040
+ // CHECK: return [[TRUNCF]] : bf16
3041
+ func.func @sequences_fastmath_contract (%arg0: bf16 ) -> bf16 {
3042
+ %0 = arith.extf %arg0 fastmath <contract > : bf16 to f32
3043
+ %1 = math.absf %0 : f32
3044
+ %2 = arith.truncf %1 fastmath <contract > : f32 to bf16
3045
+ %3 = arith.extf %2 fastmath <contract > : bf16 to f32
3046
+ %4 = math.sin %3 : f32
3047
+ %5 = arith.truncf %4 fastmath <contract > : f32 to bf16
3048
+ return %5 : bf16
3049
+ }
3050
+
3051
+ // CHECK-LABEL: @sequences_no_fastmath
3052
+ // CHECK-SAME: ([[ARG0:%.+]]: bf16)
3053
+ // CHECK: [[EXTF:%.+]] = arith.extf [[ARG0]]
3054
+ // CHECK: [[ABSF:%.+]] = math.absf [[EXTF]]
3055
+ // CHECK: [[TRUNCF1:%.+]] = arith.truncf [[ABSF]]
3056
+ // CHECK: [[EXTF1:%.+]] = arith.extf [[TRUNCF1]]
3057
+ // CHECK: [[SIN:%.+]] = math.sin [[EXTF1]]
3058
+ // CHECK: [[TRUNCF:%.+]] = arith.truncf [[SIN]]
3059
+ // CHECK: return [[TRUNCF]] : bf16
3060
+ func.func @sequences_no_fastmath (%arg0: bf16 ) -> bf16 {
3061
+ %0 = arith.extf %arg0 : bf16 to f32
3062
+ %1 = math.absf %0 : f32
3063
+ %2 = arith.truncf %1 : f32 to bf16
3064
+ %3 = arith.extf %2 : bf16 to f32
3065
+ %4 = math.sin %3 : f32
3066
+ %5 = arith.truncf %4 : f32 to bf16
3067
+ return %5 : bf16
3068
+ }
3069
+
3070
+ // CHECK-LABEL: @eliminate_cast_to_f16
3071
+ // CHECK: return [[arg0:%.+]] : f32
3072
+ func.func @eliminate_cast_to_f16 (%arg0: f32 ) -> f32 {
3073
+ %0 = arith.truncf %arg0 fastmath <contract > : f32 to f16
3074
+ %1 = arith.extf %0 fastmath <contract > : f16 to f32
3075
+ return %1 : f32
3076
+ }
3077
+
3078
+ // CHECK-LABEL: @eliminate_cast_to_bf16
3079
+ // CHECK: return [[arg0:%.+]] : f32
3080
+ func.func @eliminate_cast_to_bf16 (%arg0: f32 ) -> f32 {
3081
+ %0 = arith.truncf %arg0 fastmath <contract > : f32 to bf16
3082
+ %1 = arith.extf %0 fastmath <contract > : bf16 to f32
3083
+ return %1 : f32
3084
+ }
3085
+
3086
+ // CHECK-LABEL: @bf16_sin_vector
3087
+ // CHECK-SAME: ([[ARG0:%.+]]: vector<32x32x32xbf16>)
3088
+ // CHECK: [[EXTF:%.+]] = arith.extf [[ARG0]]
3089
+ // CHECK: [[ABSF:%.+]] = math.absf [[EXTF]]
3090
+ // CHECK: [[SIN:%.+]] = math.sin [[ABSF]]
3091
+ // CHECK: [[TRUNCF:%.+]] = arith.truncf [[SIN]]
3092
+ // CHECK: return [[TRUNCF]] : vector<32x32x32xbf16>
3093
+ func.func @bf16_sin_vector (%arg0: vector <32 x32 x32 xbf16 >) -> vector <32 x32 x32 xbf16 > {
3094
+ %0 = arith.extf %arg0 fastmath <contract > : vector <32 x32 x32 xbf16 > to vector <32 x32 x32 xf32 >
3095
+ %1 = math.absf %0 : vector <32 x32 x32 xf32 >
3096
+ %2 = arith.truncf %1 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xbf16 >
3097
+ %3 = arith.extf %2 fastmath <contract > : vector <32 x32 x32 xbf16 > to vector <32 x32 x32 xf32 >
3098
+ %4 = math.sin %3 : vector <32 x32 x32 xf32 >
3099
+ %5 = arith.truncf %4 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xbf16 >
3100
+ return %5 : vector <32 x32 x32 xbf16 >
3101
+ }
3102
+
3103
+ // CHECK-LABEL: @f16_sin_vector
3104
+ // CHECK-SAME: ([[ARG0:%.+]]: vector<32x32x32xf16>)
3105
+ // CHECK: [[EXTF:%.+]] = arith.extf [[ARG0]]
3106
+ // CHECK: [[ABSF:%.+]] = math.absf [[EXTF]]
3107
+ // CHECK: [[SIN:%.+]] = math.sin [[ABSF]]
3108
+ // CHECK: [[TRUNCF:%.+]] = arith.truncf [[SIN]]
3109
+ // CHECK: return [[TRUNCF]] : vector<32x32x32xf16>
3110
+ func.func @f16_sin_vector (%arg0: vector <32 x32 x32 xf16 >) -> vector <32 x32 x32 xf16 > {
3111
+ %0 = arith.extf %arg0 fastmath <contract > : vector <32 x32 x32 xf16 > to vector <32 x32 x32 xf32 >
3112
+ %1 = math.absf %0 : vector <32 x32 x32 xf32 >
3113
+ %2 = arith.truncf %1 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xf16 >
3114
+ %3 = arith.extf %2 fastmath <contract > : vector <32 x32 x32 xf16 > to vector <32 x32 x32 xf32 >
3115
+ %4 = math.sin %3 : vector <32 x32 x32 xf32 >
3116
+ %5 = arith.truncf %4 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xf16 >
3117
+ return %5 : vector <32 x32 x32 xf16 >
3118
+ }
3119
+
3120
+ // CHECK-LABEL: @bf16_branch_vector
3121
+ // CHECK-SAME: ([[ARG0:%.+]]: vector<32x32x32xbf16>)
3122
+ // CHECK: [[EXTF:%.+]] = arith.extf [[ARG0]]
3123
+ // CHECK: [[ABSF:%.+]] = math.absf [[EXTF]]
3124
+ // CHECK-DAG: [[SIN:%.+]] = math.sin [[ABSF]]
3125
+ // CHECK-DAG: [[COS:%.+]] = math.cos [[ABSF]]
3126
+ // CHECK: [[ADDF:%.+]] = arith.addf [[SIN]], [[COS]]
3127
+ // CHECK: [[TRUNCF:%.+]] = arith.truncf [[ADDF]]
3128
+ // CHECK: return [[TRUNCF]] : vector<32x32x32xbf16>
3129
+ func.func @bf16_branch_vector (%arg0: vector <32 x32 x32 xbf16 >) -> vector <32 x32 x32 xbf16 > {
3130
+ %0 = arith.extf %arg0 fastmath <contract > : vector <32 x32 x32 xbf16 > to vector <32 x32 x32 xf32 >
3131
+ %1 = math.absf %0 : vector <32 x32 x32 xf32 >
3132
+ %2 = arith.truncf %1 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xbf16 >
3133
+ %3 = arith.extf %2 fastmath <contract > : vector <32 x32 x32 xbf16 > to vector <32 x32 x32 xf32 >
3134
+ %4 = math.sin %3 : vector <32 x32 x32 xf32 >
3135
+ %5 = arith.truncf %4 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xbf16 >
3136
+ %6 = arith.extf %5 fastmath <contract > : vector <32 x32 x32 xbf16 > to vector <32 x32 x32 xf32 >
3137
+ %7 = math.cos %3 : vector <32 x32 x32 xf32 >
3138
+ %8 = arith.truncf %7 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xbf16 >
3139
+ %9 = arith.extf %8 fastmath <contract > : vector <32 x32 x32 xbf16 > to vector <32 x32 x32 xf32 >
3140
+ %10 = arith.addf %6 , %9 : vector <32 x32 x32 xf32 >
3141
+ %11 = arith.truncf %10 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xbf16 >
3142
+ return %11 : vector <32 x32 x32 xbf16 >
3143
+ }
3144
+
3145
+ // CHECK-LABEL: @bf16_fma
3146
+ // CHECK-SAME: ([[ARG0:%.+]]: vector<32x32x32xbf16>, [[ARG1:%.+]]: vector<32x32x32xbf16>, [[ARG2:%.+]]: vector<32x32x32xbf16>)
3147
+ // CHECK: [[EXTF0:%.+]] = arith.extf [[ARG0]]
3148
+ // CHECK: [[ABSF:%.+]] = math.absf [[EXTF0]]
3149
+ // CHECK-DAG: [[SIN:%.+]] = math.sin [[ABSF]]
3150
+ // CHECK: [[TRUNCF0:%.+]] = arith.truncf [[SIN]]
3151
+ // CHECK-DAG: [[FMA:%.+]] = math.fma [[TRUNCF0]], [[ARG1]], [[ARG2]]
3152
+ // CHECK: [[EXTF1:%.+]] = arith.extf [[FMA]]
3153
+ // CHECK: [[ADDF:%.+]] = arith.addf [[EXTF1]], [[SIN]]
3154
+ // CHECK: [[TRUNCF1:%.+]] = arith.truncf [[ADDF]]
3155
+ // CHECK: return [[TRUNCF1]] : vector<32x32x32xbf16>
3156
+ func.func @bf16_fma (%arg0: vector <32 x32 x32 xbf16 >, %arg1: vector <32 x32 x32 xbf16 >, %arg2: vector <32 x32 x32 xbf16 >) -> vector <32 x32 x32 xbf16 > {
3157
+ %0 = arith.extf %arg0 fastmath <contract > : vector <32 x32 x32 xbf16 > to vector <32 x32 x32 xf32 >
3158
+ %1 = math.absf %0 : vector <32 x32 x32 xf32 >
3159
+ %2 = arith.truncf %1 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xbf16 >
3160
+ %3 = arith.extf %2 fastmath <contract > : vector <32 x32 x32 xbf16 > to vector <32 x32 x32 xf32 >
3161
+ %4 = math.sin %3 : vector <32 x32 x32 xf32 >
3162
+ %5 = arith.truncf %4 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xbf16 >
3163
+ %6 = arith.extf %5 fastmath <contract > : vector <32 x32 x32 xbf16 > to vector <32 x32 x32 xf32 >
3164
+ %7 = math.fma %5 , %arg1 , %arg2 : vector <32 x32 x32 xbf16 >
3165
+ %8 = arith.extf %7 fastmath <contract > : vector <32 x32 x32 xbf16 > to vector <32 x32 x32 xf32 >
3166
+ %9 = arith.addf %8 , %6 : vector <32 x32 x32 xf32 >
3167
+ %10 = arith.truncf %9 fastmath <contract > : vector <32 x32 x32 xf32 > to vector <32 x32 x32 xbf16 >
3168
+ return %10 : vector <32 x32 x32 xbf16 >
3169
+ }
3170
+
3034
3171
{-#
3035
3172
dialect_resources : {
3036
3173
builtin : {
0 commit comments