Skip to content

Commit

Permalink
DSE: pre-commit tests for scalable vectors (#110669)
Browse files Browse the repository at this point in the history
As AliasAnalysis now has support for scalable sizes, add tests to
DeadStoreElimination covering the scalable vectors case, in preparation
to extend it.
  • Loading branch information
artagnon authored Nov 28, 2024
1 parent aa5cdce commit 4e8eabd
Show file tree
Hide file tree
Showing 2 changed files with 204 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,90 @@ bb:
ret void
}

define void @ScalableVectorTestFullyOverlapping(ptr %arg, i32 %i) vscale_range(1, 2) {
; CHECK-LABEL: @ScalableVectorTestFullyOverlapping(
; CHECK-NEXT: [[I_1:%.*]] = add nuw nsw i32 [[I:%.*]], 1
; CHECK-NEXT: [[EXT_I_1:%.*]] = zext i32 [[I_1]] to i64
; CHECK-NEXT: [[GEP_ARG_I_1:%.*]] = getelementptr inbounds float, ptr [[ARG:%.*]], i64 [[EXT_I_1]]
; CHECK-NEXT: store float 0.000000e+00, ptr [[GEP_ARG_I_1]], align 4
; CHECK-NEXT: [[EXT_I:%.*]] = zext i32 [[I]] to i64
; CHECK-NEXT: [[GEP_ARG_I:%.*]] = getelementptr inbounds float, ptr [[ARG]], i64 [[EXT_I]]
; CHECK-NEXT: store <vscale x 2 x float> zeroinitializer, ptr [[GEP_ARG_I]], align 8
; CHECK-NEXT: ret void
;
%i.1 = add nuw nsw i32 %i, 1
%ext.i.1 = zext i32 %i.1 to i64
%gep.arg.i.1 = getelementptr inbounds float, ptr %arg, i64 %ext.i.1
store float 0.0, ptr %gep.arg.i.1
%ext.i = zext i32 %i to i64
%gep.arg.i = getelementptr inbounds float, ptr %arg, i64 %ext.i
store <vscale x 2 x float> zeroinitializer, ptr %gep.arg.i
ret void
}

define void @ScalableVectorTestFullyOverlapping2(ptr %arg, i32 %i) {
; CHECK-LABEL: @ScalableVectorTestFullyOverlapping2(
; CHECK-NEXT: [[I_1:%.*]] = add nuw nsw i32 [[I:%.*]], 1
; CHECK-NEXT: [[EXT_I_1:%.*]] = zext i32 [[I_1]] to i64
; CHECK-NEXT: [[GEP_ARG_I_1:%.*]] = getelementptr inbounds float, ptr [[ARG:%.*]], i64 [[EXT_I_1]]
; CHECK-NEXT: store <vscale x 2 x float> zeroinitializer, ptr [[GEP_ARG_I_1]], align 8
; CHECK-NEXT: [[EXT_I:%.*]] = zext i32 [[I]] to i64
; CHECK-NEXT: [[GEP_ARG_I:%.*]] = getelementptr inbounds float, ptr [[ARG]], i64 [[EXT_I]]
; CHECK-NEXT: store <vscale x 4 x float> zeroinitializer, ptr [[GEP_ARG_I]], align 16
; CHECK-NEXT: ret void
;
%i.1 = add nuw nsw i32 %i, 1
%ext.i.1 = zext i32 %i.1 to i64
%gep.arg.i.1 = getelementptr inbounds float, ptr %arg, i64 %ext.i.1
store <vscale x 2 x float> zeroinitializer, ptr %gep.arg.i.1
%ext.i = zext i32 %i to i64
%gep.arg.i = getelementptr inbounds float, ptr %arg, i64 %ext.i
store <vscale x 4 x float> zeroinitializer, ptr %gep.arg.i
ret void
}

define void @ScalableVectorTestNonOverlapping(ptr %arg, i32 %i) vscale_range(1, 2) {
; CHECK-LABEL: @ScalableVectorTestNonOverlapping(
; CHECK-NEXT: [[I_10:%.*]] = add nuw nsw i32 [[I:%.*]], 10
; CHECK-NEXT: [[EXT_I_10:%.*]] = zext i32 [[I_10]] to i64
; CHECK-NEXT: [[GEP_ARG_I_10:%.*]] = getelementptr inbounds float, ptr [[ARG:%.*]], i64 [[EXT_I_10]]
; CHECK-NEXT: store float 0.000000e+00, ptr [[GEP_ARG_I_10]], align 4
; CHECK-NEXT: [[EXT_I:%.*]] = zext i32 [[I]] to i64
; CHECK-NEXT: [[GEP_ARG_I:%.*]] = getelementptr inbounds float, ptr [[ARG]], i64 [[EXT_I]]
; CHECK-NEXT: store <vscale x 2 x float> zeroinitializer, ptr [[GEP_ARG_I]], align 8
; CHECK-NEXT: ret void
;
%i.10 = add nuw nsw i32 %i, 10
%ext.i.10 = zext i32 %i.10 to i64
%gep.arg.i.10 = getelementptr inbounds float, ptr %arg, i64 %ext.i.10
store float 0.0, ptr %gep.arg.i.10
%ext.i = zext i32 %i to i64
%gep.arg.i = getelementptr inbounds float, ptr %arg, i64 %ext.i
store <vscale x 2 x float> zeroinitializer, ptr %gep.arg.i
ret void
}

define void @ScalableVectorTestNonOverlapping2(ptr %arg, i32 %i) vscale_range(1, 2) {
; CHECK-LABEL: @ScalableVectorTestNonOverlapping2(
; CHECK-NEXT: [[I_10:%.*]] = add nuw nsw i32 [[I:%.*]], 10
; CHECK-NEXT: [[EXT_I_10:%.*]] = zext i32 [[I_10]] to i64
; CHECK-NEXT: [[GEP_ARG_I_10:%.*]] = getelementptr inbounds float, ptr [[ARG:%.*]], i64 [[EXT_I_10]]
; CHECK-NEXT: store <vscale x 2 x float> zeroinitializer, ptr [[GEP_ARG_I_10]], align 8
; CHECK-NEXT: [[EXT_I:%.*]] = zext i32 [[I]] to i64
; CHECK-NEXT: [[GEP_ARG_I:%.*]] = getelementptr inbounds float, ptr [[ARG]], i64 [[EXT_I]]
; CHECK-NEXT: store <vscale x 4 x float> zeroinitializer, ptr [[GEP_ARG_I]], align 16
; CHECK-NEXT: ret void
;
%i.10 = add nuw nsw i32 %i, 10
%ext.i.10 = zext i32 %i.10 to i64
%gep.arg.i.10 = getelementptr inbounds float, ptr %arg, i64 %ext.i.10
store <vscale x 2 x float> zeroinitializer, ptr %gep.arg.i.10
%ext.i = zext i32 %i to i64
%gep.arg.i = getelementptr inbounds float, ptr %arg, i64 %ext.i
store <vscale x 4 x float> zeroinitializer, ptr %gep.arg.i
ret void
}

define void @ArrayTestPartiallyOverlapping(i64 %0) {
;
; The DSE pass will not kill the store because the overlap is partial
Expand All @@ -55,9 +139,9 @@ define void @ArrayTestPartiallyOverlapping(i64 %0) {
; CHECK-LABEL: @ArrayTestPartiallyOverlapping(
; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[TMP0:%.*]], 10
; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [0 x i8], ptr @BUFFER, i64 0, i64 [[TMP2]]
; CHECK-NEXT: [[TMP5:%.*]] = add i64 [[TMP0]], 15
; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds [0 x i8], ptr @BUFFER, i64 0, i64 [[TMP5]]
; CHECK-NEXT: store i32 1, ptr [[TMP6]], align 4
; CHECK-NEXT: [[TMP4:%.*]] = add i64 [[TMP0]], 15
; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds [0 x i8], ptr @BUFFER, i64 0, i64 [[TMP4]]
; CHECK-NEXT: store i32 1, ptr [[TMP5]], align 4
; CHECK-NEXT: store i64 0, ptr [[TMP3]], align 4
; CHECK-NEXT: ret void
;
Expand Down Expand Up @@ -97,3 +181,28 @@ bb:
ret void
}

define void @ScalableVectorTestPartiallyOverlapping(ptr %arg, i32 %i) {
;
; The DSE pass will not kill the store because the overlap is partial
; and won't fully clobber the original store.
;
; CHECK-LABEL: @ScalableVectorTestPartiallyOverlapping(
; CHECK-NEXT: [[EXT_I:%.*]] = zext i32 [[I:%.*]] to i64
; CHECK-NEXT: [[GEP_ARG_I:%.*]] = getelementptr inbounds float, ptr [[ARG:%.*]], i64 [[EXT_I]]
; CHECK-NEXT: store <vscale x 2 x float> zeroinitializer, ptr [[GEP_ARG_I]], align 8
; CHECK-NEXT: [[I_1:%.*]] = add nuw nsw i32 [[I]], 1
; CHECK-NEXT: [[EXT_I_1:%.*]] = zext i32 [[I_1]] to i64
; CHECK-NEXT: [[GEP_ARG_I_1:%.*]] = getelementptr inbounds float, ptr [[ARG]], i64 [[EXT_I_1]]
; CHECK-NEXT: store <vscale x 2 x float> zeroinitializer, ptr [[GEP_ARG_I_1]], align 8
; CHECK-NEXT: ret void
;
%ext.i = zext i32 %i to i64
%gep.arg.i = getelementptr inbounds float, ptr %arg, i64 %ext.i
store <vscale x 2 x float> zeroinitializer, ptr %gep.arg.i
%i.1 = add nuw nsw i32 %i, 1
%ext.i.1 = zext i32 %i.1 to i64
%gep.arg.i.1 = getelementptr inbounds float, ptr %arg, i64 %ext.i.1
store <vscale x 2 x float> zeroinitializer, ptr %gep.arg.i.1
ret void
}

Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ define void @later_non_removable_store(i1 %c, ptr %p) {
; CHECK: if:
; CHECK-NEXT: br label [[EXIT]]
; CHECK: exit:
; CHECK-NEXT: call void @use(ptr [[P]]) #[[ATTR6:[0-9]+]]
; CHECK-NEXT: call void @use(ptr [[P]]) #[[ATTR7:[0-9]+]]
; CHECK-NEXT: ret void
;
store i8 1, ptr %p
Expand All @@ -655,3 +655,94 @@ exit:
call void @use(ptr %p) argmemonly
ret void
}

define void @scalable_scalable_redundant_store(ptr %ptr) {
; CHECK-LABEL: @scalable_scalable_redundant_store(
; CHECK-NEXT: [[GEP_PTR_2:%.*]] = getelementptr i64, ptr [[PTR:%.*]], i64 2
; CHECK-NEXT: store <vscale x 2 x i64> zeroinitializer, ptr [[GEP_PTR_2]], align 16
; CHECK-NEXT: store <vscale x 4 x i64> zeroinitializer, ptr [[PTR]], align 32
; CHECK-NEXT: ret void
;
%gep.ptr.2 = getelementptr i64, ptr %ptr, i64 2
store <vscale x 2 x i64> zeroinitializer, ptr %gep.ptr.2
store <vscale x 4 x i64> zeroinitializer, ptr %ptr
ret void
}

define void @scalable_scalable_neg(ptr %ptr) {
; CHECK-LABEL: @scalable_scalable_neg(
; CHECK-NEXT: [[GEP_PTR_8:%.*]] = getelementptr i64, ptr [[PTR:%.*]], i64 8
; CHECK-NEXT: store <vscale x 4 x i64> zeroinitializer, ptr [[GEP_PTR_8]], align 32
; CHECK-NEXT: store <vscale x 2 x i64> zeroinitializer, ptr [[PTR]], align 16
; CHECK-NEXT: ret void
;
%gep.ptr.8 = getelementptr i64, ptr %ptr, i64 8
store <vscale x 4 x i64> zeroinitializer, ptr %gep.ptr.8
store <vscale x 2 x i64> zeroinitializer, ptr %ptr
ret void
}

define void @scalable_scalable_nonconst_offset_neg(ptr %ptr, i64 %i) {
; CHECK-LABEL: @scalable_scalable_nonconst_offset_neg(
; CHECK-NEXT: [[GEP_PTR_I:%.*]] = getelementptr i64, ptr [[PTR:%.*]], i64 [[I:%.*]]
; CHECK-NEXT: store <vscale x 2 x i64> zeroinitializer, ptr [[GEP_PTR_I]], align 16
; CHECK-NEXT: store <vscale x 4 x i64> zeroinitializer, ptr [[PTR]], align 32
; CHECK-NEXT: ret void
;
%gep.ptr.i = getelementptr i64, ptr %ptr, i64 %i
store <vscale x 2 x i64> zeroinitializer, ptr %gep.ptr.i
store <vscale x 4 x i64> zeroinitializer, ptr %ptr
ret void
}

define void @scalable_fixed_redundant_store(ptr %ptr) vscale_range(1, 2) {
; CHECK-LABEL: @scalable_fixed_redundant_store(
; CHECK-NEXT: [[GEP_PTR_2:%.*]] = getelementptr i64, ptr [[PTR:%.*]], i64 2
; CHECK-NEXT: store <2 x i64> zeroinitializer, ptr [[GEP_PTR_2]], align 16
; CHECK-NEXT: store <vscale x 4 x i64> zeroinitializer, ptr [[PTR]], align 32
; CHECK-NEXT: ret void
;
%gep.ptr.2 = getelementptr i64, ptr %ptr, i64 2
store <2 x i64> zeroinitializer, ptr %gep.ptr.2
store <vscale x 4 x i64> zeroinitializer, ptr %ptr
ret void
}

define void @scalable_fixed_neg(ptr %ptr) vscale_range(1, 2) {
; CHECK-LABEL: @scalable_fixed_neg(
; CHECK-NEXT: [[GEP_PTR_16:%.*]] = getelementptr i64, ptr [[PTR:%.*]], i64 16
; CHECK-NEXT: store <2 x i64> zeroinitializer, ptr [[GEP_PTR_16]], align 16
; CHECK-NEXT: store <vscale x 4 x i64> zeroinitializer, ptr [[PTR]], align 32
; CHECK-NEXT: ret void
;
%gep.ptr.16 = getelementptr i64, ptr %ptr, i64 16
store <2 x i64> zeroinitializer, ptr %gep.ptr.16
store <vscale x 4 x i64> zeroinitializer, ptr %ptr
ret void
}

define void @fixed_scalable_redundant_store(ptr %ptr) vscale_range(1, 2) {
; CHECK-LABEL: @fixed_scalable_redundant_store(
; CHECK-NEXT: [[GEP_PTR_2:%.*]] = getelementptr i64, ptr [[PTR:%.*]], i64 2
; CHECK-NEXT: store <vscale x 2 x i64> zeroinitializer, ptr [[GEP_PTR_2]], align 16
; CHECK-NEXT: store <8 x i64> zeroinitializer, ptr [[PTR]], align 64
; CHECK-NEXT: ret void
;
%gep.ptr.2 = getelementptr i64, ptr %ptr, i64 2
store <vscale x 2 x i64> zeroinitializer, ptr %gep.ptr.2
store <8 x i64> zeroinitializer, ptr %ptr
ret void
}

define void @fixed_scalable_neg(ptr %ptr) vscale_range(1, 2) {
; CHECK-LABEL: @fixed_scalable_neg(
; CHECK-NEXT: [[GEP_PTR_2:%.*]] = getelementptr i64, ptr [[PTR:%.*]], i64 2
; CHECK-NEXT: store <vscale x 2 x i64> zeroinitializer, ptr [[GEP_PTR_2]], align 16
; CHECK-NEXT: store <4 x i64> zeroinitializer, ptr [[PTR]], align 32
; CHECK-NEXT: ret void
;
%gep.ptr.2 = getelementptr i64, ptr %ptr, i64 2
store <vscale x 2 x i64> zeroinitializer, ptr %gep.ptr.2
store <4 x i64> zeroinitializer, ptr %ptr
ret void
}

0 comments on commit 4e8eabd

Please sign in to comment.