This is an archive of the discontinued LLVM Phabricator instance.

[SLP] Fix for the min/max intrinsic cost.
ClosedPublic

Authored by vporpo on Feb 23 2022, 3:30 PM.

Details

Summary

The min/max intrinsic cost is currently too low because in the cost calculation
we subtract the cost of the vector compare as we will not emit it.
For the cost of the vector compare we are currently passing BAD_ICMP_PREDICATE
which returns 3, the worst case cost.
I think we should be passing VecPred instead, since we know the predicates of
the compare instr.

I think this is related to commit b3b993a7ad817 which introduced the predicate
argument to getCmpSelInstrCost().
https://reviews.llvm.org/rGb3b993a7ad817c3c5801341fa78f34332900eb83

Diff Detail

Event Timeline

vporpo created this revision.Feb 23 2022, 3:30 PM
vporpo requested review of this revision.Feb 23 2022, 3:30 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 23 2022, 3:30 PM
ABataev added inline comments.Feb 23 2022, 4:05 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
5361–5362

This is not correct, the original code is correct. Need to check more carefully the cause and probably fix the comment.

vporpo added inline comments.Feb 23 2022, 4:17 PM
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
5361–5362

Yeah you are right. This should subtract the cost of the vectorized compares, not the vectorized selects. Let me look into it again.

vporpo updated this revision to Diff 410980.Feb 23 2022, 5:18 PM

This looks more correct.

vporpo edited the summary of this revision. (Show Details)Feb 23 2022, 5:19 PM
vporpo added inline comments.
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
5361–5362

I think the issue was the BAD_ICMP_PREDICATE. If I understand correctly we should be using VecPred here instead.

This revision is now accepted and ready to land.Feb 23 2022, 5:30 PM
vporpo updated this revision to Diff 411237.Feb 24 2022, 2:38 PM
vporpo edited the summary of this revision. (Show Details)

Updated test.

fhahn accepted this revision.Feb 24 2022, 2:44 PM

Lgtm thanks

This revision was landed with ongoing or failed builds.Feb 24 2022, 6:29 PM
This revision was automatically updated to reflect the committed changes.