Skip to content

Commit 28ae42e

Browse files
[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.
1 parent dbc1b71 commit 28ae42e

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

llvm/include/llvm/CodeGen/GlobalISel/Utils.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,13 @@ void reportGISelWarning(MachineFunction &MF, const TargetPassConfig &TPC,
171171

172172
/// If \p VReg is defined by a G_CONSTANT, return the corresponding value.
173173
std::optional<APInt> getIConstantVRegVal(Register VReg,
174-
const MachineRegisterInfo &MRI);
174+
const MachineRegisterInfo &MRI,
175+
bool LookThroughInstrs = false);
175176

176177
/// If \p VReg is defined by a G_CONSTANT fits in int64_t returns it.
177178
std::optional<int64_t> getIConstantVRegSExtVal(Register VReg,
178-
const MachineRegisterInfo &MRI);
179+
const MachineRegisterInfo &MRI,
180+
bool LookThroughInstrs = false);
179181

180182
/// Simple struct used to hold a constant integer value and a virtual
181183
/// register.

llvm/lib/CodeGen/GlobalISel/Utils.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,10 @@ void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
290290
}
291291

292292
std::optional<APInt> llvm::getIConstantVRegVal(Register VReg,
293-
const MachineRegisterInfo &MRI) {
294-
std::optional<ValueAndVReg> ValAndVReg = getIConstantVRegValWithLookThrough(
295-
VReg, MRI, /*LookThroughInstrs*/ false);
293+
const MachineRegisterInfo &MRI,
294+
bool LookThroughInstrs) {
295+
std::optional<ValueAndVReg> ValAndVReg =
296+
getIConstantVRegValWithLookThrough(VReg, MRI, LookThroughInstrs);
296297
assert((!ValAndVReg || ValAndVReg->VReg == VReg) &&
297298
"Value found while looking through instrs");
298299
if (!ValAndVReg)
@@ -301,8 +302,9 @@ std::optional<APInt> llvm::getIConstantVRegVal(Register VReg,
301302
}
302303

303304
std::optional<int64_t>
304-
llvm::getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI) {
305-
std::optional<APInt> Val = getIConstantVRegVal(VReg, MRI);
305+
llvm::getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI,
306+
bool LookThroughInstrs) {
307+
std::optional<APInt> Val = getIConstantVRegVal(VReg, MRI, LookThroughInstrs);
306308
if (Val && Val->getBitWidth() <= 64)
307309
return Val->getSExtValue();
308310
return std::nullopt;

0 commit comments

Comments
 (0)