[llvm] [GlobalISel] Combine (X >> C) << C to X & ((-1 >> C) << C) (PR #114821)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 11:30:48 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;
----------------
arsenm wrote:

This was already matched in the pattern? Ideally we could directly pass in the constant, but failing that should just assert on the failure 

https://github.com/llvm/llvm-project/pull/114821


More information about the llvm-commits mailing list