[llvm] [DAG] foldShiftToAvg - recognize sub(x, xor(y, -1)) >> 1 as avgceil[su] (#147946) (PR #156239)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 2 07:27:38 PDT 2025
================
@@ -16294,6 +16412,23 @@ SDValue DAGCombiner::visitTRUNCATE(SDNode *N) {
}
}
+ // trunc (avgceilu (sext (x), sext (y))) -> avgceils(x, y)
----------------
RKSimon wrote:
A couple of tests along the lines of this in hadd-combine.ll should be enough:
```
; trunc(avgceilu(sext x, sext y)) -> avgceils(x, y)
define <8 x i8> @trunc_urhadd_sext(<8 x i8> %a0, <8 x i8> %a1) {
%x0 = sext <8 x i8> %a0 to <8 x i16>
%x1 = sext <8 x i8> %a1 to <8 x i16>
%avg = call <8 x i16> @llvm.aarch64.neon.urhadd.v8i16(<8 x i16> %x0, <8 x i16> %x1)
%res = trunc <8 x i16> %avg to <8 x i8>
ret <8 x i8> %res
}
```
You will still need an alive2 test
https://github.com/llvm/llvm-project/pull/156239
More information about the llvm-commits
mailing list