[Mlir-commits] [mlir] [MLIR][Arith] add fastMathAttr on arith::extf and arith::truncf (PR #93443)
donald chen
llvmlistbot at llvm.org
Tue Jun 11 23:21:44 PDT 2024
================
@@ -3031,6 +3031,143 @@ func.func @mulsi_extended_i0() -> (i0, i0) {
return %mulsi_extended#0, %mulsi_extended#1 : i0, i0
}
+// CHECK-LABEL: @sequences_fastmath_contract
+// CHECK-SAME: ([[ARG0:%.+]]: bf16)
+// CHECK: [[EXTF:%.+]] = arith.extf [[ARG0]]
+// CHECK: [[ABSF:%.+]] = math.absf [[EXTF]]
+// CHECK: [[SIN:%.+]] = math.sin [[ABSF]]
+// CHECK: [[TRUNCF:%.+]] = arith.truncf [[SIN]]
+// CHECK: return [[TRUNCF]] : bf16
+func.func @sequences_fastmath_contract(%arg0: bf16) -> bf16 {
+ %0 = arith.extf %arg0 fastmath<contract> : bf16 to f32
+ %1 = math.absf %0 : f32
+ %2 = arith.truncf %1 fastmath<contract> : f32 to bf16
+ %3 = arith.extf %2 fastmath<contract> : bf16 to f32
+ %4 = math.sin %3 : f32
+ %5 = arith.truncf %4 fastmath<contract> : f32 to bf16
+ return %5 : bf16
+}
+
+// CHECK-LABEL: @sequences_no_fastmath
+// CHECK-SAME: ([[ARG0:%.+]]: bf16)
+// CHECK: [[EXTF:%.+]] = arith.extf [[ARG0]]
+// CHECK: [[ABSF:%.+]] = math.absf [[EXTF]]
+// CHECK: [[TRUNCF1:%.+]] = arith.truncf [[ABSF]]
+// CHECK: [[EXTF1:%.+]] = arith.extf [[TRUNCF1]]
+// CHECK: [[SIN:%.+]] = math.sin [[EXTF1]]
+// CHECK: [[TRUNCF:%.+]] = arith.truncf [[SIN]]
+// CHECK: return [[TRUNCF]] : bf16
+func.func @sequences_no_fastmath(%arg0: bf16) -> bf16 {
+ %0 = arith.extf %arg0 : bf16 to f32
+ %1 = math.absf %0 : f32
+ %2 = arith.truncf %1 : f32 to bf16
+ %3 = arith.extf %2 : bf16 to f32
+ %4 = math.sin %3 : f32
+ %5 = arith.truncf %4 : f32 to bf16
+ return %5 : bf16
+}
+
+// CHECK-LABEL: @eliminatecastoncastf16
+// CHECK: return [[arg0:%.+]] : f32
+func.func @eliminatecastoncastf16(%arg0: f32) -> f32 {
+ %0 = arith.truncf %arg0 fastmath<contract> : f32 to f16
+ %1 = arith.extf %0 fastmath<contract> : f16 to f32
+ return %1 : f32
+}
+
+// CHECK-LABEL: @eliminatecastoncastbf16
+// CHECK: return [[arg0:%.+]] : f32
+func.func @eliminatecastoncastbf16(%arg0: f32) -> f32 {
----------------
cxy-1993 wrote:
Recommend using _ to separate words in function name
https://github.com/llvm/llvm-project/pull/93443
More information about the Mlir-commits
mailing list