[DAGCombine] matchBinOpReduction - add partial reduction matching
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 24 Jul 2019 17:29:56 +0000 (17:29 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 24 Jul 2019 17:29:56 +0000 (17:29 +0000)
commit7d318b2bb19771745021145730387d43c589a9a7
treea59494cc301db6c25566ca4c9538a9d323ab388e
parente8bffd3ff0289cd317d457e2562e130729c3b8d2
[DAGCombine] matchBinOpReduction - add partial reduction matching

This patch adds support for recognizing cases where a larger vector type is being used to reduce just the elements in the lower subvector:

e.g. <8 x i32> reduction pattern in a <16 x i32> vector:

<4,5,6,7,u,u,u,u,u,u,u,u,u,u,u,u>
<2,3,u,u,u,u,u,u,u,u,u,u,u,u,u,u>
<1,u,u,u,u,u,u,u,u,u,u,u,u,u,u,u>

matchBinOpReduction returns the lower extracted subvector in such cases, assuming isExtractSubvectorCheap accepts the extraction.

I've only enabled it for X86 reduction sums so far. I intend to enable it for the bitop/minmax cases in future patches, and eventually I think its worth turning it on all the time. This is mainly just a case of ensuring calls to matchBinOpReduction don't make assumptions on the vector width based on the original vector extraction.

Fixes the x86 partial reduction sum cases in PR33758 and PR42023.

Differential Revision: https://reviews.llvm.org/D65047

llvm-svn: 366933
llvm/include/llvm/CodeGen/SelectionDAG.h
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/Target/X86/X86ISelLowering.cpp
llvm/test/CodeGen/X86/phaddsub-extract.ll