Skip to content

Commit

Permalink
[InstSimplify] Add tests for comparison with zero-sized allocs (NFC)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Nov 11, 2024
1 parent a41922a commit 3fcb968
Showing 1 changed file with 92 additions and 0 deletions.
92 changes: 92 additions & 0 deletions llvm/test/Transforms/InstSimplify/cmp-alloca-offsets.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

@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 }

0 comments on commit 3fcb968

Please sign in to comment.