[llvm] [GISel] Fold bitreverse(shl/srl(bitreverse(x),y)) -> srl/shl(x,y) (PR #91355)
Thorsten Schütt via llvm-commits
llvm-commits at lists.llvm.org
Wed May 8 06:58:40 PDT 2024
================
@@ -323,6 +323,24 @@ def reduce_shl_of_extend : GICombineRule<
[{ return Helper.matchCombineShlOfExtend(*${mi}, ${matchinfo}); }]),
(apply [{ Helper.applyCombineShlOfExtend(*${mi}, ${matchinfo}); }])>;
+// Combine bitreverse(shl (bitreverse x), y)) -> (lshr x, y)
+def bitreverse_shl : GICombineRule<
+ (defs root:$d, build_fn_matchinfo:$matchinfo),
+ (match (G_BITREVERSE $rev, $val),
+ (G_SHL $src, $rev, $amt),
+ (G_BITREVERSE $d, $src):$mi,
+ [{ return Helper.matchBitreverseShift(*${mi}, ${matchinfo}); }]),
+ (apply [{ Helper.applyBuildFn(*${mi}, ${matchinfo}); }])>;
+
+// Combine bitreverse(lshr (bitreverse x), y)) -> (shl x, y)
+def bitreverse_lshr : GICombineRule<
+ (defs root:$d, build_fn_matchinfo:$matchinfo),
+ (match (G_BITREVERSE $rev, $val),
+ (G_LSHR $src, $rev, $amt),
+ (G_BITREVERSE $d, $src):$mi,
+ [{ return Helper.matchBitreverseShift(*${mi}, ${matchinfo}); }]),
----------------
tschuett wrote:
Instead of passing in a MachineInstr and reconstructing the pattern, you could pass in MachineOperands, e.g, d, val, amt. Then you can take the registers of the MOs, do the legality check, and build the shift.
https://github.com/llvm/llvm-project/pull/91355
More information about the llvm-commits
mailing list