[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:47 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)))
----------------
arsenm wrote:

We really need a way to do this in tablegen 

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


More information about the llvm-commits mailing list