[PATCH] D42556: [InlineCost] Mark functions accessing varargs as not viable.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 25 13:29:19 PST 2018


fhahn created this revision.
fhahn added reviewers: efriedma, rnk, davide.
Herald added subscribers: haicheng, eraman.

This prevents functions accessing varargs from being inlined if they
have the alwaysinline attribute.


https://reviews.llvm.org/D42556

Files:
  lib/Analysis/InlineCost.cpp
  test/Transforms/Inline/inline-varargs.ll


Index: test/Transforms/Inline/inline-varargs.ll
===================================================================
--- test/Transforms/Inline/inline-varargs.ll
+++ test/Transforms/Inline/inline-varargs.ll
@@ -64,12 +64,25 @@
   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*)
Index: lib/Analysis/InlineCost.cpp
===================================================================
--- lib/Analysis/InlineCost.cpp
+++ lib/Analysis/InlineCost.cpp
@@ -2040,12 +2040,18 @@
           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;
+        }
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42556.131503.patch
Type: text/x-patch
Size: 2156 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180125/16bb45c8/attachment.bin>


More information about the llvm-commits mailing list