|
| 1 | +// RUN: cir-opt %s | FileCheck %s |
| 2 | + |
| 3 | +// Adapted from mlir/test/IR/parser.mlir |
| 4 | + |
| 5 | +// CHECK-LABEL: @f32_special_values |
| 6 | +cir.func @f32_special_values() { |
| 7 | + // F32 signaling NaNs. |
| 8 | + // CHECK: cir.const(#cir.fp<0x7F800001> : !cir.float) : !cir.float |
| 9 | + %0 = cir.const(#cir.fp<0x7F800001> : !cir.float) : !cir.float |
| 10 | + // CHECK: cir.const(#cir.fp<0x7FBFFFFF> : !cir.float) : !cir.float |
| 11 | + %1 = cir.const(#cir.fp<0x7FBFFFFF> : !cir.float) : !cir.float |
| 12 | + |
| 13 | + // F32 quiet NaNs. |
| 14 | + // CHECK: cir.const(#cir.fp<0x7FC00000> : !cir.float) : !cir.float |
| 15 | + %2 = cir.const(#cir.fp<0x7FC00000> : !cir.float) : !cir.float |
| 16 | + // CHECK: cir.const(#cir.fp<0xFFFFFFFF> : !cir.float) : !cir.float |
| 17 | + %3 = cir.const(#cir.fp<0xFFFFFFFF> : !cir.float) : !cir.float |
| 18 | + |
| 19 | + // F32 positive infinity. |
| 20 | + // CHECK: cir.const(#cir.fp<0x7F800000> : !cir.float) : !cir.float |
| 21 | + %4 = cir.const(#cir.fp<0x7F800000> : !cir.float) : !cir.float |
| 22 | + // F32 negative infinity. |
| 23 | + // CHECK: cir.const(#cir.fp<0xFF800000> : !cir.float) : !cir.float |
| 24 | + %5 = cir.const(#cir.fp<0xFF800000> : !cir.float) : !cir.float |
| 25 | + |
| 26 | + cir.return |
| 27 | +} |
| 28 | + |
| 29 | +// CHECK-LABEL: @f64_special_values |
| 30 | +cir.func @f64_special_values() { |
| 31 | + // F64 signaling NaNs. |
| 32 | + // CHECK: cir.const(#cir.fp<0x7FF0000000000001> : !cir.double) : !cir.double |
| 33 | + %0 = cir.const(#cir.fp<0x7FF0000000000001> : !cir.double) : !cir.double |
| 34 | + // CHECK: cir.const(#cir.fp<0x7FF8000000000000> : !cir.double) : !cir.double |
| 35 | + %1 = cir.const(#cir.fp<0x7FF8000000000000> : !cir.double) : !cir.double |
| 36 | + |
| 37 | + // F64 quiet NaNs. |
| 38 | + // CHECK: cir.const(#cir.fp<0x7FF0000001000000> : !cir.double) : !cir.double |
| 39 | + %2 = cir.const(#cir.fp<0x7FF0000001000000> : !cir.double) : !cir.double |
| 40 | + // CHECK: cir.const(#cir.fp<0xFFF0000001000000> : !cir.double) : !cir.double |
| 41 | + %3 = cir.const(#cir.fp<0xFFF0000001000000> : !cir.double) : !cir.double |
| 42 | + |
| 43 | + // F64 positive infinity. |
| 44 | + // CHECK: cir.const(#cir.fp<0x7FF0000000000000> : !cir.double) : !cir.double |
| 45 | + %4 = cir.const(#cir.fp<0x7FF0000000000000> : !cir.double) : !cir.double |
| 46 | + // F64 negative infinity. |
| 47 | + // CHECK: cir.const(#cir.fp<0xFFF0000000000000> : !cir.double) : !cir.double |
| 48 | + %5 = cir.const(#cir.fp<0xFFF0000000000000> : !cir.double) : !cir.double |
| 49 | + |
| 50 | + // Check that values that can't be represented with the default format, use |
| 51 | + // hex instead. |
| 52 | + // CHECK: cir.const(#cir.fp<0xC1CDC00000000000> : !cir.double) : !cir.double |
| 53 | + %6 = cir.const(#cir.fp<0xC1CDC00000000000> : !cir.double) : !cir.double |
| 54 | + |
| 55 | + cir.return |
| 56 | +} |
| 57 | + |
| 58 | +// CHECK-LABEL: @f80_special_values |
| 59 | +cir.func @f80_special_values() { |
| 60 | + // F80 signaling NaNs. |
| 61 | + // CHECK: cir.const(#cir.fp<0x7FFFE000000000000001> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 62 | + %0 = cir.const(#cir.fp<0x7FFFE000000000000001> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 63 | + // CHECK: cir.const(#cir.fp<0x7FFFB000000000000011> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 64 | + %1 = cir.const(#cir.fp<0x7FFFB000000000000011> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 65 | + |
| 66 | + // F80 quiet NaNs. |
| 67 | + // CHECK: cir.const(#cir.fp<0x7FFFC000000000100000> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 68 | + %2 = cir.const(#cir.fp<0x7FFFC000000000100000> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 69 | + // CHECK: cir.const(#cir.fp<0x7FFFE000000001000000> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 70 | + %3 = cir.const(#cir.fp<0x7FFFE000000001000000> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 71 | + |
| 72 | + // F80 positive infinity. |
| 73 | + // CHECK: cir.const(#cir.fp<0x7FFF8000000000000000> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 74 | + %4 = cir.const(#cir.fp<0x7FFF8000000000000000> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 75 | + // F80 negative infinity. |
| 76 | + // CHECK: cir.const(#cir.fp<0xFFFF8000000000000000> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 77 | + %5 = cir.const(#cir.fp<0xFFFF8000000000000000> : !cir.long_double<!cir.f80>) : !cir.long_double<!cir.f80> |
| 78 | + |
| 79 | + cir.return |
| 80 | +} |
| 81 | + |
| 82 | +// We want to print floats in exponential notation with 6 significant digits, |
| 83 | +// but it may lead to precision loss when parsing back, in which case we print |
| 84 | +// the decimal form instead. |
| 85 | +// CHECK-LABEL: @f32_potential_precision_loss() |
| 86 | +cir.func @f32_potential_precision_loss() { |
| 87 | + // CHECK: cir.const(#cir.fp<1.23697901> : !cir.float) : !cir.float |
| 88 | + %0 = cir.const(#cir.fp<1.23697901> : !cir.float) : !cir.float |
| 89 | + cir.return |
| 90 | +} |
0 commit comments