[llvm] [GlobalISel] Combine (X >> C) << C to X & ((-1 >> C) << C) (PR #114821)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 5 11:58:19 PST 2024
================
@@ -1983,6 +1983,41 @@ void CombinerHelper::applyShiftOfShiftedLogic(MachineInstr &MI,
MI.eraseFromParent();
}
+bool CombinerHelper::matchLsbClearByShifts(MachineInstr &MI,
+ BuildFnTy &MatchInfo) {
+ // fold (A >> C) << C to A & K, where K = (-1 >> C) << C
+ const GShl *Shl = cast<GShl>(&MI);
+ GLShr *Lshr = cast<GLShr>(MRI.getVRegDef(Shl->getSrcReg()));
+
+ if (!MRI.hasOneNonDBGUse(Lshr->getReg(0)))
+ return false;
+
+ APInt C1, C2;
+ if (!mi_match(Shl->getShiftReg(), MRI, m_ICstOrSplat(C1)) ||
+ !mi_match(Lshr->getShiftReg(), MRI, m_ICstOrSplat(C2)))
+ return false;
----------------
tschuett wrote:
You can use `getIConstantFromReg`.
https://github.com/llvm/llvm-project/pull/114821
More information about the llvm-commits
mailing list