[PATCH] D29727: [SLP] Fix for PR31690: Allow using of extra values in horizontal reductions.

Alexey Bataev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 9 01:30:50 PST 2017


ABataev added a comment.

In https://reviews.llvm.org/D29727#671394, @mkuper wrote:

> So, I understand you decided to vectorize the failing case, instead of bailing on it?
>  I'm not sure this is a good idea. I'm pretty sure I can craft a test-case where this will retain all of the scalar computation, in addition to performing the scalar one (e.g. have all of %x1 - %x4 as extra arguments).  If I understand this code correctly, the cost model will not get adjusted for this, so you'll end up vectorizing cases you really don't want to vectorize, just so you can perform the vector reduction.
>
> Why do you prefer not to bail?


You're not quite correct. For all extra args I'm creating a `virtual instruction` user (it is not an instruction actually, but a `MapVector<Value *, DebugLoc> ExternallyUsedValues`). In function `buildTree()` if the scalar is found in this `MapVector`, it is considered as externally used and added to the list of the externally used values with `nullptr` user (because it is not generated yet, see lines 971-977).

Each new External use registered in ExternalUses list adds a cost of `extractvalue` instruction (see function `getTreeCost()`, lines 1973-2000). So, this external use is taken into account in the cost model already.

If cost model allows vectorization with this extra `extractvalue` instruction, we start vectorization and when `extractvalue` instruction is generated, we replace the reference to extra arg in `ExternallyUsedValues MapVector` to this newly generated instruction/value (see lines 2848-2862).

After vectorization we pass all values stored in `ExternallyUsedValues MapVector` and add extra args/`extractvalue` extra args to the final reduction value (see lines 4469-4473).


https://reviews.llvm.org/D29727





More information about the llvm-commits mailing list