mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Replaces a builtin "xor", which negates its operand comparison ``` %3 = builtin "cmp_slt_Int64"(%1, %2) : $Builtin.Int1 %4 = integer_literal $Builtin.Int1, -1 %5 = builtin "xor_Int1"(%3, %4) : $Builtin.Int1 ``` with the negated comparison ``` %5 = builtin "cmp_ge_Int64"(%1, %2) : $Builtin.Int1 ``` This makes LLVM's IPSCCP happy. rdar://154950810
22 lines
782 B
Swift
22 lines
782 B
Swift
// RUN: %target-swift-frontend %s -emit-ir -O -disable-availability-checking -enable-experimental-feature Lifetimes | %FileCheck %s --check-prefix=CHECK-IR
|
|
|
|
// REQUIRES: swift_feature_Lifetimes
|
|
// REQUIRES: swift_stdlib_no_asserts, optimized_stdlib
|
|
// REQUIRES: CPU=arm64 || CPU=arm64e
|
|
|
|
// Check that the loop is fully optimized, including bounds check elimination and vectorization.
|
|
|
|
// CHECK-IR-LABEL: define {{.*}} @"$s24span_bounds_check_tests24loop4over5usingSis4SpanVys5UInt8VG_AFySiGtF"
|
|
// CHECK-IR: vector.body:
|
|
// CHECK-IR: ret
|
|
public func loop(over a: borrowing Span<UInt8>, using b: borrowing Span<Int>) -> Int {
|
|
var result = 0
|
|
precondition(UInt8.max < b.count)
|
|
for i in a.indices {
|
|
let idx = Int(a[i])
|
|
result &+= b[idx]
|
|
}
|
|
return result
|
|
}
|
|
|