[llvm] 28ae42e - [GISel] Add LookThroughInstrs for getIConstantVRegVal and getIConstan… (#68327)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 14:52:43 PDT 2023
Author: Michael Maitland
Date: 2023-10-20T17:52:39-04:00
New Revision: 28ae42e6625154dfd164803850b15d8a0c296b94
URL: https://github.com/llvm/llvm-project/commit/28ae42e6625154dfd164803850b15d8a0c296b94
DIFF: https://github.com/llvm/llvm-project/commit/28ae42e6625154dfd164803850b15d8a0c296b94.diff
LOG: [GISel] Add LookThroughInstrs for getIConstantVRegVal and getIConstan… (#68327)
…tVRegSExtVal
The implementation of these methods uses
getIConstantVRegValWithLookThrough with LookThroughInstrs argument set
to false. By adding the optional argument to getIConstantVRegVal and
getIConstantVRegSExtVal we can take advantage of the already built look
through functionality.
Added:
Modified:
llvm/include/llvm/CodeGen/GlobalISel/Utils.h
llvm/lib/CodeGen/GlobalISel/Utils.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
index ffb6e53a0363f94..515fd5975dd144e 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
@@ -171,11 +171,13 @@ void reportGISelWarning(MachineFunction &MF, const TargetPassConfig &TPC,
/// If \p VReg is defined by a G_CONSTANT, return the corresponding value.
std::optional<APInt> getIConstantVRegVal(Register VReg,
- const MachineRegisterInfo &MRI);
+ const MachineRegisterInfo &MRI,
+ bool LookThroughInstrs = false);
/// If \p VReg is defined by a G_CONSTANT fits in int64_t returns it.
std::optional<int64_t> getIConstantVRegSExtVal(Register VReg,
- const MachineRegisterInfo &MRI);
+ const MachineRegisterInfo &MRI,
+ bool LookThroughInstrs = false);
/// 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 473c3f452f8b1d9..36de083b3174384 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -290,9 +290,10 @@ void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
}
std::optional<APInt> llvm::getIConstantVRegVal(Register VReg,
- const MachineRegisterInfo &MRI) {
- std::optional<ValueAndVReg> ValAndVReg = getIConstantVRegValWithLookThrough(
- VReg, MRI, /*LookThroughInstrs*/ false);
+ const MachineRegisterInfo &MRI,
+ bool LookThroughInstrs) {
+ std::optional<ValueAndVReg> ValAndVReg =
+ getIConstantVRegValWithLookThrough(VReg, MRI, LookThroughInstrs);
assert((!ValAndVReg || ValAndVReg->VReg == VReg) &&
"Value found while looking through instrs");
if (!ValAndVReg)
@@ -301,8 +302,9 @@ std::optional<APInt> llvm::getIConstantVRegVal(Register VReg,
}
std::optional<int64_t>
-llvm::getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI) {
- std::optional<APInt> Val = getIConstantVRegVal(VReg, MRI);
+llvm::getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI,
+ bool LookThroughInstrs) {
+ std::optional<APInt> Val = getIConstantVRegVal(VReg, MRI, LookThroughInstrs);
if (Val && Val->getBitWidth() <= 64)
return Val->getSExtValue();
return std::nullopt;
More information about the llvm-commits
mailing list