[llvm] r323619 - [InlineCost] Mark functions accessing varargs as not viable.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 28 11:11:49 PST 2018
Author: fhahn
Date: Sun Jan 28 11:11:49 2018
New Revision: 323619
URL: http://llvm.org/viewvc/llvm-project?rev=323619&view=rev
Log:
[InlineCost] Mark functions accessing varargs as not viable.
This prevents functions accessing varargs from being inlined if they
have the alwaysinline attribute.
Reviewers: efriedma, rnk, davide
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D42556
Modified:
llvm/trunk/lib/Analysis/InlineCost.cpp
llvm/trunk/test/Transforms/Inline/inline-varargs.ll
Modified: llvm/trunk/lib/Analysis/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InlineCost.cpp?rev=323619&r1=323618&r2=323619&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InlineCost.cpp (original)
+++ llvm/trunk/lib/Analysis/InlineCost.cpp Sun Jan 28 11:11:49 2018
@@ -2040,12 +2040,18 @@ bool llvm::isInlineViable(Function &F) {
cast<CallInst>(CS.getInstruction())->canReturnTwice())
return false;
- // Disallow inlining functions that call @llvm.localescape. Doing this
- // correctly would require major changes to the inliner.
- if (CS.getCalledFunction() &&
- CS.getCalledFunction()->getIntrinsicID() ==
- llvm::Intrinsic::localescape)
- return false;
+ if (CS.getCalledFunction())
+ switch (CS.getCalledFunction()->getIntrinsicID()) {
+ default:
+ break;
+ // Disallow inlining functions that call @llvm.localescape. Doing this
+ // correctly would require major changes to the inliner.
+ case llvm::Intrinsic::localescape:
+ // Disallow inlining of functions that access VarArgs.
+ case llvm::Intrinsic::vastart:
+ case llvm::Intrinsic::vaend:
+ return false;
+ }
}
}
Modified: llvm/trunk/test/Transforms/Inline/inline-varargs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/inline-varargs.ll?rev=323619&r1=323618&r2=323619&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/Inline/inline-varargs.ll (original)
+++ llvm/trunk/test/Transforms/Inline/inline-varargs.ll Sun Jan 28 11:11:49 2018
@@ -64,12 +64,25 @@ entry:
ret i32 %va1
}
+define internal i32 @varg_accessed_alwaysinline(...) alwaysinline {
+entry:
+ %vargs = alloca i8*, align 8
+ %vargs.ptr = bitcast i8** %vargs to i8*
+ call void @llvm.va_start(i8* %vargs.ptr)
+ %va1 = va_arg i8** %vargs, i32
+ call void @llvm.va_end(i8* %vargs.ptr)
+ ret i32 %va1
+}
+
define i32 @call_vargs() {
- %res = call i32 (...) @varg_accessed(i32 10)
+ %res1 = call i32 (...) @varg_accessed(i32 10)
+ %res2 = call i32 (...) @varg_accessed_alwaysinline(i32 15)
+ %res = add i32 %res1, %res2
ret i32 %res
}
; CHECK-LABEL: @call_vargs
-; CHECK: %res = call i32 (...) @varg_accessed(i32 10)
+; CHECK: %res1 = call i32 (...) @varg_accessed(i32 10)
+; CHECK-NEXT: %res2 = call i32 (...) @varg_accessed_alwaysinline(i32 15)
declare void @llvm.va_start(i8*)
declare void @llvm.va_end(i8*)
More information about the llvm-commits
mailing list