|
1 | 1 | // RUN: %target-build-swift -target arm64-apple-ios8.0 -target-cpu cyclone \
|
2 |
| -// RUN: -O -S %s -parse-as-library -parse-stdlib | \ |
| 2 | +// RUN: -O -S %s -parse-as-library -parse-stdlib -module-name Swift | \ |
3 | 3 | // RUN: %FileCheck --check-prefix=TBI %s
|
4 | 4 |
|
5 | 5 | // RUN: %target-build-swift -target arm64-apple-ios7.0 -target-cpu cyclone \
|
6 |
| -// RUN: -O -S %s -parse-as-library -parse-stdlib | \ |
| 6 | +// RUN: -O -S %s -parse-as-library -parse-stdlib -module-name Swift | \ |
7 | 7 | // RUN: %FileCheck --check-prefix=NO_TBI %s
|
8 | 8 |
|
9 |
| -// REQUIRES: CPU=arm64, OS=ios |
| 9 | +// REQUIRES: CPU=arm64 |
| 10 | +// REQUIRES: OS=ios |
10 | 11 |
|
11 | 12 | // Verify that TBI is on by default in Swift on targets that support it. For our
|
12 | 13 | // purposes this means iOS8.0 or later.
|
13 | 14 |
|
14 |
| -import Swift |
| 15 | +public enum Never {} |
15 | 16 |
|
16 |
| -func f(i: Int) -> Int8 { |
17 |
| - let j = i & 0xff_ffff_ffff_ffff |
18 |
| -// TBI-NOT: and |
19 |
| -// NO_TBI: and |
20 |
| - guard let p = UnsafeMutablePointer<Int8>(bitPattern: j) else { |
| 17 | +// NO_TBI-LABEL: .globl __T0s7testTBIBi64_Bi64_1i_tF |
| 18 | +// NO_TBI: __T0s7testTBIBi64_Bi64_1i_tF |
| 19 | +// NO_TBI-NEXT: and |
| 20 | +// NO_TBI-NEXT: ldr |
| 21 | +// NO_TBI-NEXT: ret |
| 22 | + |
| 23 | +// TBI-LABEL: .globl __T0s7testTBIBi64_Bi64_1i_tF |
| 24 | +// TBI: __T0s7testTBIBi64_Bi64_1i_tF: |
| 25 | +// TBI-NEXT: ldr |
| 26 | +// TBI-NEXT: ret |
| 27 | + |
| 28 | +func testTBI(i: Builtin.Int64) -> Builtin.Int64 { |
| 29 | + |
| 30 | + // Some constants so we do not depend on the stdlib. |
| 31 | + let zero: Builtin.Int64 = Builtin.xor_Int64(i, i) |
| 32 | + let smallOne: Builtin.Int1 = Builtin.cmp_eq_Int64(zero, zero) |
| 33 | + let one: Builtin.Int64 = Builtin.zext_Int1_Int64(smallOne) |
| 34 | + let two: Builtin.Int64 = Builtin.add_Int64(one, one) |
| 35 | + let four: Builtin.Int64 = Builtin.add_Int64(two, two) |
| 36 | + let eight: Builtin.Int64 = Builtin.add_Int64(four, four) |
| 37 | + |
| 38 | + // 0xffff_ffff_ffff_ffff |
| 39 | + let allOnes: Builtin.Int64 = Builtin.sext_Int1_Int64(smallOne) |
| 40 | + // 0x00ff_ffff_ffff_ffff |
| 41 | + let constant: Builtin.Int64 = Builtin.lshr_Int64(allOnes, eight); |
| 42 | + |
| 43 | + let j = Builtin.and_Int64(i, constant) |
| 44 | + let rawValue: Builtin.RawPointer = Builtin.inttoptr_Int64(j) |
| 45 | + let zeroPtr: Builtin.RawPointer = Builtin.inttoptr_Int64(zero) |
| 46 | + let value: Builtin.Int1 = Builtin.cmp_eq_RawPointer(rawValue, zeroPtr) |
| 47 | + |
| 48 | + if value { |
21 | 49 | // Make sure we optimize away this branch.
|
22 | 50 | Builtin.unreachable()
|
23 | 51 | }
|
24 |
| - return p[0] |
| 52 | + |
| 53 | + let x: Builtin.Int64 = Builtin.load(rawValue) |
| 54 | + return x |
25 | 55 | }
|
0 commit comments