[llvm] [IR] Remove unnecessary setDebugLoc calls. NFCI. (PR #218663)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 25 04:57:27 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
@llvm/pr-subscribers-llvm-ir
Author: Jay Foad (jayfoad)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/218663.diff
4 Files Affected:
- (modified) llvm/lib/IR/AutoUpgrade.cpp (-2)
- (modified) llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp (-1)
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+5-5)
- (modified) llvm/lib/Transforms/Utils/Local.cpp (-1)
``````````diff
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.
``````````
</details>
https://github.com/llvm/llvm-project/pull/218663
More information about the llvm-commits
mailing list