Disable SpeculativeDevirtualization at -Os

This commit is contained in:
Arnold Schwaighofer
2017-08-16 11:04:16 -07:00
parent c05381f96e
commit 64f2d64b54
2 changed files with 12 additions and 0 deletions

View File

@@ -556,6 +556,13 @@ namespace {
~SpeculativeDevirtualization() override {}
void run() override {
auto &CurFn = *getFunction();
// Don't perform speculative devirtualization at -Os.
if (CurFn.getModule().getOptions().Optimization ==
SILOptions::SILOptMode::OptimizeForSize)
return;
ClassHierarchyAnalysis *CHA = PM->getAnalysis<ClassHierarchyAnalysis>();
bool Changed = false;

View File

@@ -1,4 +1,5 @@
// RUN: %target-swift-frontend %s -parse-as-library -O -emit-sil | %FileCheck %s
// RUN: %target-swift-frontend %s -parse-as-library -Osize -emit-sil | %FileCheck %s --check-prefix=OSIZE
//
// Test speculative devirtualization.
@@ -40,6 +41,10 @@ class Sub7 : Base {
// CHECK-NOT: checked_cast_br
// CHECK: %[[CM:[0-9]+]] = class_method %0 : $Base, #Base.foo!1 : (Base) -> () -> (), $@convention(method) (@guaranteed Base) -> ()
// CHECK: apply %[[CM]](%0) : $@convention(method) (@guaranteed Base) -> ()
// OSIZE: @_T016devirt_speculate28testMaxNumSpeculativeTargetsyAA4BaseCF
// OSIZE-NOT: checked_cast_br [exact] %0 : $Base to $Base
// OSIZE-NOT: checked_cast_br [exact] %0 : $Base to $Sub
public func testMaxNumSpeculativeTargets(_ b: Base) {
b.foo()
}