Files
swift-mirror/test/SILOptimizer/pack_specialization.swift
Aidan Hall 97b7c35647 PackSpecialization: Fix result & type parameter handling
Refactor certain functions to make them simpler. and avoid calling
AST.Type.loweredType, which can fail. Instead, access the types of the
function's (SIL) arguments directly.

Correctly handle exploding packs that contain generic or opaque types by using
AST.Type.mapOutOfEnvironment().

@substituted types cause the shouldExplode predicate to be unreliable for AST
types, so restrict it to just SIL.Type. Add test cases for functions that have
@substituted types.

Re-enable PackSpecialization in FunctionPass pipeline.

Add a check to avoid emitting a destructure_tuple of the original function's
return tuple when it is void/().
2025-11-28 17:39:41 +00:00

40 lines
1.5 KiB
Swift

// RUN: %target-swift-frontend %s -emit-ir -O | %FileCheck %s
// REQUIRES: swift_in_compiler
// When no witness methods are called on pack elements, all pack code can be fully eliminated.
// CHECK: define {{.*}} { i32, ptr, double } @"$s19pack_specialization8copyPack2xsxxQp_txxQp_tRvzlFs5Int32V_SPys5Int16VGSdQP_Tg5Tf8xx_n"(i32 %0, ptr %1, double %2)
// CHECK-NEXT: entry:
// CHECK-NEXT: insertvalue
// CHECK-NEXT: insertvalue
// CHECK-NEXT: insertvalue
// CHECK-NEXT: ret { i32, ptr, double }
@inline(never)
func copyPack<each A>(xs: repeat each A) -> (repeat each A) {
return (repeat each xs);
}
public func copyPackCaller(two: UnsafePointer<Int16>) -> (Int32, UnsafePointer<Int16>, Double) {
return copyPack(xs: 1, two, 3.0)
}
// The pack specialization pass alone is not enough to eliminate packs when witness methods are called.
// CHECK: define {{.*}} i32 @"$s19pack_specialization11addTogether2xsxxQp_txxQp_tRvzSjRzlFs5Int32V_QP_Tg5Tf8xx_n"(i32 %0)
// CHECK-NEXT: entry:
// CHECK-NEXT: [[IN_STACK:%[0-9]+]] = alloca %Ts5Int32V, align 4
// CHECK-NEXT: [[OUT_STACK:%[0-9]+]] = alloca %Ts5Int32V, align 4
// CHECK: store i32 %0, ptr [[IN_STACK]], align 4
// CHECK: call swiftcc void @"$ss18AdditiveArithmeticP1poiyxx_xtFZTj"
// CHECK: [[RESULT:%[0-9]+]] = load i32, ptr [[OUT_STACK]]
// CHECK: ret i32 [[RESULT]]
@inline(never)
func addTogether<each A: Numeric>(xs: repeat each A) -> (repeat each A) {
return (repeat (each xs + each xs))
}
public func addTogetherCaller() -> Int32 {
return addTogether(xs: 1)
}