Index: llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h =================================================================== --- llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h +++ llvm/include/llvm/CodeGen/GlobalISel/MIPatternMatch.h @@ -90,6 +90,22 @@ } ///} +struct ICstRegMatch { + Register &CR; + ICstRegMatch(Register &C) : CR(C) {} + bool match(const MachineRegisterInfo &MRI, Register Reg) { + if (auto MaybeCst = getConstantVRegValWithLookThrough( + Reg, MRI, /*LookThroughInstrs*/ true, + /*HandleFConstants*/ false)) { + CR = MaybeCst->VReg; + return true; + } + return false; + } +}; + +inline ICstRegMatch m_ICst(Register &Reg) { return ICstRegMatch(Reg); } + // TODO: Rework this for different kinds of MachineOperand. // Currently assumes the Src for a match is a register. // We might want to support taking in some MachineOperands and call getReg on