[llvm] [GlobalISel] Add srem-by-pow2 combine to intrem_combines (PR #194673)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 08:22:33 PDT 2026


================
@@ -6103,6 +6103,58 @@ void CombinerHelper::applyUDivByPow2(MachineInstr &MI) const {
   MI.eraseFromParent();
 }
 
+/// \p Reg is known to be +/- a power of 2.
+bool CombinerHelper::matchAbsPow2(Register Reg) const {
+  // Known bits only work for positive powers of 2.
+  if (isKnownToBeAPowerOfTwo(Reg, MRI, VT))
+    return true;
+
+  // Otherwise accept any constant whose absolute value is a power of 2.
----------------
arsenm wrote:

This should probably be an option in isKnownToBeAPowerOfTwo, rather than adding a second level of analysis in one specific use 

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


More information about the llvm-commits mailing list