Skip to content

Commit bd3ed3c

Browse files
committedJun 23, 2016
Invoke simplifycfg and sroa before instcombine.
Summary: InstCombine needs to be performed after simplifycfg and sroa, otherwise it may make bad optimization decisions. Reviewers: davidxl, wmi, dnovillo Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D21568 llvm-svn: 273606
1 parent 8d4b0ed commit bd3ed3c

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed
 

‎clang/lib/CodeGen/BackendUtil.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,14 @@ static void addAddDiscriminatorsPass(const PassManagerBuilder &Builder,
178178
PM.add(createAddDiscriminatorsPass());
179179
}
180180

181-
static void addInstructionCombiningPass(const PassManagerBuilder &Builder,
182-
legacy::PassManagerBase &PM) {
181+
static void addCleanupPassesForSampleProfiler(
182+
const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) {
183+
// instcombine is needed before sample profile annotation because it converts
184+
// certain function calls to be inlinable. simplifycfg and sroa are needed
185+
// before instcombine for necessary preparation. E.g. load store is eliminated
186+
// properly so that instcombine will not introduce unecessary liverange.
187+
PM.add(createCFGSimplificationPass());
188+
PM.add(createSROAPass());
183189
PM.add(createInstructionCombiningPass());
184190
}
185191

@@ -492,7 +498,7 @@ void EmitAssemblyHelper::CreatePasses(ModuleSummaryIndex *ModuleSummary) {
492498
MPM->add(createPruneEHPass());
493499
MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));
494500
PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
495-
addInstructionCombiningPass);
501+
addCleanupPassesForSampleProfiler);
496502
}
497503

498504
PMBuilder.populateFunctionPassManager(*FPM);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Test if PGO sample use preparation passes are executed correctly.
2+
//
3+
// Ensure that instcombine is executed after simplifycfg and sroa so that
4+
// "a < 255" will not be converted to a * 256 < 255 * 256.
5+
// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -emit-llvm -o - 2>&1 | FileCheck %s
6+
7+
void bar(int);
8+
void foo(int x, int y, int z) {
9+
int m;
10+
for (m = 0; m < x ; m++) {
11+
int a = (((y >> 8) & 0xff) * z) / 256;
12+
bar(a < 255 ? a : 255);
13+
}
14+
}
15+
16+
// CHECK-NOT: icmp slt i32 %mul, 65280

‎clang/test/CodeGen/pgo-sample.c

+3
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
//
33
// Ensure Pass PGOInstrumentationGenPass is invoked.
44
// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
5+
// CHECK: Simplify the CFG
6+
// CHECK: SROA
7+
// CHECK: Combine redundant instructions
58
// CHECK: Remove unused exception handling info
69
// CHECK: Sample profile pass

0 commit comments

Comments
 (0)
Please sign in to comment.