[llvm] [GlobalISel] Handle div-by-pow2 (PR #83155)
Kai Nacke via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 27 13:08:10 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:
`sdiv_by_pow2` matches a true subset of `sdiv_by_const`. Is there some guarantee which rules matches?
The SelectionDAG pattern matcher uses lexcial order, which can be influenced with a priority. I did not see anything about it in the [docs](https://llvm.org/docs/GlobalISel/MIRPatterns.html), but I may have overlooked it.
https://github.com/llvm/llvm-project/pull/83155
More information about the llvm-commits
mailing list