[llvm] Refine metadata handling during instruction hoisting (PR #158448)
William Moses via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 13 16:13:23 PDT 2025
https://github.com/wsmoses created https://github.com/llvm/llvm-project/pull/158448
None
>From 27285dfe8c473214ed2b73edd53c56995ad1bb0f Mon Sep 17 00:00:00 2001
From: William Moses <gh at wsmoses.com>
Date: Sat, 13 Sep 2025 18:13:11 -0500
Subject: [PATCH] Refine metadata handling during instruction hoisting
---
llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 5a842f9b49c1b..6d6e32d51b62e 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3387,11 +3387,13 @@ bool SimplifyCFGOpt::speculativelyExecuteBB(BranchInst *BI,
// Metadata can be dependent on the condition we are hoisting above.
// Strip all UB-implying metadata on the instruction. Drop the debug loc
// to avoid making it appear as if the condition is a constant, which would
- // be misleading while debugging.
+ // be misleading while debugging. However, make sure to keep debug info
+ // for calls as inlinable function calls in a function with debug info must
+ // have a !dbg location.
// Similarly strip attributes that maybe dependent on condition we are
// hoisting above.
for (auto &I : make_early_inc_range(*ThenBB)) {
- if (!SpeculatedStoreValue || &I != SpeculatedStore) {
+ if (!SpeculatedStoreValue || &I != SpeculatedStore && !isa<CallBase>(&I)) {
I.setDebugLoc(DebugLoc::getDropped());
}
I.dropUBImplyingAttrsAndMetadata();
More information about the llvm-commits
mailing list