[PATCH] D83300: [GlobalOpt] Don't remove inalloca from musttail-called functions

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 7 05:54:05 PDT 2020


hans created this revision.
hans added reviewers: aeubanks, efriedma.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

Otherwise the verifier complains about the mismatching function ABIs.


https://reviews.llvm.org/D83300

Files:
  llvm/lib/Transforms/IPO/GlobalOpt.cpp
  llvm/test/Transforms/GlobalOpt/fastcc.ll


Index: llvm/test/Transforms/GlobalOpt/fastcc.ll
===================================================================
--- llvm/test/Transforms/GlobalOpt/fastcc.ll
+++ llvm/test/Transforms/GlobalOpt/fastcc.ll
@@ -35,6 +35,17 @@
   ret i32 %rv
 }
 
+define i32 @inalloca2_caller(i32* inalloca %p) {
+  %rv = musttail call i32 @inalloca2(i32* inalloca %p)
+  ret i32 %rv
+}
+define internal i32 @inalloca2(i32* inalloca %p) {
+; Because of the musttail caller, this inalloca cannot be dropped.
+; CHECK-LABEL: define internal i32 @inalloca2(i32* inalloca %p)
+  %rv = load i32, i32* %p
+  ret i32 %rv
+}
+
 define internal i32 @preallocated(i32* preallocated(i32) %p) {
 ; CHECK-LABEL: define internal fastcc i32 @preallocated(i32* %p)
   %rv = load i32, i32* %p
Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp
===================================================================
--- llvm/lib/Transforms/IPO/GlobalOpt.cpp
+++ llvm/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2442,7 +2442,7 @@
     // FIXME: We should also hoist alloca affected by this to the entry
     // block if possible.
     if (F->getAttributes().hasAttrSomewhere(Attribute::InAlloca) &&
-        !F->hasAddressTaken()) {
+        !F->hasAddressTaken() && !hasMustTailCallers(F)) {
       RemoveAttribute(F, Attribute::InAlloca);
       Changed = true;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83300.276026.patch
Type: text/x-patch
Size: 1318 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200707/5ac32a37/attachment.bin>


More information about the llvm-commits mailing list