This is an archive of the discontinued LLVM Phabricator instance.

[X86] Add costs for SSE zext/sext to v4i64 to TTI
ClosedPublic

Authored by mkuper on Jun 8 2016, 3:40 PM.

Details

Summary

The costs are somewhat hand-wavy, but should be much closer to the truth - what we get from the target-independent code right now is ridiculously high.

The underlying problem seems to be that the target-independent code in BasicTTIImpl assumes that if the dest type is illegal, the operation will get completely scalarized. This is, of course, nonsense. What it should probably do is take the legalization cost + 2 * the actual cost of the extend after the split (by querying the concrete TTI on the result vector).
This problem isn't unique to casts, there's similar logic for, at least, arithmetic instructions and selects. Changing that right now seems like it would rock the boat too much, I want to see if I run into more cases like this in practice first.

Diff Detail

Event Timeline

mkuper updated this revision to Diff 60110.Jun 8 2016, 3:40 PM
mkuper retitled this revision from to [X86] Add costs for SSE zext/sext to v4i64 to TTI.
mkuper updated this object.
mkuper added reviewers: RKSimon, congh.
mkuper added a subscriber: llvm-commits.
RKSimon edited edge metadata.Jun 9 2016, 9:58 AM

Why isn't the legalization/cost scale values from getTypeLegalizationCost not working?

Because BasicTTIImpl::getCastInstrCost() doesn't even try to use it for vector sexts/zexts. It just assumes scalarization.

This is the case we fall into:

// If we are converting vectors and the operation is illegal, or
// if the vectors are legalized to different types, estimate the
// scalarization costs.
unsigned Num = Dst->getVectorNumElements();
unsigned Cost = static_cast<T *>(this)->getCastInstrCost(
    Opcode, Dst->getScalarType(), Src->getScalarType());

// Return the cost of multiple scalar invocation plus the cost of
// inserting and extracting the values.
return getScalarizationOverhead(Dst, true, true) + Num * Cost;

Changing this (and the other two places where we have the same logic) to use getTypeLegalizationCost() and query getCastInstrCost() for the legalized type was what I meant above.

RKSimon accepted this revision.Jun 10 2016, 7:18 AM
RKSimon edited edge metadata.

Thanks I get that now - please can you either add a descriptive TODO comment or raise a BZ explaining why this isn't working.

Other than that, we already have plenty of costs that are in similar situations, so LGTM.

This revision is now accepted and ready to land.Jun 10 2016, 7:18 AM
This revision was automatically updated to reflect the committed changes.