Skip to content

Commit 64f2d64

Browse files
committed
Disable SpeculativeDevirtualization at -Os
1 parent c05381f commit 64f2d64

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/SILOptimizer/Transforms/SpeculativeDevirtualizer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,13 @@ namespace {
556556
~SpeculativeDevirtualization() override {}
557557

558558
void run() override {
559+
560+
auto &CurFn = *getFunction();
561+
// Don't perform speculative devirtualization at -Os.
562+
if (CurFn.getModule().getOptions().Optimization ==
563+
SILOptions::SILOptMode::OptimizeForSize)
564+
return;
565+
559566
ClassHierarchyAnalysis *CHA = PM->getAnalysis<ClassHierarchyAnalysis>();
560567

561568
bool Changed = false;

test/SILOptimizer/devirt_speculate.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend %s -parse-as-library -O -emit-sil | %FileCheck %s
2+
// RUN: %target-swift-frontend %s -parse-as-library -Osize -emit-sil | %FileCheck %s --check-prefix=OSIZE
23
//
34
// Test speculative devirtualization.
45

@@ -40,6 +41,10 @@ class Sub7 : Base {
4041
// CHECK-NOT: checked_cast_br
4142
// CHECK: %[[CM:[0-9]+]] = class_method %0 : $Base, #Base.foo!1 : (Base) -> () -> (), $@convention(method) (@guaranteed Base) -> ()
4243
// CHECK: apply %[[CM]](%0) : $@convention(method) (@guaranteed Base) -> ()
44+
45+
// OSIZE: @_T016devirt_speculate28testMaxNumSpeculativeTargetsyAA4BaseCF
46+
// OSIZE-NOT: checked_cast_br [exact] %0 : $Base to $Base
47+
// OSIZE-NOT: checked_cast_br [exact] %0 : $Base to $Sub
4348
public func testMaxNumSpeculativeTargets(_ b: Base) {
4449
b.foo()
4550
}

0 commit comments

Comments
 (0)