Author: dehao
Date: Thu Jun 23 15:13:10 2016
New Revision: 273606

URL: http://llvm.org/viewvc/llvm-project?rev=273606&view=rev
Log:
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

Added:
    cfe/trunk/test/CodeGen/pgo-sample-preparation.c
Modified:
    cfe/trunk/lib/CodeGen/BackendUtil.cpp
    cfe/trunk/test/CodeGen/pgo-sample.c

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=273606&r1=273605&r2=273606&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu Jun 23 15:13:10 2016
@@ -178,8 +178,14 @@ static void addAddDiscriminatorsPass(con
   PM.add(createAddDiscriminatorsPass());
 }
 
-static void addInstructionCombiningPass(const PassManagerBuilder &Builder,
-                                        legacy::PassManagerBase &PM) {
+static void addCleanupPassesForSampleProfiler(
+    const PassManagerBuilder &Builder, legacy::PassManagerBase &PM) {
+  // instcombine is needed before sample profile annotation because it converts
+  // certain function calls to be inlinable. simplifycfg and sroa are needed
+  // before instcombine for necessary preparation. E.g. load store is 
eliminated
+  // properly so that instcombine will not introduce unecessary liverange.
+  PM.add(createCFGSimplificationPass());
+  PM.add(createSROAPass());
   PM.add(createInstructionCombiningPass());
 }
 
@@ -492,7 +498,7 @@ void EmitAssemblyHelper::CreatePasses(Mo
     MPM->add(createPruneEHPass());
     MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));
     PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
-                           addInstructionCombiningPass);
+                           addCleanupPassesForSampleProfiler);
   }
 
   PMBuilder.populateFunctionPassManager(*FPM);

Added: cfe/trunk/test/CodeGen/pgo-sample-preparation.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pgo-sample-preparation.c?rev=273606&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/pgo-sample-preparation.c (added)
+++ cfe/trunk/test/CodeGen/pgo-sample-preparation.c Thu Jun 23 15:13:10 2016
@@ -0,0 +1,16 @@
+// Test if PGO sample use preparation passes are executed correctly.
+//
+// Ensure that instcombine is executed after simplifycfg and sroa so that
+// "a < 255" will not be converted to a * 256 < 255 * 256.
+// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-emit-llvm -o - 2>&1 | FileCheck %s
+
+void bar(int);
+void foo(int x, int y, int z) {
+  int m;
+  for (m = 0; m < x ; m++) {
+    int a = (((y >> 8) & 0xff) * z) / 256;
+    bar(a < 255 ? a : 255);
+  }
+}
+
+// CHECK-NOT: icmp slt i32 %mul, 65280

Modified: cfe/trunk/test/CodeGen/pgo-sample.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pgo-sample.c?rev=273606&r1=273605&r2=273606&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/pgo-sample.c (original)
+++ cfe/trunk/test/CodeGen/pgo-sample.c Thu Jun 23 15:13:10 2016
@@ -2,5 +2,8 @@
 //
 // Ensure Pass PGOInstrumentationGenPass is invoked.
 // RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s
+// CHECK: Simplify the CFG
+// CHECK: SROA
+// CHECK: Combine redundant instructions
 // CHECK: Remove unused exception handling info
 // CHECK: Sample profile pass


_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to