File: constant_propagation_floats_x86.sil

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (97 lines) | stat: -rw-r--r-- 3,757 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// RUN: %target-sil-opt -enable-sil-verify-all %s -diagnostic-constant-propagation | %FileCheck %s
// RUN: %target-sil-opt -enable-sil-verify-all %s -performance-constant-propagation | %FileCheck %s
//
// REQUIRES: CPU=i386 || CPU=x86_64
//
// Tests that check constant-folding of conversions of floating point values
// to integer types for x86 architectures.

import Swift
import Builtin

sil @foldFPToUInt8UsingDouble : $@convention(thin) () -> UInt8 {
bb0:
%0 = float_literal $Builtin.FPIEEE80, 0x4006FF00000000000000 // 255
%1 = builtin "fptrunc_FPIEEE80_FPIEEE64"(%0 : $Builtin.FPIEEE80) : $Builtin.FPIEEE64
%2 = struct $Double (%1 : $Builtin.FPIEEE64)
%3 = struct_extract %2 : $Double, #Double._value
%4 = builtin "fptoui_FPIEEE64_Int8"(%3 : $Builtin.FPIEEE64) : $Builtin.Int8
%5 = struct $UInt8 (%4 : $Builtin.Int8)
return %5 : $UInt8

// CHECK-LABEL: sil @foldFPToUInt8UsingDouble
// CHECK-NOT: float_literal
// CHECK-NOT: builtin
// CHECK-NOT: struct $Double
// CHECK-NOT: struct_extract
// CHECK: [[LIT:%.*]] = integer_literal $Builtin.Int8, -1
// CHECK-NEXT: [[RES:%.*]] = struct $UInt8 ([[LIT]] : $Builtin.Int8)
// CHECK-NEXT: return [[RES]] : $UInt8
}

sil @foldFPToInt64 : $@convention(thin) () -> Builtin.Int64 {
bb0:
%0 = float_literal $Builtin.FPIEEE80,  0xC03DFFFFFFFFFFFFFFFE // -9223372036854775807
%1 = builtin "fptosi_FPIEEE80_Int64"(%0 : $Builtin.FPIEEE80) : $Builtin.Int64
return %1 : $Builtin.Int64

// CHECK-LABEL: sil @foldFPToInt64
// CHECK-NOT: float_literal
// CHECK-NOT: builtin
// CHECK: [[RES:%.*]] = integer_literal $Builtin.Int64, -9223372036854775807
// CHECK-NEXT: return [[RES]] : $Builtin.Int64
}

sil @foldFPToInt64Unsigned : $@convention(thin) () -> Builtin.Int64 {
bb0:
%0 = float_literal $Builtin.FPIEEE80, 0x403EFFFFFFFFFFFFFFFF // 18446744073709551615
%1 = builtin "fptoui_FPIEEE80_Int64"(%0 : $Builtin.FPIEEE80) : $Builtin.Int64
return %1 : $Builtin.Int64

// CHECK-LABEL: sil @foldFPToInt64Unsigned
// CHECK-NOT: float_literal
// CHECK-NOT: builtin
// CHECK: [[RES:%.*]] = integer_literal $Builtin.Int64, -1
// CHECK-NEXT: return [[RES]] : $Builtin.Int64
}

// The following tests check folding of FPTrunc instructions.

sil @foldFloat80ToFloat: $@convention(thin) () -> Builtin.FPIEEE32 {
bb0:
%0 = float_literal $Builtin.FPIEEE80, 0x407D96769950B50D88F4 // 9.99999999999999999993E+37
%1 = builtin "fptrunc_FPIEEE80_FPIEEE32"(%0 : $Builtin.FPIEEE80) : $Builtin.FPIEEE32
return %1 : $Builtin.FPIEEE32

// CHECK-LABEL: sil @foldFloat80ToFloat
// CHECK-NOT: float_literal $Builtin.FPIEEE80
// CHECK-NOT: builtin
// CHECK: [[RES:%.*]] = float_literal $Builtin.FPIEEE32, 0x7E967699 // 9.99999968E+37
// CHECK-NEXT: return [[RES]] : $Builtin.FPIEEE32
}

sil @foldFloat80ToDouble: $@convention(thin) () -> Builtin.FPIEEE64 {
bb0:
%0 = float_literal $Builtin.FPIEEE80, 0x43FE8E679C2F5E44FF8F // 9.99999999999999999966E+307
%1 = builtin "fptrunc_FPIEEE80_FPIEEE64"(%0 : $Builtin.FPIEEE80) : $Builtin.FPIEEE64
return %1 : $Builtin.FPIEEE64

// CHECK-LABEL: sil @foldFloat80ToDouble
// CHECK-NOT: float_literal $Builtin.FPIEEE80
// CHECK-NOT: builtin
// CHECK: [[RES:%.*]] = float_literal $Builtin.FPIEEE64, 0x7FE1CCF385EBC8A0 // 1.0E+308
// CHECK-NEXT: return [[RES]] : $Builtin.FPIEEE64
}

sil @foldFloat80ToFloat2: $@convention(thin) () -> Builtin.FPIEEE32 {
bb0:
%0 = float_literal $Builtin.FPIEEE80, 0x3F84881CEA14545C7575 // 9.9999999999999999995E-38
%1 = builtin "fptrunc_FPIEEE80_FPIEEE32"(%0 : $Builtin.FPIEEE80) : $Builtin.FPIEEE32
return %1 : $Builtin.FPIEEE32

// CHECK-LABEL: sil @foldFloat80ToFloat2
// CHECK-NOT: float_literal $Builtin.FPIEEE80
// CHECK-NOT: builtin
// CHECK: [[RES:%.*]] = float_literal $Builtin.FPIEEE32, 0x2081CEA // 9.99999991E-38
// CHECK-NEXT: return [[RES]] : $Builtin.FPIEEE32
}