83 lines · plain
1// REQUIRES: system-linux2// TODO: Run only on Linux until we figure out how to build3// mlir_apfloat_wrappers in a platform-independent way.4 5// Case 1: All floating-point arithmetics is lowered through APFloat.6// RUN: mlir-opt %s --convert-arith-to-apfloat --convert-to-llvm | \7// RUN: mlir-runner -e entry --entry-point-result=void \8// RUN: --shared-libs=%mlir_c_runner_utils \9// RUN: --shared-libs=%mlir_apfloat_wrappers | FileCheck %s10 11// Case 2: Only unsupported arithmetics (f8E4M3FN) is lowered through APFloat.12// Arithmetics on f32 is lowered directly to LLVM.13// RUN: mlir-opt %s --convert-to-llvm --convert-arith-to-apfloat \14// RUN: --convert-to-llvm --reconcile-unrealized-casts | \15// RUN: mlir-runner -e entry --entry-point-result=void \16// RUN: --shared-libs=%mlir_c_runner_utils \17// RUN: --shared-libs=%mlir_apfloat_wrappers | FileCheck %s18 19// Put rhs into separate function so that it won't be constant-folded.20func.func @foo() -> (f8E4M3FN, f32) {21 %cst1 = arith.constant 2.2 : f8E4M3FN22 %cst2 = arith.constant 2.2 : f3223 return %cst1, %cst2 : f8E4M3FN, f3224}25 26func.func @entry() {27 %a1 = arith.constant 1.4 : f8E4M3FN28 %a2 = arith.constant 1.4 : f3229 %b1, %b2 = func.call @foo() : () -> (f8E4M3FN, f32)30 31 // CHECK: 2.232 vector.print %b2 : f3233 34 // CHECK-NEXT: 3.535 %c1 = arith.addf %a1, %b1 : f8E4M3FN // not supported by LLVM36 vector.print %c1 : f8E4M3FN37 38 // CHECK-NEXT: 3.639 %c2 = arith.addf %a2, %b2 : f32 // supported by LLVM40 vector.print %c2 : f3241 42 // CHECK-NEXT: 2.2543 %cvt = arith.truncf %b2 : f32 to f8E4M3FN44 vector.print %cvt : f8E4M3FN45 46 // CHECK-NEXT: -2.2547 %negated = arith.negf %cvt : f8E4M3FN48 vector.print %negated : f8E4M3FN49 50 // CHECK-NEXT: -2.2551 %min = arith.minimumf %cvt, %negated : f8E4M3FN52 vector.print %min : f8E4M3FN53 54 // CHECK-NEXT: 155 %cmp1 = arith.cmpf "olt", %cvt, %c1 : f8E4M3FN56 vector.print %cmp1 : i157 58 // CHECK-NEXT: 159 // Bit pattern: 01, interpreted as signed integer: 160 %cvt_int_signed = arith.fptosi %cvt : f8E4M3FN to i261 vector.print %cvt_int_signed : i262 63 // CHECK-NEXT: -264 // Bit pattern: 10, interpreted as signed integer: -265 %cvt_int_unsigned = arith.fptoui %cvt : f8E4M3FN to i266 vector.print %cvt_int_unsigned : i267 68 // CHECK-NEXT: -669 // Bit pattern: 1...11110111, interpreted as signed: -970 // Closest f4E2M1FN value: -6.071 %c9 = arith.constant -9 : i1672 %cvt_from_signed_int = arith.sitofp %c9 : i16 to f4E2M1FN73 vector.print %cvt_from_signed_int : f4E2M1FN74 75 // CHECK-NEXT: 676 // Bit pattern: 1...11110111, interpreted as unsigned: 6552777 // Closest f4E2M1FN value: 6.078 %cvt_from_unsigned_int = arith.uitofp %c9 : i16 to f4E2M1FN79 vector.print %cvt_from_unsigned_int : f4E2M1FN80 81 return82}83