[DAG] Fold Op(vecreduce(a), vecreduce(b)) into vecreduce(Op(a,b))
authorDavid Green <david.green@arm.com>
Wed, 8 Feb 2023 11:43:36 +0000 (11:43 +0000)
committerDavid Green <david.green@arm.com>
Wed, 8 Feb 2023 11:43:36 +0000 (11:43 +0000)
commit1af3f596f6c6b213cec9b3acd7099f8c4f11d0d0
tree93ce3750a19d74cf820793d895640b1b3704a985
parent665ee0cd57f92a112cf8e929d00768e282fb205a
[DAG] Fold Op(vecreduce(a), vecreduce(b)) into vecreduce(Op(a,b))

So long as the operation is reassociative, we can reassociate the double
vecreduce from for example fadd(vecreduce(a), vecreduce(b)) to
vecreduce(fadd(a,b)). This will in general save a few instructions, but some
architectures (MVE) require the opposite fold, so a shouldExpandReduction is
added to account for it. Only targets that use shouldExpandReduction will be
affected.

Differential Revision: https://reviews.llvm.org/D141870
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/lib/Target/ARM/ARMISelLowering.h
llvm/test/CodeGen/AArch64/aarch64-addv.ll
llvm/test/CodeGen/AArch64/double_reduct.ll
llvm/test/CodeGen/AArch64/sve-doublereduct.ll
llvm/test/CodeGen/AArch64/sve-fp-reduce.ll
llvm/test/CodeGen/AArch64/vecreduce-add.ll
llvm/test/CodeGen/AArch64/vecreduce-fadd.ll
llvm/test/CodeGen/RISCV/double_reduct.ll
llvm/test/CodeGen/Thumb2/mve-doublereduct.ll