Hi all, This patch reimplements the MD patterns for the UHADD,SHADD,UHSUB,SHSUB,URHADD,SRHADD instructions using standard RTL operations rather than unspecs. The correct RTL representations involves widening the inputs before adding them and halving, followed by a truncation back to the original mode. An unfortunate wart in the patch is that we end up having very similar expanders for the intrinsics through the aarch64_h and aarch64_rhadd names and the standard names for the vector averaging optabs avg3_floor and avg3_ceil. I'd like to reuse avg3_ceil for the intrinsics builtin as well but our scheme in aarch64-simd-builtins.def and aarch64-builtins.cc makes it awkward by only allowing mappings of entries in aarch64-simd-builtins.def to: 0 - CODE_FOR_aarch64_ 1-9 - CODE_FOR_<1-9> 10 - CODE_FOR_ whereas here we want a string after the i.e. CODE_FOR_uavg3_ceil. This patch adds a bit of remapping logic in aarch64-builtins.cc before the construction of the builtin info that remaps the CODE_FOR_* definitions in aarch64-simd-builtins.def to the optab-derived ones. CODE_FOR_aarch64_srhaddv4si gets remapped to CODE_FOR_avgv4si3_ceil, for example. It's a bit specific to this case, but this solution requires the least invasive changes while avoiding having duplicate expanders just for the sake of a different pattern name. Bootstrapped and tested on aarch64-none-linux-gnu and aarch64_be-none-elf. Pushing to trunk. Thanks, Kyrill gcc/ChangeLog: * config/aarch64/aarch64-builtins.cc (VAR1): Move to after inclusion of aarch64-builtin-iterators.h. Add definition to remap shadd, uhadd, srhadd, urhadd builtin codes for standard optab ones. * config/aarch64/aarch64-simd.md (avg3_floor): Rename to... (avg3_floor): ... This. Expand to RTL codes rather than unspec. (avg3_ceil): Rename to... (avg3_ceil): ... This. Expand to RTL codes rather than unspec. (aarch64_hsub): New define_expand. (aarch64_h): Split into... (*aarch64_h_insn): ... This... (*aarch64_rhadd_insn): ... And this.