[PATCH] D115329: [LoopVectorize] Pass a vector type to isLegalMaskedGather/Scatter

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 13 08:34:28 PST 2021


lebedev.ri added a comment.

In D115329#3189215 <https://reviews.llvm.org/D115329#3189215>, @sdesmalen wrote:

> In D115329#3188963 <https://reviews.llvm.org/D115329#3188963>, @lebedev.ri wrote:
>
>> The fact that something is/isn't legal does not mean that LV will pick *that* particular path.
>> It merely allows LV to consider this path, among the others,
>> and out of all the legal paths, pick the most profitable one.
>
> The LV makes the decision to use gathers/scatters because the cost-model said the gather/scatter cost was lower than the scalarization cost, but that only works if the gather/scatter cost is correct. If it will be scalarized, then I'd expect this costs to be no different than the scalarization cost.

If the cost model is wrong then lots of weird shit will go wrong, yes.

>> We don't "trick LV to think it's legal and then scalarize anyway", it *is* legal.
>
> I'm not sure what the meaning of "legal" is in that case.

That the gather with VF=2 can be done by the same instruction as for the VF=4, but after padding the mask with zeros.

> My understanding of the term is that it means that the target can handle the operation directly without legalization, e.g. using a special instruction or a sequence of instructions.



> From that perspective, saying that <operation> is legal, means it will not need to be scalarized.

Define "need".
It is not much different from what VectorCombine does ("would scalar cost be lower than vector cost?
if so, scalarize" or the other way around), just implemented in an another pass.

> (conversely, the ScalarizeMaskedOperations pass only scalarizes the intrinsic if it is *not* marked as legal).  If the LV asks the question "is a masked gather operation legal?" and it returns `true`, it seems wrong to me to query the cost as if it were a gather rather than asking for the scalarization cost, but then later still decide to scalarize the operation.



>> But for those particular VF's, it's more costly than the native scalarized path.
>> So LV won't actually produce gather intrinsics, and naturally, they won't be scalarized.
>>
>> Furthermore, no, while we could just always prefer the intrinsics (from correctness viewpoint),
>> that is detrimental to the performance. See e.g. my recent patches, namely D111220 <https://reviews.llvm.org/D111220> / D111363 <https://reviews.llvm.org/D111363> / D111546 <https://reviews.llvm.org/D111546>.
>
> This is the answer I was after, thanks for pointing me to those patches!

Cheers.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115329/new/

https://reviews.llvm.org/D115329



More information about the llvm-commits mailing list