[PATCH] D145209: [DAE] Don't change the return type if we have virtual musttail calls

Mircea Trofin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 2 18:49:23 PST 2023


mtrofin updated this revision to Diff 502038.
mtrofin added a comment.

newline at end of test file


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145209/new/

https://reviews.llvm.org/D145209

Files:
  llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
  llvm/test/Transforms/DeadArgElim/musttail-indirect.ll


Index: llvm/test/Transforms/DeadArgElim/musttail-indirect.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/DeadArgElim/musttail-indirect.ll
@@ -0,0 +1,9 @@
+; RUN: opt -passes=deadargelim,verify -S < %s 2>&1 | FileCheck %s
+define internal i32 @test(ptr %fptr, i32 %a, i32 %b) {
+  %r = musttail call i32 %fptr(ptr %fptr, i32 %a, i32 0)
+  ret i32 %r
+}
+
+; CHECK-NOT: cannot guarantee tail call due to mismatched parameter counts
+; CHECK: define internal i32 @test
+; CHECK-NEXT: %r = musttail call i32 %fptr
Index: llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
===================================================================
--- llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
+++ llvm/lib/Transforms/IPO/DeadArgumentElimination.cpp
@@ -520,8 +520,14 @@
   for (const BasicBlock &BB : F) {
     // If we have any returns of `musttail` results - the signature can't
     // change
-    if (BB.getTerminatingMustTailCall() != nullptr)
+    if (const auto *TC = BB.getTerminatingMustTailCall()) {
       HasMustTailCalls = true;
+      // In addition, if the called function is virtual, we can't change
+      // the return type.
+      if (!TC->getCalledFunction())
+        for (unsigned Ri = 0; Ri < RetCount; ++Ri)
+          RetValLiveness[Ri] = Live;
+    }
   }
 
   if (HasMustTailCalls) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145209.502038.patch
Type: text/x-patch
Size: 1374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230303/ed1f4c67/attachment.bin>


More information about the llvm-commits mailing list