[llvm] c6b38f4 - [RISCV] Make sure we use LMUL=1 for scalar reduction input in combineBinOpToReduce

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 11 16:25:44 PST 2023


Author: Craig Topper
Date: 2023-01-11T16:24:23-08:00
New Revision: c6b38f491fb22eb5705bf30fed1ce4a14416e8fe

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

LOG: [RISCV] Make sure we use LMUL=1 for scalar reduction input in combineBinOpToReduce

We might have looked through an INSERT_SUBVECTOR to find the
vmv.s.x or vfmv.s.f. If we did the ScalarV type is no longer LMUL=1.
We need to add a new INSERT_SUBVECTOR to restore it before
creating the new reduction.

While there, use the same debug location for all of the newly created
nodes. I believe we were using multiple debug locations from the
original nodes, but changing their relative order. I don't think
we're supposed to do that.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index 860f2023e4dce..4424292f783d7 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -8170,6 +8170,7 @@ static SDValue combineBinOpToReduce(SDNode *N, SelectionDAG &DAG,
     return SDValue();
 
   SDValue ScalarV = Reduce.getOperand(2);
+  EVT ScalarVT = ScalarV.getValueType();
   if (ScalarV.getOpcode() == ISD::INSERT_SUBVECTOR &&
       ScalarV.getOperand(0)->isUndef())
     ScalarV = ScalarV.getOperand(1);
@@ -8194,15 +8195,23 @@ static SDValue combineBinOpToReduce(SDNode *N, SelectionDAG &DAG,
 
   SDValue NewStart = N->getOperand(1 - ReduceIdx);
 
+  SDLoc DL(N);
   SDValue NewScalarV =
-    lowerScalarInsert(NewStart, ScalarV.getOperand(2), ScalarV.getSimpleValueType(),
-                      SDLoc(N), DAG, Subtarget);
+      lowerScalarInsert(NewStart, ScalarV.getOperand(2),
+                        ScalarV.getSimpleValueType(), DL, DAG, Subtarget);
+
+  // If we looked through an INSERT_SUBVECTOR we need to restore it.
+  if (ScalarVT != ScalarV.getValueType())
+    NewScalarV =
+        DAG.getNode(ISD::INSERT_SUBVECTOR, DL, ScalarVT, DAG.getUNDEF(ScalarVT),
+                    NewScalarV, DAG.getConstant(0, DL, Subtarget.getXLenVT()));
+
   SDValue NewReduce =
-      DAG.getNode(Reduce.getOpcode(), SDLoc(Reduce), Reduce.getValueType(),
+      DAG.getNode(Reduce.getOpcode(), DL, Reduce.getValueType(),
                   Reduce.getOperand(0), Reduce.getOperand(1), NewScalarV,
                   Reduce.getOperand(3), Reduce.getOperand(4));
-  return DAG.getNode(Extract.getOpcode(), SDLoc(Extract),
-                     Extract.getValueType(), NewReduce, Extract.getOperand(1));
+  return DAG.getNode(Extract.getOpcode(), DL, Extract.getValueType(), NewReduce,
+                     Extract.getOperand(1));
 }
 
 // Optimize (add (shl x, c0), (shl y, c1)) ->


        


More information about the llvm-commits mailing list