[llvm] Add an all-in-one histogram intrinsic, along with lowering for AArch64 (PR #88106)

Paschalis Mpeis via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 24 10:06:12 PDT 2024


================
@@ -6673,6 +6677,56 @@ SDValue AArch64TargetLowering::LowerOperation(SDValue Op,
     return LowerFunnelShift(Op, DAG);
   case ISD::FLDEXP:
     return LowerFLDEXP(Op, DAG);
+  case ISD::EXPERIMENTAL_HISTOGRAM: {
+    // FIXME: Move to another function.
+    // FIXME: Maybe share some code with LowerMGather/Scatter?
+    MaskedHistogramSDNode *HG = cast<MaskedHistogramSDNode>(Op);
+    SDLoc DL(HG);
+    SDValue Chain = HG->getOperand(0);
+    SDValue Inc = HG->getOperand(1);
+    SDValue Mask = HG->getOperand(2);
+    SDValue Ptr = HG->getOperand(3);
+    SDValue Index = HG->getOperand(4);
+    SDValue Scale = HG->getOperand(5);
+
+    EVT IncVT = Inc.getValueType();
+    EVT IndexVT = Index.getValueType();
+    EVT MemVT = EVT::getVectorVT(*DAG.getContext(), IncVT,
+                                 IndexVT.getVectorElementCount());
+    SDValue Zero = DAG.getConstant(0, DL, MVT::i64);
+    SDValue PassThru = DAG.getSplatVector(MemVT, DL, Zero);
+    SDValue IncSplat = DAG.getSplatVector(MemVT, DL, Inc);
+    SDValue Ops[] = {Chain, PassThru, Mask, Ptr, Index, Scale};
+
+    // Set the MMO to load only, rather than load|store.
+    MachineMemOperand *GMMO = HG->getMemOperand();
+    GMMO->setFlags(MachineMemOperand::MOLoad);
+    ISD::MemIndexType IndexType = HG->getIndexType();
+    SDValue Gather =
+                DAG.getMaskedGather(DAG.getVTList(MemVT, MVT::Other), MemVT, DL,
+                                    Ops, HG->getMemOperand(),
----------------
paschalis-mpeis wrote:

nit: maybe can reuse `GMMO` here?

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


More information about the llvm-commits mailing list