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

via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 20 08:57:50 PST 2024


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 71b87d12678cbdb900c3a8fb673dcaf14d0433be dc3dba57e8cd76191ba03270d512f9931d4f4600 --extensions h,cpp -- llvm/include/llvm/CodeGen/TargetLowering.h llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/Target/AArch64/AArch64ISelLowering.cpp llvm/lib/Target/AArch64/AArch64ISelLowering.h
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 0338310fd9..51e716f508 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -468,8 +468,10 @@ public:
     return true;
   }
 
-  /// Return true if the @llvm.experimental.get.alias.lane.mask intrinsic should be expanded using generic code in SelectionDAGBuilder.
-  virtual bool shouldExpandGetAliasLaneMask(EVT VT, EVT PtrVT, unsigned EltSize) const {
+  /// Return true if the @llvm.experimental.get.alias.lane.mask intrinsic should
+  /// be expanded using generic code in SelectionDAGBuilder.
+  virtual bool shouldExpandGetAliasLaneMask(EVT VT, EVT PtrVT,
+                                            unsigned EltSize) const {
     return true;
   }
 
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 39e84e06a8..f942ab0514 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -8288,17 +8288,19 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
     SDValue SourceValue = getValue(I.getOperand(0));
     SDValue SinkValue = getValue(I.getOperand(1));
     SDValue EltSize = getValue(I.getOperand(2));
-    bool IsWriteAfterRead = cast<ConstantSDNode>(getValue(I.getOperand(3)))->getZExtValue() != 0;
+    bool IsWriteAfterRead =
+        cast<ConstantSDNode>(getValue(I.getOperand(3)))->getZExtValue() != 0;
     auto IntrinsicVT = EVT::getEVT(I.getType());
     auto PtrVT = SourceValue->getValueType(0);
 
-    if (!TLI.shouldExpandGetAliasLaneMask(IntrinsicVT, PtrVT, cast<ConstantSDNode>(EltSize)->getSExtValue())) {
+    if (!TLI.shouldExpandGetAliasLaneMask(
+            IntrinsicVT, PtrVT,
+            cast<ConstantSDNode>(EltSize)->getSExtValue())) {
       visitTargetIntrinsic(I, Intrinsic);
       return;
     }
 
-    SDValue Diff = DAG.getNode(ISD::SUB, sdl,
-                              PtrVT, SinkValue, SourceValue);
+    SDValue Diff = DAG.getNode(ISD::SUB, sdl, PtrVT, SinkValue, SourceValue);
     if (!IsWriteAfterRead)
       Diff = DAG.getNode(ISD::ABS, sdl, PtrVT, Diff);
 
@@ -8306,9 +8308,10 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
     SDValue Zero = DAG.getTargetConstant(0, sdl, PtrVT);
 
     // If the difference is positive then some elements may alias
-    auto CmpVT = TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(),
-                                   PtrVT);
-    SDValue Cmp = DAG.getSetCC(sdl, CmpVT, Diff, Zero, IsWriteAfterRead ? ISD::SETLE : ISD::SETEQ);
+    auto CmpVT =
+        TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), PtrVT);
+    SDValue Cmp = DAG.getSetCC(sdl, CmpVT, Diff, Zero,
+                               IsWriteAfterRead ? ISD::SETLE : ISD::SETEQ);
 
     // Splat the compare result then OR it with a lane mask
     SDValue Splat = DAG.getSplat(IntrinsicVT, sdl, Cmp);
@@ -8316,14 +8319,17 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
     SDValue DiffMask;
     // Don't emit an active lane mask if the target doesn't support it
     if (TLI.shouldExpandGetActiveLaneMask(IntrinsicVT, PtrVT)) {
-        EVT VecTy = EVT::getVectorVT(*DAG.getContext(), PtrVT,
-                                     IntrinsicVT.getVectorElementCount());
-        SDValue DiffSplat = DAG.getSplat(VecTy, sdl, Diff);
-        SDValue VectorStep = DAG.getStepVector(sdl, VecTy);
-        DiffMask = DAG.getSetCC(sdl, IntrinsicVT, VectorStep,
-                                     DiffSplat, ISD::CondCode::SETULT);
+      EVT VecTy = EVT::getVectorVT(*DAG.getContext(), PtrVT,
+                                   IntrinsicVT.getVectorElementCount());
+      SDValue DiffSplat = DAG.getSplat(VecTy, sdl, Diff);
+      SDValue VectorStep = DAG.getStepVector(sdl, VecTy);
+      DiffMask = DAG.getSetCC(sdl, IntrinsicVT, VectorStep, DiffSplat,
+                              ISD::CondCode::SETULT);
     } else {
-      DiffMask = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, sdl, IntrinsicVT, DAG.getTargetConstant(Intrinsic::get_active_lane_mask, sdl, MVT::i64), Zero, Diff);
+      DiffMask = DAG.getNode(
+          ISD::INTRINSIC_WO_CHAIN, sdl, IntrinsicVT,
+          DAG.getTargetConstant(Intrinsic::get_active_lane_mask, sdl, MVT::i64),
+          Zero, Diff);
     }
     SDValue Or = DAG.getNode(ISD::OR, sdl, IntrinsicVT, DiffMask, Splat);
     setValue(&I, Or);
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index 66eaec0d5a..020635400e 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -2033,7 +2033,8 @@ bool AArch64TargetLowering::shouldExpandGetActiveLaneMask(EVT ResVT,
   return false;
 }
 
-bool AArch64TargetLowering::shouldExpandGetAliasLaneMask(EVT VT, EVT PtrVT, unsigned EltSize) const {
+bool AArch64TargetLowering::shouldExpandGetAliasLaneMask(
+    EVT VT, EVT PtrVT, unsigned EltSize) const {
   if (!Subtarget->hasSVE2())
     return true;
 
@@ -2042,7 +2043,7 @@ bool AArch64TargetLowering::shouldExpandGetAliasLaneMask(EVT VT, EVT PtrVT, unsi
 
   if (VT == MVT::v2i1 || VT == MVT::nxv2i1)
     return EltSize != 8;
-  if( VT == MVT::v4i1 || VT == MVT::nxv4i1)
+  if (VT == MVT::v4i1 || VT == MVT::nxv4i1)
     return EltSize != 4;
   if (VT == MVT::v8i1 || VT == MVT::nxv8i1)
     return EltSize != 2;
@@ -5905,12 +5906,14 @@ SDValue AArch64TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
   case Intrinsic::aarch64_sve_whilewr_h:
   case Intrinsic::aarch64_sve_whilewr_s:
   case Intrinsic::aarch64_sve_whilewr_d:
-    return DAG.getNode(AArch64ISD::WHILEWR, dl, Op.getValueType(), Op.getOperand(1), Op.getOperand(2));
+    return DAG.getNode(AArch64ISD::WHILEWR, dl, Op.getValueType(),
+                       Op.getOperand(1), Op.getOperand(2));
   case Intrinsic::aarch64_sve_whilerw_b:
   case Intrinsic::aarch64_sve_whilerw_h:
   case Intrinsic::aarch64_sve_whilerw_s:
   case Intrinsic::aarch64_sve_whilerw_d:
-    return DAG.getNode(AArch64ISD::WHILERW, dl, Op.getValueType(), Op.getOperand(1), Op.getOperand(2));
+    return DAG.getNode(AArch64ISD::WHILERW, dl, Op.getValueType(),
+                       Op.getOperand(1), Op.getOperand(2));
   case Intrinsic::aarch64_neon_abs: {
     EVT Ty = Op.getValueType();
     if (Ty == MVT::i64) {
@@ -6377,34 +6380,38 @@ SDValue AArch64TargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
       uint64_t EltSize = Op.getOperand(3)->getAsZExtVal();
       bool IsWriteAfterRead = Op.getOperand(4)->getAsZExtVal() == 1;
       switch (EltSize) {
-        case 1:
-          IntrinsicID = IsWriteAfterRead ? Intrinsic::aarch64_sve_whilewr_b : Intrinsic::aarch64_sve_whilerw_b;
-          break;
-        case 2:
-          IntrinsicID = IsWriteAfterRead ? Intrinsic::aarch64_sve_whilewr_h : Intrinsic::aarch64_sve_whilerw_h;
-          break;
-        case 4:
-          IntrinsicID = IsWriteAfterRead ? Intrinsic::aarch64_sve_whilewr_s : Intrinsic::aarch64_sve_whilerw_s;
-          break;
-        case 8:
-          IntrinsicID = IsWriteAfterRead ? Intrinsic::aarch64_sve_whilewr_d : Intrinsic::aarch64_sve_whilerw_d;
-          break;
-        default:
-          llvm_unreachable("Unexpected element size for get.alias.lane.mask");
-          break;
+      case 1:
+        IntrinsicID = IsWriteAfterRead ? Intrinsic::aarch64_sve_whilewr_b
+                                       : Intrinsic::aarch64_sve_whilerw_b;
+        break;
+      case 2:
+        IntrinsicID = IsWriteAfterRead ? Intrinsic::aarch64_sve_whilewr_h
+                                       : Intrinsic::aarch64_sve_whilerw_h;
+        break;
+      case 4:
+        IntrinsicID = IsWriteAfterRead ? Intrinsic::aarch64_sve_whilewr_s
+                                       : Intrinsic::aarch64_sve_whilerw_s;
+        break;
+      case 8:
+        IntrinsicID = IsWriteAfterRead ? Intrinsic::aarch64_sve_whilewr_d
+                                       : Intrinsic::aarch64_sve_whilerw_d;
+        break;
+      default:
+        llvm_unreachable("Unexpected element size for get.alias.lane.mask");
+        break;
       }
     }
-    SDValue ID =
-        DAG.getTargetConstant(IntrinsicID, dl, MVT::i64);
+    SDValue ID = DAG.getTargetConstant(IntrinsicID, dl, MVT::i64);
 
     EVT VT = Op.getValueType();
     if (VT.isScalableVector())
       return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, ID, Op.getOperand(1),
                          Op.getOperand(2));
 
-    // We can use the SVE whilelo/whilewr/whilerw instruction to lower this intrinsic by
-    // creating the appropriate sequence of scalable vector operations and
-    // then extracting a fixed-width subvector from the scalable vector.
+    // We can use the SVE whilelo/whilewr/whilerw instruction to lower this
+    // intrinsic by creating the appropriate sequence of scalable vector
+    // operations and then extracting a fixed-width subvector from the scalable
+    // vector.
 
     EVT ContainerVT = getContainerForFixedLengthVector(DAG, VT);
     EVT WhileVT = ContainerVT.changeElementType(MVT::i1);
@@ -19544,7 +19551,8 @@ static bool isPredicateCCSettingOp(SDValue N) {
         // get_active_lane_mask is lowered to a whilelo instruction.
         N.getConstantOperandVal(0) == Intrinsic::get_active_lane_mask ||
         // get_alias_lane_mask is lowered to a whilewr/rw instruction.
-        N.getConstantOperandVal(0) == Intrinsic::experimental_get_alias_lane_mask)))
+        N.getConstantOperandVal(0) ==
+            Intrinsic::experimental_get_alias_lane_mask)))
     return true;
 
   return false;
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.h b/llvm/lib/Target/AArch64/AArch64ISelLowering.h
index b2f766b229..41f5634921 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.h
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.h
@@ -984,7 +984,8 @@ public:
 
   bool shouldExpandGetActiveLaneMask(EVT VT, EVT OpVT) const override;
 
-  bool shouldExpandGetAliasLaneMask(EVT VT, EVT PtrVT, unsigned EltSize) const override;
+  bool shouldExpandGetAliasLaneMask(EVT VT, EVT PtrVT,
+                                    unsigned EltSize) const override;
 
   bool
   shouldExpandPartialReductionIntrinsic(const IntrinsicInst *I) const override;

``````````

</details>


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


More information about the llvm-commits mailing list