This patch is based on discussion on the llvmdev mailing list:
and also solves:
As mentioned on the dev list and bug report, the new loop on the vector register size may cause an unacceptable compile-time increase, so this may need to be shielded by some more aggressive optimization specification. If not, this patch could be extended to other SLP pattern matchers that hardcode the vector register size (see FIXME comments).
The AMDGPU XFAIL test either should be fixed or removed if it's not valid any more?