[llvm] 3fcb968 - [InstSimplify] Add tests for comparison with zero-sized allocs (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 11 07:41:45 PST 2024
Author: Nikita Popov
Date: 2024-11-11T16:41:35+01:00
New Revision: 3fcb9684cf6ba4ff9009ebabd9ff966eeb8b15f7
URL: https://github.com/llvm/llvm-project/commit/3fcb9684cf6ba4ff9009ebabd9ff966eeb8b15f7
DIFF: https://github.com/llvm/llvm-project/commit/3fcb9684cf6ba4ff9009ebabd9ff966eeb8b15f7.diff
LOG: [InstSimplify] Add tests for comparison with zero-sized allocs (NFC)
Added:
Modified:
llvm/test/Transforms/InstSimplify/cmp-alloca-offsets.ll
Removed:
################################################################################
diff --git a/llvm/test/Transforms/InstSimplify/cmp-alloca-offsets.ll b/llvm/test/Transforms/InstSimplify/cmp-alloca-offsets.ll
index 79fd9a22ba5cc9..d076035b269e46 100644
--- a/llvm/test/Transforms/InstSimplify/cmp-alloca-offsets.ll
+++ b/llvm/test/Transforms/InstSimplify/cmp-alloca-offsets.ll
@@ -230,4 +230,96 @@ define i1 @mixed_alloca_size4() {
ret i1 %res
}
+define i1 @zst_alloca_start() {
+; CHECK-LABEL: @zst_alloca_start(
+; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
+; CHECK-NEXT: [[A2:%.*]] = alloca {}, align 8
+; CHECK-NEXT: call void @escape(ptr [[A]], ptr [[A2]])
+; CHECK-NEXT: ret i1 false
+;
+ %a = alloca i64
+ %a2 = alloca {}
+ %gep = getelementptr i8, ptr %a, i64 0
+ %cmp = icmp eq ptr %gep, %a2
+ call void @escape(ptr %a, ptr %a2)
+ ret i1 %cmp
+}
+
+define i1 @zst_alloca_middle() {
+; CHECK-LABEL: @zst_alloca_middle(
+; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
+; CHECK-NEXT: [[A2:%.*]] = alloca {}, align 8
+; CHECK-NEXT: call void @escape(ptr [[A]], ptr [[A2]])
+; CHECK-NEXT: ret i1 false
+;
+ %a = alloca i64
+ %a2 = alloca {}
+ %gep = getelementptr i8, ptr %a, i64 4
+ %cmp = icmp eq ptr %gep, %a2
+ call void @escape(ptr %a, ptr %a2)
+ ret i1 %cmp
+}
+
+define i1 @zst_alloca_end() {
+; CHECK-LABEL: @zst_alloca_end(
+; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
+; CHECK-NEXT: [[A2:%.*]] = alloca {}, align 8
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[A]], i64 8
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[GEP]], [[A2]]
+; CHECK-NEXT: call void @escape(ptr [[A]], ptr [[A2]])
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %a = alloca i64
+ %a2 = alloca {}
+ %gep = getelementptr i8, ptr %a, i64 8
+ %cmp = icmp eq ptr %gep, %a2
+ call void @escape(ptr %a, ptr %a2)
+ ret i1 %cmp
+}
+
+ at gz = external global {}
+
+define i1 @zst_global_start() {
+; CHECK-LABEL: @zst_global_start(
+; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
+; CHECK-NEXT: call void @escape(ptr [[A]], ptr @gz)
+; CHECK-NEXT: ret i1 false
+;
+ %a = alloca i64
+ %gep = getelementptr i8, ptr %a, i64 0
+ %cmp = icmp eq ptr %gep, @gz
+ call void @escape(ptr %a, ptr @gz)
+ ret i1 %cmp
+}
+
+define i1 @zst_global_middle() {
+; CHECK-LABEL: @zst_global_middle(
+; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
+; CHECK-NEXT: call void @escape(ptr [[A]], ptr @gz)
+; CHECK-NEXT: ret i1 false
+;
+ %a = alloca i64
+ %gep = getelementptr i8, ptr %a, i64 4
+ %cmp = icmp eq ptr %gep, @gz
+ call void @escape(ptr %a, ptr @gz)
+ ret i1 %cmp
+}
+
+define i1 @zst_global_end() {
+; CHECK-LABEL: @zst_global_end(
+; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
+; CHECK-NEXT: [[GEP:%.*]] = getelementptr i8, ptr [[A]], i64 8
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq ptr [[GEP]], @gz
+; CHECK-NEXT: call void @escape(ptr [[A]], ptr @gz)
+; CHECK-NEXT: ret i1 [[CMP]]
+;
+ %a = alloca i64
+ %gep = getelementptr i8, ptr %a, i64 8
+ %cmp = icmp eq ptr %gep, @gz
+ call void @escape(ptr %a, ptr @gz)
+ ret i1 %cmp
+}
+
+declare void @escape(ptr, ptr)
+
attributes #0 = { null_pointer_is_valid }
More information about the llvm-commits
mailing list