[llvm] 7047c47 - [VecCombine] Fix sort comparator logic in foldShuffleFromReductions

David Green via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 01:30:16 PDT 2022


Author: David Green
Date: 2022-04-29T09:30:02+01:00
New Revision: 7047c47918a6f84a2d5a1e63882f5af4cafb43a4

URL: https://github.com/llvm/llvm-project/commit/7047c47918a6f84a2d5a1e63882f5af4cafb43a4
DIFF: https://github.com/llvm/llvm-project/commit/7047c47918a6f84a2d5a1e63882f5af4cafb43a4.diff

LOG: [VecCombine] Fix sort comparator logic in foldShuffleFromReductions

I think this sort comparator was overly complex, and the windows
expensive check bot agreed, failing as it was not giving a strict weak
ordering. Change it to use the comparison of the mask values as unsigned
integers. This should sort the undef elements to the end whilst keeping
X<Y otherwise.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/VectorCombine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
index 7d6e5ed0a464..05fc8c6330c5 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -1200,9 +1200,7 @@ bool VectorCombine::foldShuffleFromReductions(Instruction &I) {
   // become a identity or concat mask. Undef elements are pushed to the end.
   SmallVector<int> ConcatMask;
   Shuffle->getShuffleMask(ConcatMask);
-  sort(ConcatMask, [](int X, int Y) {
-    return Y == UndefMaskElem ? true : (X == UndefMaskElem ? false : X < Y);
-  });
+  sort(ConcatMask, [](int X, int Y) { return (unsigned)X < (unsigned)Y; });
   bool UsesSecondVec =
       any_of(ConcatMask, [&](int M) { return M >= NumInputElts; });
   InstructionCost OldCost = TTI.getShuffleCost(


        


More information about the llvm-commits mailing list