[llvm] [GlobalISel] Handle div-by-pow2 (PR #83155)

Kai Nacke via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 27 13:28:50 PST 2024


================
@@ -1005,7 +1005,13 @@ def sdiv_by_const : GICombineRule<
    [{ return Helper.matchSDivByConst(*${root}); }]),
   (apply [{ Helper.applySDivByConst(*${root}); }])>;
 
-def intdiv_combines : GICombineGroup<[udiv_by_const, sdiv_by_const]>;
+def sdiv_by_pow2 : GICombineRule<
+  (defs root:$root),
+  (match (wip_match_opcode G_SDIV):$root,
+   [{ return Helper.matchSDivByPow2(*${root}); }]),
+  (apply [{ Helper.applySDivByPow2(*${root}); }])>;
+
+def intdiv_combines : GICombineGroup<[udiv_by_const, sdiv_by_const, sdiv_by_pow2]>;
----------------
redstar wrote:

I would prefer to have it separate, since my backend has no support for multiplying 2 numbers with the result being twice as large. Then `sdiv_by_const` results in code which is more expensive than using the `sdiv` instruction. However, `sdiv_by_pow2` is very useful (I considered to implement it myself, so thank you for working on that).
 
The matching order is a separate problem, I wonder if there are already other dependencies between rules.

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


More information about the llvm-commits mailing list