[PATCH] D11232: Always run GlobalDCE before the inliner

Evgeniy Stepanov eugenis at google.com
Wed Jul 15 11:26:11 PDT 2015


eugenis created this revision.
eugenis added a reviewer: dberlin.
eugenis added a subscriber: llvm-commits.
eugenis set the repository for this revision to rL LLVM.

Inliner, as an SCC pass, does not run on functions that are not reachable from the callgraph entry node.
Because of this, it may fail to inline an alwaysinline function.

The change runs GlobalDCE before inlining to make sure that this does not happen.
See the testcase for a sample input triggering this issue (the interesting case here is -O1, reproducing with both opt -O1 and clang -O1).


Repository:
  rL LLVM

http://reviews.llvm.org/D11232

Files:
  lib/Transforms/IPO/PassManagerBuilder.cpp
  test/Transforms/Inline/always-inline-O1.ll

Index: test/Transforms/Inline/always-inline-O1.ll
===================================================================
--- test/Transforms/Inline/always-inline-O1.ll
+++ test/Transforms/Inline/always-inline-O1.ll
@@ -0,0 +1,40 @@
+; RUN: opt < %s -O1 -S | FileCheck %s
+; RUN: opt < %s -O2 -S | FileCheck %s
+; RUN: opt < %s -O3 -S | FileCheck %s
+; CHECK-NOT: call{{.*}}BBB
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+declare void @AAA()
+
+define void @BBB() alwaysinline {
+entry:
+  call void @AAA()
+  ret void
+}
+
+define internal void @CCC()  {
+entry:
+  call void @BBB()
+  ret void
+}
+
+define void @DDD(i8* %x) {
+entry:
+  %a = load i8, i8* %x, align 4
+  %cmpa = icmp ne i8 %a, 1
+  br i1 %cmpa, label %return, label %if.end
+
+if.end:
+  %b = load i8, i8* %x, align 4
+  %cmpb = icmp eq i8 %b, 1
+  br i1 %cmpb, label %return, label %if.end.2
+
+if.end.2:
+  call void @CCC()
+  br label %return
+
+return:
+  ret void
+}
Index: lib/Transforms/IPO/PassManagerBuilder.cpp
===================================================================
--- lib/Transforms/IPO/PassManagerBuilder.cpp
+++ lib/Transforms/IPO/PassManagerBuilder.cpp
@@ -176,6 +176,7 @@
   // if enabled, the function merging pass.
   if (OptLevel == 0) {
     if (Inliner) {
+      MPM.add(createGlobalDCEPass());         // Remove dead fns and globals.
       MPM.add(Inliner);
       Inliner = nullptr;
     }
@@ -217,6 +218,7 @@
   if (!DisableUnitAtATime)
     MPM.add(createPruneEHPass());             // Remove dead EH info
   if (Inliner) {
+    MPM.add(createGlobalDCEPass());         // Remove dead fns and globals.
     MPM.add(Inliner);
     Inliner = nullptr;
   }
@@ -453,6 +455,7 @@
   // Inline small functions
   bool RunInliner = Inliner;
   if (RunInliner) {
+    PM.add(createGlobalDCEPass());         // Remove dead fns and globals.
     PM.add(Inliner);
     Inliner = nullptr;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11232.29804.patch
Type: text/x-patch
Size: 1950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150715/0e3970b4/attachment.bin>


More information about the llvm-commits mailing list