OSDN Git Service

[GlobalOpt] Don't remove inalloca from musttail-called functions
authorHans Wennborg <hans@chromium.org>
Tue, 7 Jul 2020 12:51:34 +0000 (14:51 +0200)
committerHans Wennborg <hans@chromium.org>
Tue, 7 Jul 2020 17:02:46 +0000 (19:02 +0200)
Otherwise the verifier complains about the mismatching function ABIs.

Differential revision: https://reviews.llvm.org/D83300

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

index ed98952..d9fb820 100644 (file)
@@ -2442,7 +2442,7 @@ OptimizeFunctions(Module &M,
     // 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;
     }
index 9c9076d..edd0688 100644 (file)
@@ -35,6 +35,17 @@ define internal i32 @inalloca(i32* inalloca %p) {
   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