[llvm] fix cratch in tail call return type (PR #210579)

via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 19 01:17:01 PDT 2026


https://github.com/SomeFlyingThing updated https://github.com/llvm/llvm-project/pull/210579

>From 920ead400a04fa5257993815d23360d442b7de4c Mon Sep 17 00:00:00 2001
From: SomeFlyingThing <306498559+SomeFlyingThing at users.noreply.github.com>
Date: Sun, 19 Jul 2026 08:52:10 +0100
Subject: [PATCH 1/2] fix cratch in tail call return type

---
 llvm/lib/CodeGen/Analysis.cpp                      | 6 ++++--
 llvm/test/CodeGen/X86/tail-call-empty-aggregate.ll | 9 +++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/X86/tail-call-empty-aggregate.ll

diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp
index 9ece9f0c187a2..c4d50b38479a5 100644
--- a/llvm/lib/CodeGen/Analysis.cpp
+++ b/llvm/lib/CodeGen/Analysis.cpp
@@ -692,8 +692,10 @@ bool llvm::returnTypeIsEligibleForTailCall(const Function *F,
       // We've exhausted the values produced by the tail call instruction, the
       // rest are essentially undef. The type doesn't really matter, but we need
       // *something*.
-      Type *SlotType =
-          ExtractValueInst::getIndexedType(RetSubTypes.back(), RetPath.back());
+      Type *SlotType = RetVal->getType();
+      if (!RetPath.empty())
+        SlotType = ExtractValueInst::getIndexedType(RetSubTypes.back(),
+                                                    RetPath.back());
       CallVal = UndefValue::get(SlotType);
     }
 
diff --git a/llvm/test/CodeGen/X86/tail-call-empty-aggregate.ll b/llvm/test/CodeGen/X86/tail-call-empty-aggregate.ll
new file mode 100644
index 0000000000000..1b2e86af6f79b
--- /dev/null
+++ b/llvm/test/CodeGen/X86/tail-call-empty-aggregate.ll
@@ -0,0 +1,9 @@
+; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -o /dev/null
+
+declare { {} } @callee()
+
+define i32 @caller() {
+entry:
+  %call = tail call { {} } @callee()
+  ret i32 0
+}

>From d65072fac28a433595706e3e0b4b9b74b24dc698 Mon Sep 17 00:00:00 2001
From: SomeFlyingThing <306498559+SomeFlyingThing at users.noreply.github.com>
Date: Sun, 19 Jul 2026 09:16:13 +0100
Subject: [PATCH 2/2] Fix SCC enter block collection in BPI

---
 llvm/lib/Analysis/BranchProbabilityInfo.cpp   |  2 +-
 .../Analysis/BranchProbabilityInfo/loop.ll    | 30 +++++++++++++++++++
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 1b0a8b8e74f4a..feb0b34cd4c48 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -391,7 +391,7 @@ void BPIConstruction::SccInfo::getSccEnterBlocks(
     if (isSCCHeader(BB, SccNum))
       for (const auto *Pred : predecessors(BB))
         if (getSCCNum(Pred) != SccNum)
-          Enters.push_back(const_cast<BasicBlock *>(BB));
+          Enters.push_back(const_cast<BasicBlock *>(Pred));
   }
 }
 
diff --git a/llvm/test/Analysis/BranchProbabilityInfo/loop.ll b/llvm/test/Analysis/BranchProbabilityInfo/loop.ll
index ffac1cd466641..e6b8429eddaa7 100644
--- a/llvm/test/Analysis/BranchProbabilityInfo/loop.ll
+++ b/llvm/test/Analysis/BranchProbabilityInfo/loop.ll
@@ -722,4 +722,34 @@ exit:
 }
 
 
+; Check that a cold irreducible loop propagates its estimated weight through
+; the blocks entering the SCC.
+define void @test19(i1 %arg, i1 %arg2, i1 %arg3, i1 %arg4) {
+; CHECK: edge %entry -> %dispatch probability is 0x078780e3 / 0x80000000 = 5.88%
+; CHECK: edge %entry -> %exit probability is 0x78787f1d / 0x80000000 = 94.12% [HOT edge]
+
+entry:
+  br i1 %arg, label %dispatch, label %exit
+
+dispatch:
+  br i1 %arg2, label %entry1, label %entry2
+
+entry1:
+  br label %loop1
+
+entry2:
+  br label %loop2
+
+loop1:
+  br i1 %arg3, label %loop2, label %cold
+
+loop2:
+  br i1 %arg4, label %loop1, label %cold
 
+cold:
+  call void @cold()
+  br label %exit
+
+exit:
+  ret void
+}



More information about the llvm-commits mailing list