]> granicus.if.org Git - llvm/commitdiff
[IPSCCP] Don't propagate return values of functions marked as noinline.
authorDavide Italiano <davide@freebsd.org>
Wed, 1 Feb 2017 18:52:20 +0000 (18:52 +0000)
committerDavide Italiano <davide@freebsd.org>
Wed, 1 Feb 2017 18:52:20 +0000 (18:52 +0000)
This tries to address what Hal defined (in the post-commit review of
r293727) a long-standing problem with noinline, where we end up
de facto inlining trivial functions e.g.

__attribute__((noinline)) int patatino(void) { return 5; }

because of return value propagation.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@293799 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/SCCP.cpp
test/Transforms/IPConstantProp/noinline-return.ll [new file with mode: 0644]

index dd1123fd4faf1c1a95403a4185455db2bdfc4c27..054ad712d3849e985c8512fa9ad492a5d8dc7afa 100644 (file)
@@ -1715,7 +1715,12 @@ static bool runIPSCCP(Module &M, const DataLayout &DL,
     // Don't touch naked functions. They may contain asm returning a
     // value we don't see, so we may end up interprocedurally propagating
     // the return value incorrectly.
-    if (F.hasExactDefinition() && !F.hasFnAttribute(Attribute::Naked))
+    // Also, don't touch functions marked as noinline. Trivial functions may
+    // essentially be inlined because of return value propagation.
+    // (e.g. int tinkywinky(void) { return 666; })
+    if (F.hasExactDefinition() &&
+        !(F.hasFnAttribute(Attribute::Naked) ||
+          F.hasFnAttribute(Attribute::NoInline)))
       Solver.AddTrackedFunction(&F);
 
     // If this function only has direct calls that we can see, we can track its
diff --git a/test/Transforms/IPConstantProp/noinline-return.ll b/test/Transforms/IPConstantProp/noinline-return.ll
new file mode 100644 (file)
index 0000000..1095032
--- /dev/null
@@ -0,0 +1,21 @@
+; RUN: opt %s -ipsccp -S | FileCheck %s
+
+define i32 @tinkywinky() #0 {
+entry:
+  ret i32 5
+}
+
+define i32 @patatino() {
+entry:
+  %call = call i32 @tinkywinky()
+
+; Check that we don't propagate the return value of
+; @tinkywinky.
+; CHECK: call i32 @dipsy(i32 %call)
+  %call1 = call i32 @dipsy(i32 %call)
+  ret i32 %call1
+}
+
+declare i32 @dipsy(i32)
+
+attributes #0 = { noinline }