Skip to content

Commit 1c3ef6c

Browse files
committed
ColdSplit: avoid with -Osize
Based on prior evaluation, this optimization always increases code size. It splits out blocks and introduces calls, which always adds extra instructions to shuffle values for calling conventions and to make the actual call/return. Apple clang avoids the optimization in `-Oz`, which I think is pretty close to what Swift's `-Osize` really means.
1 parent 1b2c13b commit 1c3ef6c

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
222222
PTO.LoopVectorization = true;
223223
PTO.SLPVectorization = true;
224224
PTO.MergeFunctions = true;
225-
DoHotColdSplit = Opts.EnableHotColdSplit;
225+
// Splitting trades code size to enhance memory locality, avoid in -Osize.
226+
DoHotColdSplit = Opts.EnableHotColdSplit && !Opts.optimizeForSize();
226227
level = llvm::OptimizationLevel::Os;
227228
} else {
228229
level = llvm::OptimizationLevel::O0;

test/IRGen/cold_split.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
// RUN: -enable-throws-prediction -O -disable-split-cold-code \
88
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
99

10+
//// Test using -Osize doesn't yield a split.
11+
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
12+
// RUN: -enable-throws-prediction -Osize -enable-split-cold-code \
13+
// RUN: | %FileCheck --check-prefix CHECK-DISABLED %s
14+
1015
//// Test disabling optimization entirely doesn't yield a split.
1116
// RUN: %target-swift-frontend %s -module-name=test -emit-assembly \
1217
// RUN: -enable-throws-prediction -enable-split-cold-code \

0 commit comments

Comments
 (0)