[PATCH] D21568: Invoke simplifycfg and sroa before instcombine.

Dehao Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 15:01:54 PDT 2016


danielcdh updated this revision to Diff 61615.
danielcdh added a comment.

address Diego's reviews.


http://reviews.llvm.org/D21568

Files:
  lib/CodeGen/BackendUtil.cpp
  test/CodeGen/pgo-sample-preparation.c
  test/CodeGen/pgo-sample.c

Index: test/CodeGen/pgo-sample.c
===================================================================
--- test/CodeGen/pgo-sample.c
+++ test/CodeGen/pgo-sample.c
@@ -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
Index: test/CodeGen/pgo-sample-preparation.c
===================================================================
--- /dev/null
+++ test/CodeGen/pgo-sample-preparation.c
@@ -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
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -178,8 +178,14 @@
   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());
 }
 
@@ -491,7 +497,7 @@
     MPM->add(createPruneEHPass());
     MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));
     PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
-                           addInstructionCombiningPass);
+                           addCleanupPassesForSampleProfiler);
   }
 
   PMBuilder.populateFunctionPassManager(*FPM);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21568.61615.patch
Type: text/x-patch
Size: 2577 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160622/d02cfcf0/attachment.bin>


More information about the llvm-commits mailing list