Skip to content

Commit 6c27e7e

Browse files
committed
Remove all stdlib dependencies from the tbi test.
This should eliminate any deployment target issues that we may run into when using this test. rdar://24370377
1 parent ea82bd1 commit 6c27e7e

File tree

1 file changed

+40
-10
lines changed

1 file changed

+40
-10
lines changed

test/Misc/tbi.swift

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,55 @@
11
// 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 | \
33
// RUN: %FileCheck --check-prefix=TBI %s
44

55
// 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 | \
77
// RUN: %FileCheck --check-prefix=NO_TBI %s
88

9-
// REQUIRES: CPU=arm64, OS=ios
9+
// REQUIRES: CPU=arm64
10+
// REQUIRES: OS=ios
1011

1112
// Verify that TBI is on by default in Swift on targets that support it. For our
1213
// purposes this means iOS8.0 or later.
1314

14-
import Swift
15+
public enum Never {}
1516

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 {
2149
// Make sure we optimize away this branch.
2250
Builtin.unreachable()
2351
}
24-
return p[0]
52+
53+
let x: Builtin.Int64 = Builtin.load(rawValue)
54+
return x
2555
}

0 commit comments

Comments
 (0)