Skip to content

[GISel] Add LookThroughInstrs for getIConstantVRegVal and getIConstan… #68327

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions llvm/include/llvm/CodeGen/GlobalISel/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions llvm/lib/CodeGen/GlobalISel/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down