[llvm] [GlobalISel] Combine (X >> C) << C to X & ((-1 >> C) << C) (PR #114821)

Thorsten Schütt via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 5 11:56:13 PST 2024


================
@@ -365,6 +365,13 @@ def bitreverse_lshr : GICombineRule<
                                                     MRI.getType(${amt}.getReg())}}); }]),
   (apply (G_SHL $d, $val, $amt))>;
 
+def lsb_bits_clearing_by_shifts_to_and: GICombineRule<
+  (defs root:$root, build_fn_matchinfo:$matchinfo),
+  (match (G_LSHR $d, $src, $amt1),
+         (G_SHL $root, $d, $amt2):$root,
----------------
tschuett wrote:

```
 (match (G_CONSTANT $amt2, $imm2),
        (G_CONSTANT $amt, $imm),
         (G_LSHR $d, $src, $amt2),
         (G_SHL $root, $d, $amt):$root,
```
May need some tweaking to compile, but gives you an idea.

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


More information about the llvm-commits mailing list