Index: llvm/include/llvm/CodeGen/GlobalISel/Utils.h =================================================================== --- llvm/include/llvm/CodeGen/GlobalISel/Utils.h +++ llvm/include/llvm/CodeGen/GlobalISel/Utils.h @@ -41,6 +41,7 @@ class TargetPassConfig; class TargetRegisterInfo; class TargetRegisterClass; +class ConstantInt; class ConstantFP; class APFloat; @@ -189,6 +190,8 @@ bool LookThroughInstrs = true, bool HandleFConstants = true, bool LookThroughAnyExt = false); +const ConstantInt *getConstantIntVRegVal(Register VReg, + const MachineRegisterInfo &MRI); const ConstantFP* getConstantFPVRegVal(Register VReg, const MachineRegisterInfo &MRI); Index: llvm/lib/CodeGen/GlobalISel/Utils.cpp =================================================================== --- llvm/lib/CodeGen/GlobalISel/Utils.cpp +++ llvm/lib/CodeGen/GlobalISel/Utils.cpp @@ -365,6 +365,14 @@ return ValueAndVReg{Val, VReg}; } +const ConstantInt *llvm::getConstantIntVRegVal(Register VReg, + const MachineRegisterInfo &MRI) { + MachineInstr *MI = MRI.getVRegDef(VReg); + if (MI->getOpcode() != TargetOpcode::G_CONSTANT) + return nullptr; + return MI->getOperand(1).getCImm(); +} + const ConstantFP * llvm::getConstantFPVRegVal(Register VReg, const MachineRegisterInfo &MRI) { MachineInstr *MI = MRI.getVRegDef(VReg);