summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/Scalar/SCCP.cpp7
-rw-r--r--llvm/test/Transforms/IPConstantProp/noinline-return.ll21
2 files changed, 27 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/SCCP.cpp b/llvm/lib/Transforms/Scalar/SCCP.cpp
index dd1123fd4fa..054ad712d38 100644
--- a/llvm/lib/Transforms/Scalar/SCCP.cpp
+++ b/llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -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/llvm/test/Transforms/IPConstantProp/noinline-return.ll b/llvm/test/Transforms/IPConstantProp/noinline-return.ll
new file mode 100644
index 00000000000..10950327327
--- /dev/null
+++ b/llvm/test/Transforms/IPConstantProp/noinline-return.ll
@@ -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 }
OpenPOWER on IntegriCloud