[llvm] d3e66a8 - [VectorCombine] foldBitcastShuf - compute scale factors using shuffle type element size instead of element count. NFCI.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 11:06:01 PDT 2023


Author: Simon Pilgrim
Date: 2023-10-05T18:58:36+01:00
New Revision: d3e66a88c2c5ceb8b3cb3f4bdd2e914e4f3e468a

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

LOG: [VectorCombine] foldBitcastShuf - compute scale factors using shuffle type element size instead of element count. NFCI.

First step towards supporting length changing shuffles

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 9b9aaa22a71c6be..286120ed534b776 100644
--- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
+++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp
@@ -696,20 +696,20 @@ bool VectorCombine::foldBitcastShuf(Instruction &I) {
     return false;
 
   auto *DestTy = cast<FixedVectorType>(I.getType());
-  unsigned DestNumElts = DestTy->getNumElements();
-  unsigned SrcNumElts = SrcTy->getNumElements();
+  unsigned DestEltSize = DestTy->getScalarSizeInBits();
+  unsigned SrcEltSize = SrcTy->getScalarSizeInBits();
   SmallVector<int, 16> NewMask;
-  if (SrcNumElts <= DestNumElts) {
+  if (DestEltSize <= SrcEltSize) {
     // The bitcast is from wide to narrow/equal elements. The shuffle mask can
     // always be expanded to the equivalent form choosing narrower elements.
-    assert(DestNumElts % SrcNumElts == 0 && "Unexpected shuffle mask");
-    unsigned ScaleFactor = DestNumElts / SrcNumElts;
+    assert(SrcEltSize % DestEltSize == 0 && "Unexpected shuffle mask");
+    unsigned ScaleFactor = SrcEltSize / DestEltSize;
     narrowShuffleMaskElts(ScaleFactor, Mask, NewMask);
   } else {
     // The bitcast is from narrow elements to wide elements. The shuffle mask
     // must choose consecutive elements to allow casting first.
-    assert(SrcNumElts % DestNumElts == 0 && "Unexpected shuffle mask");
-    unsigned ScaleFactor = SrcNumElts / DestNumElts;
+    assert(DestEltSize % SrcEltSize == 0 && "Unexpected shuffle mask");
+    unsigned ScaleFactor = DestEltSize / SrcEltSize;
     if (!widenShuffleMaskElts(ScaleFactor, Mask, NewMask))
       return false;
   }


        


More information about the llvm-commits mailing list