[llvm] [Intrinsics][AArch64] Add intrinsic to mask off aliasing vector lanes (PR #117007)

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 07:22:14 PDT 2025


================
@@ -1768,6 +1775,46 @@ SDValue VectorLegalizer::ExpandVP_FCOPYSIGN(SDNode *Node) {
   return DAG.getNode(ISD::BITCAST, DL, VT, CopiedSign);
 }
 
+SDValue VectorLegalizer::ExpandLOOP_DEPENDENCE_MASK(SDNode *N) {
+  SDLoc DL(N);
+  SDValue SourceValue = N->getOperand(0);
+  SDValue SinkValue = N->getOperand(1);
+  SDValue EltSize = N->getOperand(2);
+
+  bool IsWriteAfterRead =
+      N->getOpcode() == ISD::EXPERIMENTAL_LOOP_DEPENDENCE_WAR_MASK;
+  auto VT = N->getValueType(0);
+  auto PtrVT = SourceValue->getValueType(0);
+
+  SDValue Diff = DAG.getNode(ISD::SUB, DL, PtrVT, SinkValue, SourceValue);
+  if (!IsWriteAfterRead)
+    Diff = DAG.getNode(ISD::ABS, DL, PtrVT, Diff);
+
+  Diff = DAG.getNode(ISD::SDIV, DL, PtrVT, Diff, EltSize);
+
+  // If the difference is positive then some elements may alias
+  auto CmpVT = TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
+                                      Diff.getValueType());
+  SDValue Zero = DAG.getTargetConstant(0, DL, PtrVT);
+  SDValue Cmp = DAG.getSetCC(DL, CmpVT, Diff, Zero,
+                             IsWriteAfterRead ? ISD::SETLE : ISD::SETEQ);
+
+  // Create the lane mask
+  EVT SplatTY =
+      EVT::getVectorVT(*DAG.getContext(), PtrVT, VT.getVectorElementCount());
+  SDValue DiffSplat = DAG.getSplat(SplatTY, DL, Diff);
+  SDValue VectorStep = DAG.getStepVector(DL, SplatTY);
+  SDValue DiffMask =
+      DAG.getSetCC(DL, VT, VectorStep, DiffSplat, ISD::CondCode::SETULT);
+
+  // Splat the compare result then OR it with the lane mask
+  auto VTElementTy = VT.getVectorElementType();
----------------
SamTebbs33 wrote:

Done.

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


More information about the llvm-commits mailing list