[llvm] r293799 - [IPSCCP] Don't propagate return values of functions marked as noinline.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 1 10:52:20 PST 2017


Author: davide
Date: Wed Feb  1 12:52:20 2017
New Revision: 293799

URL: http://llvm.org/viewvc/llvm-project?rev=293799&view=rev
Log:
[IPSCCP] Don't propagate return values of functions marked as noinline.

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.

Added:
    llvm/trunk/test/Transforms/IPConstantProp/noinline-return.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/SCCP.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=293799&r1=293798&r2=293799&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Wed Feb  1 12:52:20 2017
@@ -1715,7 +1715,12 @@ static bool runIPSCCP(Module &M, const D
     // 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

Added: llvm/trunk/test/Transforms/IPConstantProp/noinline-return.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/IPConstantProp/noinline-return.ll?rev=293799&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/IPConstantProp/noinline-return.ll (added)
+++ llvm/trunk/test/Transforms/IPConstantProp/noinline-return.ll Wed Feb  1 12:52:20 2017
@@ -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 }




More information about the llvm-commits mailing list