[llvm] [RISCV] Combine a gather to a larger element type (PR #66694)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 18 15:31:55 PDT 2023


================
@@ -14020,6 +14066,33 @@ SDValue RISCVTargetLowering::PerformDAGCombine(SDNode *N,
         DAG.getVectorShuffle(VT, DL, Load, DAG.getUNDEF(VT), ShuffleMask);
       return DAG.getMergeValues({Shuffle, Load.getValue(1)}, DL);
     }
+
+    if (MGN->getExtensionType() == ISD::NON_EXTLOAD &&
+        matchIndexAsWiderOp(VT, Index, MGN->getMask(),
+                            MGN->getMemOperand()->getBaseAlign(), Subtarget)) {
+      SmallVector<SDValue> NewIndices;
+      for (unsigned i = 0; i < Index->getNumOperands(); i += 2)
+        NewIndices.push_back(Index.getOperand(i));
+      EVT IndexVT = Index.getValueType()
+        .getHalfNumVectorElementsVT(*DAG.getContext());
+      Index = DAG.getBuildVector(IndexVT, DL, NewIndices);
+
+      unsigned ElementSize = VT.getScalarStoreSize();
+      EVT WideScalarVT = MVT::getIntegerVT(ElementSize * 8 * 2);
+      EVT WideVT = VT.changeVectorElementType(WideScalarVT)
----------------
topperc wrote:

That doesn't help. VT already is an EVT, but EVT internally is an MVT or a Type*. The constructor uses MVT when possible.

You can use roughly `EVT::getVectorVT(*DAG.getContext(), WideScalarVT, VT.getVectorElementCount())`.

Or we should add a context argument to changeVectorElementType. I'm tired of finding this bug.

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


More information about the llvm-commits mailing list