1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=lower-constant-intrinsics -S < %s | FileCheck %s
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
5 target triple = "x86_64-apple-darwin10.0.0"
7 declare i64 @llvm.objectsize.i64(ptr, i1, i1, i1) nounwind readonly
8 declare i64 @llvm.objectsize.i64.p1(ptr addrspace(1), i1, i1, i1) nounwind readonly
9 declare void @llvm.trap() nounwind
11 ; objectsize should fold to a constant, which causes the branch to fold to an
13 define i32 @test1(ptr %ptr) nounwind ssp noredzone align 2 {
14 ; CHECK-LABEL: @test1(
16 ; CHECK-NEXT: br label [[T:%.*]]
18 ; CHECK-NEXT: ret i32 4
21 %0 = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false, i1 false, i1 false)
22 %1 = icmp ugt i64 %0, 3
23 br i1 %1, label %T, label %trap
26 trap: ; preds = %0, %entry
27 tail call void @llvm.trap() noreturn nounwind
34 define i64 @test_objectsize_null_flag(ptr %ptr) {
35 ; CHECK-LABEL: @test_objectsize_null_flag(
37 ; CHECK-NEXT: ret i64 -1
40 %0 = tail call i64 @llvm.objectsize.i64(ptr null, i1 false, i1 true, i1 false)
44 define i64 @test_objectsize_null_flag_min(ptr %ptr) {
45 ; CHECK-LABEL: @test_objectsize_null_flag_min(
47 ; CHECK-NEXT: ret i64 0
50 %0 = tail call i64 @llvm.objectsize.i64(ptr null, i1 true, i1 true, i1 false)
54 ; Test foldable null pointers because we evaluate them with non-exact modes in
56 define i64 @test_objectsize_null_flag_noas0() {
57 ; CHECK-LABEL: @test_objectsize_null_flag_noas0(
59 ; CHECK-NEXT: ret i64 -1
62 %0 = tail call i64 @llvm.objectsize.i64.p1(ptr addrspace(1) null, i1 false,
67 define i64 @test_objectsize_null_flag_min_noas0() {
68 ; CHECK-LABEL: @test_objectsize_null_flag_min_noas0(
70 ; CHECK-NEXT: ret i64 0
73 %0 = tail call i64 @llvm.objectsize.i64.p1(ptr addrspace(1) null, i1 true,
78 define i64 @test_objectsize_null_known_flag_noas0() {
79 ; CHECK-LABEL: @test_objectsize_null_known_flag_noas0(
81 ; CHECK-NEXT: ret i64 -1
84 %0 = tail call i64 @llvm.objectsize.i64.p1(ptr addrspace(1) null, i1 false,
89 define i64 @test_objectsize_null_known_flag_min_noas0() {
90 ; CHECK-LABEL: @test_objectsize_null_known_flag_min_noas0(
92 ; CHECK-NEXT: ret i64 0
95 %0 = tail call i64 @llvm.objectsize.i64.p1(ptr addrspace(1) null, i1 true,
100 define i64 @test_objectsize_byval_arg(ptr byval([42 x i8]) %ptr) {
101 ; CHECK-LABEL: @test_objectsize_byval_arg(
102 ; CHECK-NEXT: ret i64 42
104 %size = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 true, i1 false, i1 false)
108 define i64 @test_objectsize_byref_arg(ptr byref([42 x i8]) %ptr) {
109 ; CHECK-LABEL: @test_objectsize_byref_arg(
110 ; CHECK-NEXT: ret i64 42
112 %size = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 true, i1 false, i1 false)
116 ; https://llvm.org/PR50023
117 ; The alloca operand type may not match pointer type size.
119 define i64 @vla_pointer_size_mismatch(i42 %x) {
120 ; CHECK-LABEL: @vla_pointer_size_mismatch(
121 ; CHECK-NEXT: [[TMP1:%.*]] = zext i42 [[X:%.*]] to i64
122 ; CHECK-NEXT: [[TMP2:%.*]] = mul i64 1, [[TMP1]]
123 ; CHECK-NEXT: [[A:%.*]] = alloca i8, i42 [[X]], align 1
124 ; CHECK-NEXT: [[G1:%.*]] = getelementptr i8, ptr [[A]], i8 17
125 ; CHECK-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2]], 17
126 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ult i64 [[TMP2]], 17
127 ; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP4]], i64 0, i64 [[TMP3]]
128 ; CHECK-NEXT: [[TMP6:%.*]] = icmp ne i64 [[TMP5]], -1
129 ; CHECK-NEXT: call void @llvm.assume(i1 [[TMP6]])
130 ; CHECK-NEXT: ret i64 [[TMP5]]
132 %A = alloca i8, i42 %x, align 1
133 %G1 = getelementptr i8, ptr %A, i8 17
134 %objsize = call i64 @llvm.objectsize.i64(ptr %G1, i1 false, i1 true, i1 true)
138 declare ptr @malloc(i64) allocsize(0)
140 define i64 @test_objectsize_malloc() {
141 ; CHECK-LABEL: @test_objectsize_malloc(
142 ; CHECK-NEXT: [[PTR:%.*]] = call ptr @malloc(i64 16)
143 ; CHECK-NEXT: ret i64 16
145 %ptr = call ptr @malloc(i64 16)
146 %objsize = call i64 @llvm.objectsize.i64(ptr %ptr, i1 false, i1 true, i1 true)
150 @gv_weak = weak global i64 zeroinitializer, align 16
152 define i32 @promote_with_objectsize_min_false() {
153 ; CHECK-LABEL: @promote_with_objectsize_min_false(
154 ; CHECK-NEXT: ret i32 -1
156 %size = call i32 @llvm.objectsize.i32.p0(ptr @gv_weak, i1 false, i1 false, i1 false)
160 define i32 @promote_with_objectsize_min_true() {
161 ; CHECK-LABEL: @promote_with_objectsize_min_true(
162 ; CHECK-NEXT: ret i32 8
164 %size = call i32 @llvm.objectsize.i32.p0(ptr @gv_weak, i1 true, i1 false, i1 false)
168 @gv_extern = extern_weak global i64, align 16
170 define i32 @promote_with_objectsize_nullunknown_false() {
171 ; CHECK-LABEL: @promote_with_objectsize_nullunknown_false(
172 ; CHECK-NEXT: ret i32 0
174 %size = call i32 @llvm.objectsize.i32.p0(ptr @gv_extern, i1 true, i1 false, i1 false)
178 define i32 @promote_with_objectsize_nullunknown_true() {
179 ; CHECK-LABEL: @promote_with_objectsize_nullunknown_true(
180 ; CHECK-NEXT: ret i32 0
182 %size = call i32 @llvm.objectsize.i32.p0(ptr @gv_extern, i1 true, i1 true, i1 false)
186 declare i32 @llvm.objectsize.i32.p0(ptr, i1, i1, i1)