[PATCH] D120664: [VP] IR expansion pass for VP gather and scatter

Lorenzo Albano via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 28 08:57:36 PST 2022


loralb created this revision.
loralb added reviewers: craig.topper, frasercrmck, simoll, rogfer01, bmahjour.
Herald added a subscriber: hiraditya.
loralb requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Add `vp_gather` and `vp_scatter` expansion to unpredicated intrinsics.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120664

Files:
  llvm/lib/CodeGen/ExpandVectorPredication.cpp
  llvm/test/CodeGen/Generic/expand-vp-gather-scatter.ll


Index: llvm/test/CodeGen/Generic/expand-vp-gather-scatter.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/Generic/expand-vp-gather-scatter.ll
@@ -0,0 +1,32 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt --expandvp -S < %s | FileCheck %s
+
+declare <vscale x 1 x i64> @llvm.vp.gather.nxv1i64.nxv1p0i64(<vscale x 1 x i64*>, <vscale x 1 x i1>, i32)
+
+define <vscale x 1 x i64> @vpgather_nxv1i64(<vscale x 1 x i64*> %ptrs, <vscale x 1 x i1> %m, i32 zeroext %evl) {
+; CHECK-LABEL: @vpgather_nxv1i64(
+; CHECK-NEXT:    [[TMP1:%.*]] = call <vscale x 1 x i1> @llvm.get.active.lane.mask.nxv1i1.i32(i32 0, i32 [[EVL:%.*]])
+; CHECK-NEXT:    [[TMP2:%.*]] = and <vscale x 1 x i1> [[TMP1]], [[M:%.*]]
+; CHECK-NEXT:    [[VSCALE:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT:    [[SCALABLE_SIZE:%.*]] = mul nuw i32 [[VSCALE]], 1
+; CHECK-NEXT:    [[V1:%.*]] = call <vscale x 1 x i64> @llvm.masked.gather.nxv1i64.nxv1p0i64(<vscale x 1 x i64*> [[PTRS:%.*]], i32 1, <vscale x 1 x i1> [[TMP2]], <vscale x 1 x i64> undef)
+; CHECK-NEXT:    ret <vscale x 1 x i64> [[V1]]
+;
+  %v = call <vscale x 1 x i64> @llvm.vp.gather.nxv1i64.nxv1p0i64(<vscale x 1 x i64*> %ptrs, <vscale x 1 x i1> %m, i32 %evl)
+  ret <vscale x 1 x i64> %v
+}
+
+declare void @llvm.vp.scatter.nxv1i64.nxv1p0i64(<vscale x 1 x i64>, <vscale x 1 x i64*>, <vscale x 1 x i1>, i32)
+
+define void @vpscatter_nxv1i64(<vscale x 1 x i64> %val, <vscale x 1 x i64*> %ptrs, <vscale x 1 x i1> %m, i32 zeroext %evl) {
+; CHECK-LABEL: @vpscatter_nxv1i64(
+; CHECK-NEXT:    [[TMP1:%.*]] = call <vscale x 1 x i1> @llvm.get.active.lane.mask.nxv1i1.i32(i32 0, i32 [[EVL:%.*]])
+; CHECK-NEXT:    [[TMP2:%.*]] = and <vscale x 1 x i1> [[TMP1]], [[M:%.*]]
+; CHECK-NEXT:    [[VSCALE:%.*]] = call i32 @llvm.vscale.i32()
+; CHECK-NEXT:    [[SCALABLE_SIZE:%.*]] = mul nuw i32 [[VSCALE]], 1
+; CHECK-NEXT:    call void @llvm.masked.scatter.nxv1i64.nxv1p0i64(<vscale x 1 x i64> [[VAL:%.*]], <vscale x 1 x i64*> [[PTRS:%.*]], i32 1, <vscale x 1 x i1> [[TMP2]])
+; CHECK-NEXT:    ret void
+;
+  call void @llvm.vp.scatter.nxv1i64.nxv1p0i64(<vscale x 1 x i64> %val, <vscale x 1 x i64*> %ptrs, <vscale x 1 x i1> %m, i32 %evl)
+  ret void
+}
Index: llvm/lib/CodeGen/ExpandVectorPredication.cpp
===================================================================
--- llvm/lib/CodeGen/ExpandVectorPredication.cpp
+++ llvm/lib/CodeGen/ExpandVectorPredication.cpp
@@ -427,6 +427,15 @@
 
     break;
   }
+  case Intrinsic::vp_scatter:
+    NewMemoryInst = Builder.CreateMaskedScatter(
+        DataParam, PtrParam, AlignOpt.valueOrOne(), MaskParam);
+    break;
+  case Intrinsic::vp_gather:
+    NewMemoryInst = Builder.CreateMaskedGather(VPI.getType(), PtrParam,
+                                               AlignOpt.valueOrOne(), MaskParam,
+                                               nullptr, VPI.getName());
+    break;
   }
 
   assert(NewMemoryInst);
@@ -515,6 +524,8 @@
     break;
   case Intrinsic::vp_load:
   case Intrinsic::vp_store:
+  case Intrinsic::vp_gather:
+  case Intrinsic::vp_scatter:
     return expandPredicationInMemoryIntrinsic(Builder, VPI);
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120664.411819.patch
Type: text/x-patch
Size: 3206 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220228/2e208813/attachment.bin>


More information about the llvm-commits mailing list