This is an archive of the discontinued LLVM Phabricator instance.

[LV] Freeze start value for select-reductions.
Needs ReviewPublic

Authored by fhahn on Jun 24 2023, 3:46 AM.

Details

Reviewers
Ayal
gilr
rengolin
Summary

When creating select-reductions, we are introducing multiple new uses of
the reduction start value. If the start value may be undef or poison,
then differnet uses (e.g in the final select or vector compares) can
evaluate to different values, leading to incorrect results.

To avoid this, freeze the start value in the preheader by introducing a
new Freeze VPInstruction.

Depends on D153696.

Fixes #62565.

Diff Detail

Event Timeline

fhahn created this revision.Jun 24 2023, 3:46 AM
fhahn requested review of this revision.Jun 24 2023, 3:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 24 2023, 3:46 AM
Herald added a subscriber: vkmr. · View Herald Transcript
Ayal added a comment.Jun 26 2023, 4:19 AM

When creating select-reductions, we are introducing multiple new uses of
the reduction start value. If the start value may be undef or poison,
then differnet uses (e.g in the final select or vector compares) can
evaluate to different values, leading to incorrect results.

These SelectCmp reductions are essentially boolean Any reductions which should use the original reduction start value only once - at the reduction epilog, as described in https://reviews.llvm.org/D150851#4440545?
They should also use their alternative value only once, as in result = (cond(i) for any i) ? startValue : alternativeValue.
This would also reduce the size of the vectorized/unrolled "accumulator" maintained within the loop, to a minimum.