[llvm] [GISel] Funnel shift combiner port from SelectionDAG ISel to GlobalISel (PR #135132)

David Green via llvm-commits llvm-commits at lists.llvm.org
Sat May 17 09:43:02 PDT 2025


================
@@ -1034,20 +1034,26 @@ def funnel_shift_overshift: GICombineRule<
 >;
 
 // Transform: fshl x, z, y | shl x, y -> fshl x, z, y
+// Transform: shl x, y | fshl x, z, y  -> fshl x, z, y
+def funnel_shift_or_shift_to_funnel_shift_left_frags : GICombinePatFrag<
+  (outs root: $dst, $out1, $out2), (ins),
+  !foreach(inst, [(G_OR $dst, $out1, $out2), (G_OR $dst, $out2, $out1)], 
+           (pattern (G_FSHL $out1, $x, $z, $y), (G_SHL $out2, $x, $y), inst))>;
 def funnel_shift_or_shift_to_funnel_shift_left: GICombineRule<
   (defs root:$root), 
-  (match (G_FSHL $out1, $x, $z, $y),
-         (G_SHL $out2, $x, $y),
-         (G_OR $root, $out1, $out2)),
+  (match (funnel_shift_or_shift_to_funnel_shift_left_frags $root, $out1, $out2)),
   (apply (GIReplaceReg $root, $out1))
 >;
----------------
davemgreen wrote:

It would ideally be handled automatically by the gisel tablegen combining infrastructure (which should know that G_OR is commutative).  That sounds like a separate issue though and this looks OK to me in the meantime. It might be worth adding a comment that the lack of commutativity is why the extra pattern has been added. I was kind of surprised that this wasn't handled already.

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


More information about the llvm-commits mailing list