[llvm] [AArch64][GlobalISel] Add pre-legalizer combines for AVGFLOOR and AVGCEIL (PR #192866)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Fri May 1 10:13:28 PDT 2026
================
@@ -2300,6 +2300,60 @@ def overflow_combines: GICombineGroup<[
match_subo_no_overflow
]>;
+def any_sext: GICombinePatFrag<
+ (outs root:$root),
+ (ins $src),
+ [
+ (pattern (G_SEXT $root, $src)),
+ (pattern (G_SEXT_INREG $root, $src, $imm))
+ ]
+>;
+
+def avgfloor_u_match : GICombineRule<
+ (defs root:$dst, build_fn_matchinfo:$matchinfo),
+ (match (G_ZEXT $ext1, $x),
+ (G_ZEXT $ext2, $y),
+ (G_ADD $sum, $ext1, $ext2),
+ (G_LSHR $dst, $sum, 1):$mi,
+ [{ return Helper.matchAVGFloor(*${mi}, ${x}.getReg(), ${y}.getReg(), /*IsSigned=*/false, MRI); }]),
+ (apply [{ Helper.applyAVG(B, *${mi}, ${ext1}.getReg(), ${ext2}.getReg(), /*IsSigned=*/false, /*IsCeil=*/false); }])
+>;
+
+def avgfloor_s_match : GICombineRule<
+ (defs root:$dst, build_fn_matchinfo:$matchinfo),
+ (match (any_sext $ext1, $x),
+ (any_sext $ext2, $y),
+ (G_ADD $sum, $ext1, $ext2),
+ (G_ASHR $dst, $sum, 1):$mi,
+ [{ return Helper.matchAVGFloor(*${mi}, ${x}.getReg(), ${y}.getReg(), /*IsSigned=*/true, MRI); }]),
+ (apply [{ Helper.applyAVG(B, *${mi}, ${ext1}.getReg(), ${ext2}.getReg(), /*IsSigned=*/true, /*IsCeil=*/false); }])
+>;
+
+def avgceil_sum : GICombinePatFrag<
+ (outs root:$root),
+ (ins $ext1, $ext2),
+ [
+ (pattern (G_ADD $inner, $ext1, $ext2), (G_ADD $root, $inner, 1)),
+ (pattern (G_ADD $inner, $ext1, 1), (G_ADD $root, $inner, $ext2))
+ ]
+>;
+
+def avgceil_u_match : GICombineRule<
+ (defs root:$dst, build_fn_matchinfo:$matchinfo),
+ (match (avgceil_sum $sum, $ext1, $ext2),
----------------
davemgreen wrote:
Should this pattern match zext's too?
https://github.com/llvm/llvm-project/pull/192866
More information about the llvm-commits
mailing list