[llvm] [GISel] Return const APInt & from getIConstantFromReg. NFC (PR #114320)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 30 15:56:59 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-globalisel
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
This matches what the call to ConstantInt::getValue returns. Let the caller make a copy if needed.
---
Full diff: https://github.com/llvm/llvm-project/pull/114320.diff
2 Files Affected:
- (modified) llvm/include/llvm/CodeGen/GlobalISel/Utils.h (+1-1)
- (modified) llvm/lib/CodeGen/GlobalISel/Utils.cpp (+1-1)
``````````diff
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
index 4016247376c4f6..37653631cc2388 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
@@ -180,7 +180,7 @@ std::optional<int64_t> getIConstantVRegSExtVal(Register VReg,
const MachineRegisterInfo &MRI);
/// \p VReg is defined by a G_CONSTANT, return the corresponding value.
-APInt getIConstantFromReg(Register VReg, const MachineRegisterInfo &MRI);
+const APInt &getIConstantFromReg(Register VReg, const MachineRegisterInfo &MRI);
/// Simple struct used to hold a constant integer value and a virtual
/// register.
diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index dcbbb0871a8445..549cba02bbdd6f 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -287,7 +287,7 @@ std::optional<APInt> llvm::getIConstantVRegVal(Register VReg,
return ValAndVReg->Value;
}
-APInt llvm::getIConstantFromReg(Register Reg, const MachineRegisterInfo &MRI) {
+const APInt &llvm::getIConstantFromReg(Register Reg, const MachineRegisterInfo &MRI) {
MachineInstr *Const = MRI.getVRegDef(Reg);
assert((Const && Const->getOpcode() == TargetOpcode::G_CONSTANT) &&
"expected a G_CONSTANT on Reg");
``````````
</details>
https://github.com/llvm/llvm-project/pull/114320
More information about the llvm-commits
mailing list