Don't eliminate frame pointer by default at -O0 (#2483)

Fixes issue #2480.
This commit is contained in:
Martin Kinkelin 2018-01-13 13:49:10 +01:00 committed by GitHub
parent a4043a4bcc
commit ca6472c3b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 33 additions and 21 deletions

View file

@ -35,7 +35,11 @@ Reloc::Model getRelocModel() { return ::RelocModel; }
CodeModel::Model getCodeModel() { return ::CMModel; }
bool disableFPElim() { return ::DisableFPElim; }
cl::boolOrDefault disableFPElim() {
return ::DisableFPElim.getNumOccurrences() == 0
? cl::BOU_UNSET
: ::DisableFPElim ? cl::BOU_TRUE : cl::BOU_FALSE;
}
bool disableRedZone() { return ::DisableRedZone; }

View file

@ -24,7 +24,7 @@ llvm::Optional<llvm::Reloc::Model> getRelocModel();
llvm::Reloc::Model getRelocModel();
#endif
llvm::CodeModel::Model getCodeModel();
bool disableFPElim();
llvm::cl::boolOrDefault disableFPElim();
bool disableRedZone();
bool printTargetFeaturesHelp();

View file

@ -459,9 +459,8 @@ void applyTargetMachineAttributes(llvm::Function &func,
func.addFnAttr("no-infs-fp-math", TO.NoInfsFPMath ? "true" : "false");
func.addFnAttr("no-nans-fp-math", TO.NoNaNsFPMath ? "true" : "false");
// Frame pointer elimination
func.addFnAttr("no-frame-pointer-elim",
opts::disableFPElim() ? "true" : "false");
willEliminateFramePointer() ? "false" : "true");
}
} // anonymous namespace

View file

@ -120,6 +120,12 @@ bool willCrossModuleInline() {
return enableCrossModuleInlining == llvm::cl::BOU_TRUE;
}
bool willEliminateFramePointer() {
const llvm::cl::boolOrDefault disableFPElimEnum = opts::disableFPElim();
return disableFPElimEnum == llvm::cl::BOU_FALSE ||
(disableFPElimEnum == llvm::cl::BOU_UNSET && isOptimizationEnabled());
}
bool isOptimizationEnabled() { return optimizeLevel != 0; }
llvm::CodeGenOpt::Level codeGenOptLevel() {

View file

@ -35,6 +35,8 @@ bool willInline();
bool willCrossModuleInline();
bool willEliminateFramePointer();
unsigned optLevel();
bool isOptimizationEnabled();

View file

@ -1,26 +1,27 @@
// Tests that our TargetMachine options are added as function attributes
// RUN: %ldc -c -output-ll -of=%t.ll %s && FileCheck %s --check-prefix=DEFAULT < %t.ll
// RUN: %ldc -c -output-ll -of=%t.ll %s -disable-fp-elim && FileCheck %s --check-prefix=FRAMEPTR < %t.ll
// RUN: %ldc -c -output-ll -of=%t.ll %s -mattr=test && FileCheck %s --check-prefix=ATTR < %t.ll
// RUN: %ldc -c -output-ll -of=%t.ll %s
// RUN: FileCheck %s --check-prefix=COMMON --check-prefix=WITH_FP < %t.ll
// RUN: %ldc -c -output-ll -of=%t.ll %s -O2
// RUN: FileCheck %s --check-prefix=COMMON --check-prefix=NO_FP < %t.ll
// RUN: %ldc -c -output-ll -of=%t.ll %s -O2 -disable-fp-elim
// RUN: FileCheck %s --check-prefix=COMMON --check-prefix=WITH_FP < %t.ll
// RUN: %ldc -c -output-ll -of=%t.ll %s -disable-fp-elim=false -mattr=test
// RUN: FileCheck %s --check-prefix=COMMON --check-prefix=NO_FP --check-prefix=ATTR < %t.ll
// DEFAULT: define{{.*}} @{{.*}}3fooFZv{{.*}} #[[KEYVALUE:[0-9]+]]
// FRAMEPTR: define{{.*}} @{{.*}}3fooFZv{{.*}} #[[KEYVALUE:[0-9]+]]
// ATTR: define{{.*}} @{{.*}}3fooFZv{{.*}} #[[KEYVALUE:[0-9]+]]
// COMMON: define{{.*}} @{{.*}}3fooFZv{{.*}} #[[KEYVALUE:[0-9]+]]
void foo()
{
}
// DEFAULT: attributes #[[KEYVALUE]]
// DEFAULT-DAG: "target-cpu"=
// DEFAULT-DAG: "no-frame-pointer-elim"="false"
// DEFAULT-DAG: "unsafe-fp-math"="false"
// DEFAULT-DAG: "less-precise-fpmad"="false"
// DEFAULT-DAG: "no-infs-fp-math"="false"
// DEFAULT-DAG: "no-nans-fp-math"="false"
// COMMON: attributes #[[KEYVALUE]]
// COMMON-DAG: "target-cpu"=
// COMMON-DAG: "unsafe-fp-math"="false"
// COMMON-DAG: "less-precise-fpmad"="false"
// COMMON-DAG: "no-infs-fp-math"="false"
// COMMON-DAG: "no-nans-fp-math"="false"
// FRAMEPTR: attributes #[[KEYVALUE]]
// FRAMEPTR-DAG: "no-frame-pointer-elim"="true"
// WITH_FP-DAG: "no-frame-pointer-elim"="true"
// NO_FP-DAG: "no-frame-pointer-elim"="false"
// ATTR: attributes #[[KEYVALUE]]
// ATTR-DAG: "target-features"="{{.*}}+test{{.*}}"

@ -1 +1 @@
Subproject commit 5e9ab8e37b6d435f6cfba4cfd87b3c6651e9e562
Subproject commit 9e3d6271d78ac959a42c48fd9ca15e8d7a8ba531