[PATCH] D103441: [SLP] Avoid std::stable_sort(properlyDominates()).

Harald van Dijk via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 1 01:42:37 PDT 2021


hvdijk created this revision.
hvdijk added reviewers: ABataev, RKSimon.
Herald added subscribers: mgrang, hiraditya.
hvdijk requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

As noticed by NAKAMURA Takumi back in 2017, we cannot use
properlyDominates for std::stable_sort as properlyDominates only
partially orders blocks. That is, for blocks A, B, C, D, where A
dominates B and C dominates D, we have A == C, B == C, but A < B. This
is not a valid comparison function for std::stable_sort and causes
different results between libstdc++ and libc++.

This change uses DFS numbering to give deterministic results for all
reachable blocks. Unreachable blocks are not found by DFS and cannot be
compared this way, but as the existing test unreachable.ll shows, we
should be doing more work to avoid entering unreachable blocks anyway:
we should not stop vectorization just because a PHI incoming value from
an unreachable block cannot be vectorized. We know that particular value
will never be used so we can just replace it with poison.

Fixes bug 50409.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D103441

Files:
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
  llvm/test/Transforms/SLPVectorizer/X86/ordering-bug.ll
  llvm/test/Transforms/SLPVectorizer/X86/unreachable.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D103441.348904.patch
Type: text/x-patch
Size: 7988 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210601/54fefa0d/attachment.bin>


More information about the llvm-commits mailing list