[llvm] [IR] Remove unnecessary setDebugLoc calls. NFCI. (PR #218663)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 04:56:50 PDT 2026
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/218663
If we are already calling copyMetadata to copy metadata including MD_dbg
from an old instruction to a newly created one then there is no need to
call setDebugLoc to copy the debug metadata again.
>From b0de391a7faa69eb2b3f930839bef0c82826c53e Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Tue, 25 Aug 2026 11:50:31 +0100
Subject: [PATCH] [IR] Remove unnecessary setDebugLoc calls. NFCI.
If we are already calling copyMetadata to copy metadata including MD_dbg
from an old instruction to a newly created one then there is no need to
call setDebugLoc to copy the debug metadata again.
---
llvm/lib/IR/AutoUpgrade.cpp | 2 --
llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp | 1 -
.../Transforms/InstCombine/InstructionCombining.cpp | 10 +++++-----
llvm/lib/Transforms/Utils/Local.cpp | 1 -
4 files changed, 5 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp
index 9865816e36959..0723598342c23 100644
--- a/llvm/lib/IR/AutoUpgrade.cpp
+++ b/llvm/lib/IR/AutoUpgrade.cpp
@@ -5089,7 +5089,6 @@ static Value *upgradeAMDGCNIntrinsicCall(StringRef Name, CallBase *CI,
NewCall->setTailCallKind(cast<CallInst>(CI)->getTailCallKind());
NewCall->setCallingConv(CI->getCallingConv());
NewCall->setAttributes(CI->getAttributes());
- NewCall->setDebugLoc(CI->getDebugLoc());
NewCall->copyMetadata(*CI);
return NewCall;
};
@@ -5146,7 +5145,6 @@ static Value *upgradeAMDGCNIntrinsicCall(StringRef Name, CallBase *CI,
NewCall->setTailCallKind(cast<CallInst>(CI)->getTailCallKind());
NewCall->setCallingConv(CI->getCallingConv());
NewCall->setAttributes(CI->getAttributes());
- NewCall->setDebugLoc(CI->getDebugLoc());
NewCall->copyMetadata(*CI);
NewCall->takeName(CI);
return NewCall;
diff --git a/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp b/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp
index 2ad87d8d068ad..244c0343960a2 100644
--- a/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp
+++ b/llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp
@@ -57,7 +57,6 @@ static bool lowerAllocas(Function &F) {
auto *LocalAlloca = new AllocaInst(AI->getAllocatedType(),
ADDRESS_SPACE_LOCAL, AI->getArraySize(),
AI->getAlign(), "", AI->getIterator());
- LocalAlloca->setDebugLoc(AI->getDebugLoc());
LocalAlloca->copyMetadata(*AI);
LocalAlloca->setUsedWithInAlloca(AI->isUsedWithInAlloca());
LocalAlloca->setSwiftError(AI->isSwiftError());
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 6aa33b0821f10..b877f79a000cf 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -77,6 +77,7 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Intrinsics.h"
+#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PassManager.h"
@@ -1836,12 +1837,11 @@ Instruction *InstCombinerImpl::FoldOpIntoSelect(Instruction &Op, SelectInst *SI,
SelectInst *NewSel = SelectInst::Create(SI->getCondition(), NewTV, NewFV);
- // Preserve metadata that remains valid for the transformed select.
+ // Preserve metadata that remains valid for the transformed select including
+ // source location information.
NewSel->copyMetadata(*SI,
- {LLVMContext::MD_prof, LLVMContext::MD_unpredictable});
-
- // Preserve source location information.
- NewSel->setDebugLoc(SI->getDebugLoc());
+ {LLVMContext::MD_prof, LLVMContext::MD_unpredictable,
+ LLVMContext::MD_dbg});
return NewSel;
}
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 29bd7c4dba51e..717765ca03b42 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -2601,7 +2601,6 @@ CallInst *llvm::createCallMatchingInvoke(InvokeInst *II) {
II->getCalledOperand(), Args, OpBundles);
NewCall->setCallingConv(II->getCallingConv());
NewCall->setAttributes(II->getAttributes());
- NewCall->setDebugLoc(II->getDebugLoc());
NewCall->copyMetadata(*II);
// If the invoke had profile metadata, try converting them for CallInst.
More information about the llvm-commits
mailing list