[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
Tue May 7 10:54:06 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}); }]),
+  (apply [{ Helper.applyBuildFn(*${mi}, ${matchinfo}); }])>;
----------------
tschuett wrote:

Good job. If you match for G_BITREVERSE, then the combiner will jump for every G_BITREVERSE into C++ and fail in most cases.

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


More information about the llvm-commits mailing list