[llvm] 4fcbd0e - [GVN] Add more tests for opaque pointer GEPs (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 27 06:42:02 PDT 2022
Author: Nikita Popov
Date: 2022-04-27T15:41:55+02:00
New Revision: 4fcbd0eb4ad58956d57fccf8424b7f92ac22a712
URL: https://github.com/llvm/llvm-project/commit/4fcbd0eb4ad58956d57fccf8424b7f92ac22a712
DIFF: https://github.com/llvm/llvm-project/commit/4fcbd0eb4ad58956d57fccf8424b7f92ac22a712.diff
LOG: [GVN] Add more tests for opaque pointer GEPs (NFC)
Some of these are equivalent when considering an offset encoding.
Added:
Modified:
llvm/test/Transforms/GVN/opaque-ptr.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/GVN/opaque-ptr.ll b/llvm/test/Transforms/GVN/opaque-ptr.ll
index ffc14d9a96af3..fa203da28bb73 100644
--- a/llvm/test/Transforms/GVN/opaque-ptr.ll
+++ b/llvm/test/Transforms/GVN/opaque-ptr.ll
@@ -22,6 +22,81 @@ define void @gep_cse(ptr %p) {
ret void
}
+define void @gep_cse_offset_canonicalization(ptr %p, i64 %idx, i64 %idx2) {
+; CHECK-LABEL: @gep_cse_offset_canonicalization(
+; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i64, ptr [[P:%.*]], i64 1
+; CHECK-NEXT: [[GEP1_SAME1:%.*]] = getelementptr i32, ptr [[P]], i64 2
+; CHECK-NEXT: [[GEP1_SAME2:%.*]] = getelementptr i8, ptr [[P]], i64 8
+; CHECK-NEXT: [[GEP1_DIFFERENT:%.*]] = getelementptr i8, ptr [[P]], i64 12
+; CHECK-NEXT: call void @use(ptr [[GEP1]])
+; CHECK-NEXT: call void @use(ptr [[GEP1_SAME1]])
+; CHECK-NEXT: call void @use(ptr [[GEP1_SAME2]])
+; CHECK-NEXT: call void @use(ptr [[GEP1_DIFFERENT]])
+; CHECK-NEXT: [[GEP2:%.*]] = getelementptr i64, ptr [[P]], i64 [[IDX:%.*]]
+; CHECK-NEXT: [[GEP2_SAME:%.*]] = getelementptr { i32, i32 }, ptr [[P]], i64 [[IDX]]
+; CHECK-NEXT: [[GEP2_DIFFERENT:%.*]] = getelementptr { i32, i32, i32 }, ptr [[P]], i64 [[IDX]]
+; CHECK-NEXT: call void @use(ptr [[GEP2]])
+; CHECK-NEXT: call void @use(ptr [[GEP2_SAME]])
+; CHECK-NEXT: call void @use(ptr [[GEP2_DIFFERENT]])
+; CHECK-NEXT: [[GEP3:%.*]] = getelementptr { [0 x i32], [0 x i32] }, ptr [[P]], i64 0, i32 0, i64 [[IDX]]
+; CHECK-NEXT: [[GEP3_SAME1:%.*]] = getelementptr { [0 x i32], [0 x i32] }, ptr [[P]], i64 0, i32 1, i64 [[IDX]]
+; CHECK-NEXT: [[GEP3_SAME2:%.*]] = getelementptr { [0 x i32], [0 x i32] }, ptr [[P]], i64 1, i32 0, i64 [[IDX]]
+; CHECK-NEXT: [[GEP3_DIFFERENT:%.*]] = getelementptr { [0 x i32], [0 x i32] }, ptr [[P]], i64 0, i32 0, i64 [[IDX2:%.*]]
+; CHECK-NEXT: call void @use(ptr [[GEP3]])
+; CHECK-NEXT: call void @use(ptr [[GEP3_SAME1]])
+; CHECK-NEXT: call void @use(ptr [[GEP3_SAME2]])
+; CHECK-NEXT: call void @use(ptr [[GEP3_DIFFERENT]])
+; CHECK-NEXT: [[GEP4:%.*]] = getelementptr [4 x i32], ptr [[P]], i64 [[IDX]], i64 [[IDX2]]
+; CHECK-NEXT: [[GEP4_SAME:%.*]] = getelementptr [4 x float], ptr [[P]], i64 [[IDX]], i64 [[IDX2]]
+; CHECK-NEXT: [[GEP4_DIFFERENT:%.*]] = getelementptr [4 x float], ptr [[P]], i64 [[IDX2]], i64 [[IDX]]
+; CHECK-NEXT: call void @use(ptr [[GEP4]])
+; CHECK-NEXT: call void @use(ptr [[GEP4_SAME]])
+; CHECK-NEXT: call void @use(ptr [[GEP4_DIFFERENT]])
+; CHECK-NEXT: [[GEP5:%.*]] = getelementptr <vscale x 2 x i32>, ptr [[P]], i64 1
+; CHECK-NEXT: [[GEP5_SAME:%.*]] = getelementptr <vscale x 2 x float>, ptr [[P]], i64 1
+; CHECK-NEXT: [[GEP5_DIFFERENT:%.*]] = getelementptr <vscale x 2 x i64>, ptr [[P]], i64 1
+; CHECK-NEXT: call void @use(ptr [[GEP5]])
+; CHECK-NEXT: call void @use(ptr [[GEP5_SAME]])
+; CHECK-NEXT: call void @use(ptr [[GEP5_DIFFERENT]])
+; CHECK-NEXT: ret void
+;
+ %gep1 = getelementptr i64, ptr %p, i64 1
+ %gep1.same1 = getelementptr i32, ptr %p, i64 2
+ %gep1.same2 = getelementptr i8, ptr %p, i64 8
+ %gep1.
diff erent = getelementptr i8, ptr %p, i64 12
+ call void @use(ptr %gep1)
+ call void @use(ptr %gep1.same1)
+ call void @use(ptr %gep1.same2)
+ call void @use(ptr %gep1.
diff erent)
+ %gep2 = getelementptr i64, ptr %p, i64 %idx
+ %gep2.same = getelementptr { i32, i32 }, ptr %p, i64 %idx
+ %gep2.
diff erent = getelementptr { i32, i32, i32 }, ptr %p, i64 %idx
+ call void @use(ptr %gep2)
+ call void @use(ptr %gep2.same)
+ call void @use(ptr %gep2.
diff erent)
+ %gep3 = getelementptr { [0 x i32], [0 x i32] }, ptr %p, i64 0, i32 0, i64 %idx
+ %gep3.same1 = getelementptr { [0 x i32], [0 x i32] }, ptr %p, i64 0, i32 1, i64 %idx
+ %gep3.same2 = getelementptr { [0 x i32], [0 x i32] }, ptr %p, i64 1, i32 0, i64 %idx
+ %gep3.
diff erent = getelementptr { [0 x i32], [0 x i32] }, ptr %p, i64 0, i32 0, i64 %idx2
+ call void @use(ptr %gep3)
+ call void @use(ptr %gep3.same1)
+ call void @use(ptr %gep3.same2)
+ call void @use(ptr %gep3.
diff erent)
+ %gep4 = getelementptr [4 x i32], ptr %p, i64 %idx, i64 %idx2
+ %gep4.same = getelementptr [4 x float], ptr %p, i64 %idx, i64 %idx2
+ %gep4.
diff erent = getelementptr [4 x float], ptr %p, i64 %idx2, i64 %idx
+ call void @use(ptr %gep4)
+ call void @use(ptr %gep4.same)
+ call void @use(ptr %gep4.
diff erent)
+ %gep5 = getelementptr <vscale x 2 x i32>, ptr %p, i64 1
+ %gep5.same = getelementptr <vscale x 2 x float>, ptr %p, i64 1
+ %gep5.
diff erent = getelementptr <vscale x 2 x i64>, ptr %p, i64 1
+ call void @use(ptr %gep5)
+ call void @use(ptr %gep5.same)
+ call void @use(ptr %gep5.
diff erent)
+ ret void
+}
+
define i32 @phi_trans(i1 %c, ptr %p1, ptr %p2) {
; CHECK-LABEL: @phi_trans(
; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
More information about the llvm-commits
mailing list