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

Alex MacLean via llvm-commits llvm-commits at lists.llvm.org
Mon May 4 09:54:13 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.
----------------
AlexMaclean wrote:

Yep, that is much cleaner, I've switched to this approach.

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


More information about the llvm-commits mailing list