[llvm-branch-commits] [llvm-branch] r329858 - Merging r326521:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Apr 11 15:53:38 PDT 2018


Author: tstellar
Date: Wed Apr 11 15:53:38 2018
New Revision: 329858

URL: http://llvm.org/viewvc/llvm-project?rev=329858&view=rev
Log:
Merging r326521:

------------------------------------------------------------------------
r326521 | indutny | 2018-03-01 16:59:27 -0800 (Thu, 01 Mar 2018) | 13 lines

[ArgumentPromotion] don't break musttail invariant PR36543

Summary:
Do not break musttail invariant by promoting arguments of musttail
callee or caller.

Reviewers: sanjoy, dberlin, hfinkel, george.burgess.iv, fhahn, rnk

Reviewed By: rnk

Subscribers: rnk, llvm-commits

Differential Revision: https://reviews.llvm.org/D43926
------------------------------------------------------------------------

Added:
    llvm/branches/release_60/test/Transforms/ArgumentPromotion/musttail.ll
Modified:
    llvm/branches/release_60/lib/Transforms/IPO/ArgumentPromotion.cpp

Modified: llvm/branches/release_60/lib/Transforms/IPO/ArgumentPromotion.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/lib/Transforms/IPO/ArgumentPromotion.cpp?rev=329858&r1=329857&r2=329858&view=diff
==============================================================================
--- llvm/branches/release_60/lib/Transforms/IPO/ArgumentPromotion.cpp (original)
+++ llvm/branches/release_60/lib/Transforms/IPO/ArgumentPromotion.cpp Wed Apr 11 15:53:38 2018
@@ -847,10 +847,20 @@ promoteArguments(Function *F, function_r
     if (CS.getInstruction() == nullptr || !CS.isCallee(&U))
       return nullptr;
 
+    // Can't change signature of musttail callee
+    if (CS.isMustTailCall())
+      return nullptr;
+
     if (CS.getInstruction()->getParent()->getParent() == F)
       isSelfRecursive = true;
   }
 
+  // Can't change signature of musttail caller
+  // FIXME: Support promoting whole chain of musttail functions
+  for (BasicBlock &BB : *F)
+    if (BB.getTerminatingMustTailCall())
+      return nullptr;
+
   const DataLayout &DL = F->getParent()->getDataLayout();
 
   AAResults &AAR = AARGetter(*F);

Added: llvm/branches/release_60/test/Transforms/ArgumentPromotion/musttail.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/test/Transforms/ArgumentPromotion/musttail.ll?rev=329858&view=auto
==============================================================================
--- llvm/branches/release_60/test/Transforms/ArgumentPromotion/musttail.ll (added)
+++ llvm/branches/release_60/test/Transforms/ArgumentPromotion/musttail.ll Wed Apr 11 15:53:38 2018
@@ -0,0 +1,45 @@
+; RUN: opt < %s -argpromotion -S | FileCheck %s
+; PR36543
+
+; Don't promote arguments of musttail callee
+
+%T = type { i32, i32, i32, i32 }
+
+; CHECK-LABEL: define internal i32 @test(%T* %p)
+define internal i32 @test(%T* %p) {
+  %a.gep = getelementptr %T, %T* %p, i64 0, i32 3
+  %b.gep = getelementptr %T, %T* %p, i64 0, i32 2
+  %a = load i32, i32* %a.gep
+  %b = load i32, i32* %b.gep
+  %v = add i32 %a, %b
+  ret i32 %v
+}
+
+; CHECK-LABEL: define i32 @caller(%T* %p)
+define i32 @caller(%T* %p) {
+  %v = musttail call i32 @test(%T* %p)
+  ret i32 %v
+}
+
+; Don't promote arguments of musttail caller
+
+define i32 @foo(%T* %p, i32 %v) {
+  ret i32 0
+}
+
+; CHECK-LABEL: define internal i32 @test2(%T* %p, i32 %p2)
+define internal i32 @test2(%T* %p, i32 %p2) {
+  %a.gep = getelementptr %T, %T* %p, i64 0, i32 3
+  %b.gep = getelementptr %T, %T* %p, i64 0, i32 2
+  %a = load i32, i32* %a.gep
+  %b = load i32, i32* %b.gep
+  %v = add i32 %a, %b
+  %ca = musttail call i32 @foo(%T* undef, i32 %v)
+  ret i32 %ca
+}
+
+; CHECK-LABEL: define i32 @caller2(%T* %g)
+define i32 @caller2(%T* %g) {
+  %v = call i32 @test2(%T* %g, i32 0)
+  ret i32 %v
+}




More information about the llvm-branch-commits mailing list