[llvm] [PowerPC] Fix vector_shuffle combines when inputs are scalar_to_vector of differing types. (PR #80784)

zhijian lin via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 10 13:51:58 PDT 2024


================
@@ -15371,33 +15381,52 @@ SDValue PPCTargetLowering::combineVectorShuffle(ShuffleVectorSDNode *SVN,
     // the value into element zero. Since scalar size of LHS and RHS may differ
     // after isScalarToVec, this should be checked using their own sizes.
     if (SToVLHS) {
-      if (!IsLittleEndian && SToVLHS.getValueType().getScalarSizeInBits() >= 64)
+      int LHSScalarSize = SToVLHS.getValueType().getScalarSizeInBits();
+      if (!IsLittleEndian && LHSScalarSize >= 64)
         return Res;
       // Set up the values for the shuffle vector fixup.
-      LHSMaxIdx = NumEltsOut / NumEltsIn;
+      LHSNumValidElts =
+          LHSScalarSize / LHS.getValueType().getScalarSizeInBits();
+      // The last element that comes from the LHS. For example:
+      // (shuff (s_to_v i32), (bitcast (s_to_v i64), v4i32), ...)
+      // The last element that comes from the LHS is actually 0, not 3
+      // because elements 1 and higher of a scalar_to_vector are undefined.
+      LHSLastElt = LHSScalarSize / (ShuffleEltWidth + 1);
----------------
diggerlin wrote:

not sure why `ShuffleEltWidth + 1` in `LHSLastElt = LHSScalarSize / (ShuffleEltWidth + 1); ` , can you explain it ?

https://github.com/llvm/llvm-project/pull/80784


More information about the llvm-commits mailing list