You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Revisit/replace priority_queue usage in sroa-hlsl #5701
TL;DR
Can we get rid of problematic std::priority_queue usage, such as in SROA?
Description std::priority_queue used in SROAGlobalAndAllocas in file lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp does not have the same behavior across C++ implementations for items that compare equal.
Observed inconsistent ordering between platforms in this case has been "fixed" by comparing more properties in the comparison function. However, this fix is ugly, and may not be sufficient for all cases.
We should revisit this code and reconsider whether sorting by size is needed in the first place, and whether this is the right approach if so. Could there be a cleaner, portable, stable approach?
One suggestion was to "use an llvm::SmallVector<std::pair<uint64_t,Value*> > for the work list where the uint64_t is the size. After all the elements are added to the work list a std::stable_sort should give a consistent and implementation-independent ordering." However, items are added to the worklist at various points as it's processed, which could mean a lot of extra sorting/comparison work if not careful.
The reason to sort is to lowered more memcpy into replace src with dst instead of copy of all elements.
If SROA on small struct first, when lower memcpy on the small struct, src/dst of the memcpy might be part of another big struct which need more check to make sure it is safe to replace. Now we only check the src has one use or dst has one define case.
Activity
python3kgae commentedon Sep 13, 2023
The reason to sort is to lowered more memcpy into replace src with dst instead of copy of all elements.
If SROA on small struct first, when lower memcpy on the small struct, src/dst of the memcpy might be part of another big struct which need more check to make sure it is safe to replace. Now we only check the src has one use or dst has one define case.
llvm-beanz commentedon Sep 13, 2023
We can sort without using a priority queue. We could use a SmallVector of
std::pairand sort withstd::stable_sort.