[llvm] 3272938 - InstCombine: Add baseline tests for some ptrmask handling
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 28 04:25:54 PDT 2023
Author: Matt Arsenault
Date: 2023-06-28T07:25:48-04:00
New Revision: 3272938d040be1011bd183d7d85ee66e4a3462a2
URL: https://github.com/llvm/llvm-project/commit/3272938d040be1011bd183d7d85ee66e4a3462a2
DIFF: https://github.com/llvm/llvm-project/commit/3272938d040be1011bd183d7d85ee66e4a3462a2.diff
LOG: InstCombine: Add baseline tests for some ptrmask handling
Added:
Modified:
llvm/test/Transforms/InstCombine/align-addr.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstCombine/align-addr.ll b/llvm/test/Transforms/InstCombine/align-addr.ll
index 0b935b51c7ba3..a3ae024d339ca 100644
--- a/llvm/test/Transforms/InstCombine/align-addr.ll
+++ b/llvm/test/Transforms/InstCombine/align-addr.ll
@@ -119,3 +119,117 @@ define void @test3(ptr sret(%struct.s) %a4) {
call void @use(ptr %a4)
ret void
}
+
+declare ptr @llvm.ptrmask.p0.i64(ptr, i64)
+declare ptr @llvm.ptrmask.p0.i32(ptr, i32)
+declare ptr @llvm.ptrmask.p0.i128(ptr, i128)
+
+define <16 x i8> @ptrmask_align_unknown_ptr_align1(ptr align 1 %ptr, i64 %mask) {
+; CHECK-LABEL: @ptrmask_align_unknown_ptr_align1(
+; CHECK-NEXT: [[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[PTR:%.*]], i64 [[MASK:%.*]])
+; CHECK-NEXT: [[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
+; CHECK-NEXT: ret <16 x i8> [[LOAD]]
+;
+ %aligned = call ptr @llvm.ptrmask.p0.i64(ptr %ptr, i64 %mask)
+ %load = load <16 x i8>, ptr %aligned, align 1
+ ret <16 x i8> %load
+}
+
+define <16 x i8> @ptrmask_align_unknown_ptr_align8(ptr align 8 %ptr, i64 %mask) {
+; CHECK-LABEL: @ptrmask_align_unknown_ptr_align8(
+; CHECK-NEXT: [[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[PTR:%.*]], i64 [[MASK:%.*]])
+; CHECK-NEXT: [[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
+; CHECK-NEXT: ret <16 x i8> [[LOAD]]
+;
+ %aligned = call ptr @llvm.ptrmask.p0.i64(ptr %ptr, i64 %mask)
+ %load = load <16 x i8>, ptr %aligned, align 1
+ ret <16 x i8> %load
+}
+
+; Increase load align from 1 to 2
+define <16 x i8> @ptrmask_align2_ptr_align1(ptr align 1 %ptr) {
+; CHECK-LABEL: @ptrmask_align2_ptr_align1(
+; CHECK-NEXT: [[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[PTR:%.*]], i64 -2)
+; CHECK-NEXT: [[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
+; CHECK-NEXT: ret <16 x i8> [[LOAD]]
+;
+ %aligned = call ptr @llvm.ptrmask.p0.i64(ptr %ptr, i64 -2)
+ %load = load <16 x i8>, ptr %aligned, align 1
+ ret <16 x i8> %load
+}
+
+; Increase load align from 1 to 4
+define <16 x i8> @ptrmask_align4_ptr_align1(ptr align 1 %ptr) {
+; CHECK-LABEL: @ptrmask_align4_ptr_align1(
+; CHECK-NEXT: [[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[PTR:%.*]], i64 -4)
+; CHECK-NEXT: [[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
+; CHECK-NEXT: ret <16 x i8> [[LOAD]]
+;
+ %aligned = call ptr @llvm.ptrmask.p0.i64(ptr %ptr, i64 -4)
+ %load = load <16 x i8>, ptr %aligned, align 1
+ ret <16 x i8> %load
+}
+
+; Increase load align from 1 to 8
+define <16 x i8> @ptrmask_align8_ptr_align1(ptr align 1 %ptr) {
+; CHECK-LABEL: @ptrmask_align8_ptr_align1(
+; CHECK-NEXT: [[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[PTR:%.*]], i64 -8)
+; CHECK-NEXT: [[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
+; CHECK-NEXT: ret <16 x i8> [[LOAD]]
+;
+ %aligned = call ptr @llvm.ptrmask.p0.i64(ptr %ptr, i64 -8)
+ %load = load <16 x i8>, ptr %aligned, align 1
+ ret <16 x i8> %load
+}
+
+; Underlying alignment already the same as forced alignment by ptrmask
+; TODO: Should be able to drop the ptrmask
+define <16 x i8> @ptrmask_align8_ptr_align8(ptr align 8 %ptr) {
+; CHECK-LABEL: @ptrmask_align8_ptr_align8(
+; CHECK-NEXT: [[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[PTR:%.*]], i64 -8)
+; CHECK-NEXT: [[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
+; CHECK-NEXT: ret <16 x i8> [[LOAD]]
+;
+ %aligned = call ptr @llvm.ptrmask.p0.i64(ptr %ptr, i64 -8)
+ %load = load <16 x i8>, ptr %aligned, align 1
+ ret <16 x i8> %load
+}
+
+; Underlying alignment greater than alignment forced by ptrmask
+; TODO: Should be able to drop the ptrmask
+define <16 x i8> @ptrmask_align8_ptr_align16(ptr align 16 %ptr) {
+; CHECK-LABEL: @ptrmask_align8_ptr_align16(
+; CHECK-NEXT: [[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i64(ptr [[PTR:%.*]], i64 -8)
+; CHECK-NEXT: [[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
+; CHECK-NEXT: ret <16 x i8> [[LOAD]]
+;
+ %aligned = call ptr @llvm.ptrmask.p0.i64(ptr %ptr, i64 -8)
+ %load = load <16 x i8>, ptr %aligned, align 1
+ ret <16 x i8> %load
+}
+
+; Increase load align from 1 to 8, and the mask type is smaller
+; than the pointer size.
+define <16 x i8> @ptrmask_align8_ptr_align1_smallmask(ptr align 1 %ptr) {
+; CHECK-LABEL: @ptrmask_align8_ptr_align1_smallmask(
+; CHECK-NEXT: [[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i32(ptr [[PTR:%.*]], i32 -8)
+; CHECK-NEXT: [[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
+; CHECK-NEXT: ret <16 x i8> [[LOAD]]
+;
+ %aligned = call ptr @llvm.ptrmask.p0.i32(ptr %ptr, i32 -8)
+ %load = load <16 x i8>, ptr %aligned, align 1
+ ret <16 x i8> %load
+}
+
+; Increase load align from 1 to 8, and the mask type is larger
+; than the pointer size.
+define <16 x i8> @ptrmask_align8_ptr_align1_bigmask(ptr align 1 %ptr) {
+; CHECK-LABEL: @ptrmask_align8_ptr_align1_bigmask(
+; CHECK-NEXT: [[ALIGNED:%.*]] = call ptr @llvm.ptrmask.p0.i128(ptr [[PTR:%.*]], i128 -8)
+; CHECK-NEXT: [[LOAD:%.*]] = load <16 x i8>, ptr [[ALIGNED]], align 1
+; CHECK-NEXT: ret <16 x i8> [[LOAD]]
+;
+ %aligned = call ptr @llvm.ptrmask.p0.i128(ptr %ptr, i128 -8)
+ %load = load <16 x i8>, ptr %aligned, align 1
+ ret <16 x i8> %load
+}
More information about the llvm-commits
mailing list