[PATCH] D43926: [ArgumentPromotion] don't break musttail invariant PR36543

Fedor Indutny via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 1 17:01:49 PST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL326521: [ArgumentPromotion] don't break musttail invariant PR36543 (authored by indutny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D43926?vs=136461&id=136649#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D43926

Files:
  llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
  llvm/trunk/test/Transforms/ArgumentPromotion/musttail.ll


Index: llvm/trunk/test/Transforms/ArgumentPromotion/musttail.ll
===================================================================
--- llvm/trunk/test/Transforms/ArgumentPromotion/musttail.ll
+++ llvm/trunk/test/Transforms/ArgumentPromotion/musttail.ll
@@ -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
+}
Index: llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
===================================================================
--- llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
+++ llvm/trunk/lib/Transforms/IPO/ArgumentPromotion.cpp
@@ -853,10 +853,20 @@
     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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43926.136649.patch
Type: text/x-patch
Size: 2291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180302/0ccc2f7e/attachment.bin>


More information about the llvm-commits mailing list