[llvm] [X86] ReplaceNodeResults - truncate sub-128-bit vectors as shuffles directly (PR #83120)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 27 06:05:30 PST 2024


================
@@ -32341,20 +32341,20 @@ void X86TargetLowering::ReplaceNodeResults(SDNode *N,
       }
     }
 
-    if (128 % InBits == 0) {
+    if ((128 % InBits) == 0 && WidenVT.is128BitVector()) {
       // 128 bit and smaller inputs should avoid truncate all together and
-      // just use a build_vector that will become a shuffle.
-      // TODO: Widen and use a shuffle directly?
-      SmallVector<SDValue, 16> Ops(WidenNumElts, DAG.getUNDEF(EltVT));
-      // Use the original element count so we don't do more scalar opts than
-      // necessary.
-      for (unsigned i=0; i < MinElts; ++i) {
-        SDValue Val = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, InEltVT, In,
-                                  DAG.getIntPtrConstant(i, dl));
-        Ops[i] = DAG.getNode(ISD::TRUNCATE, dl, EltVT, Val);
-      }
-      Results.push_back(DAG.getBuildVector(WidenVT, dl, Ops));
-      return;
+      // use a shuffle.
+      if ((InEltVT.getSizeInBits() % EltVT.getSizeInBits()) == 0) {
----------------
RKSimon wrote:

EltVT should be legal already, InEltVT might not be, but we're protected as 128 must be divisible by the input vector width - I can add some legality assertions if you like?

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


More information about the llvm-commits mailing list