1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -passes=lower-constant-intrinsics -S < %s | FileCheck %s
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"
target triple = "x86_64-apple-darwin10.0.0"
declare i64 @llvm.objectsize.i64(ptr, i1, i1, i1) nounwind readonly
declare i64 @llvm.objectsize.i64.p1(ptr addrspace(1), i1, i1, i1) nounwind readonly
declare void @llvm.trap() nounwind
; objectsize should fold to a constant, which causes the branch to fold to an
; uncond branch.
define i32 @test1(ptr %ptr) nounwind ssp noredzone align 2 {
; CHECK-LABEL: @test1(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[T:%.*]]
; CHECK: T:
; CHECK-NEXT: ret i32 4
;
entry:
%0 = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 false, i1 false, i1 false)
%1 = icmp ugt i64 %0, 3
br i1 %1, label %T, label %trap
trap: ; preds = %0, %entry
tail call void @llvm.trap() noreturn nounwind
unreachable
T:
ret i32 4
}
define i64 @test_objectsize_null_flag(ptr %ptr) {
; CHECK-LABEL: @test_objectsize_null_flag(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i64 -1
;
entry:
%0 = tail call i64 @llvm.objectsize.i64(ptr null, i1 false, i1 true, i1 false)
ret i64 %0
}
define i64 @test_objectsize_null_flag_min(ptr %ptr) {
; CHECK-LABEL: @test_objectsize_null_flag_min(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i64 0
;
entry:
%0 = tail call i64 @llvm.objectsize.i64(ptr null, i1 true, i1 true, i1 false)
ret i64 %0
}
; Test foldable null pointers because we evaluate them with non-exact modes in
; CodeGenPrepare.
define i64 @test_objectsize_null_flag_noas0() {
; CHECK-LABEL: @test_objectsize_null_flag_noas0(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i64 -1
;
entry:
%0 = tail call i64 @llvm.objectsize.i64.p1(ptr addrspace(1) null, i1 false,
i1 true, i1 false)
ret i64 %0
}
define i64 @test_objectsize_null_flag_min_noas0() {
; CHECK-LABEL: @test_objectsize_null_flag_min_noas0(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i64 0
;
entry:
%0 = tail call i64 @llvm.objectsize.i64.p1(ptr addrspace(1) null, i1 true,
i1 true, i1 false)
ret i64 %0
}
define i64 @test_objectsize_null_known_flag_noas0() {
; CHECK-LABEL: @test_objectsize_null_known_flag_noas0(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i64 -1
;
entry:
%0 = tail call i64 @llvm.objectsize.i64.p1(ptr addrspace(1) null, i1 false,
i1 false, i1 false)
ret i64 %0
}
define i64 @test_objectsize_null_known_flag_min_noas0() {
; CHECK-LABEL: @test_objectsize_null_known_flag_min_noas0(
; CHECK-NEXT: entry:
; CHECK-NEXT: ret i64 0
;
entry:
%0 = tail call i64 @llvm.objectsize.i64.p1(ptr addrspace(1) null, i1 true,
i1 false, i1 false)
ret i64 %0
}
define i64 @test_objectsize_byval_arg(ptr byval([42 x i8]) %ptr) {
; CHECK-LABEL: @test_objectsize_byval_arg(
; CHECK-NEXT: ret i64 42
;
%size = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 true, i1 false, i1 false)
ret i64 %size
}
define i64 @test_objectsize_byref_arg(ptr byref([42 x i8]) %ptr) {
; CHECK-LABEL: @test_objectsize_byref_arg(
; CHECK-NEXT: ret i64 42
;
%size = tail call i64 @llvm.objectsize.i64(ptr %ptr, i1 true, i1 false, i1 false)
ret i64 %size
}
; https://llvm.org/PR50023
; The alloca operand type may not match pointer type size.
define i64 @vla_pointer_size_mismatch(i42 %x) {
; CHECK-LABEL: @vla_pointer_size_mismatch(
; CHECK-NEXT: [[TMP1:%.*]] = zext i42 [[X:%.*]] to i64
; CHECK-NEXT: [[TMP2:%.*]] = mul i64 1, [[TMP1]]
; CHECK-NEXT: [[A:%.*]] = alloca i8, i42 [[X]], align 1
; CHECK-NEXT: [[G1:%.*]] = getelementptr i8, ptr [[A]], i8 17
; CHECK-NEXT: [[TMP3:%.*]] = sub i64 [[TMP2]], 17
; CHECK-NEXT: [[TMP4:%.*]] = icmp ult i64 [[TMP2]], 17
; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP4]], i64 0, i64 [[TMP3]]
; CHECK-NEXT: [[TMP6:%.*]] = icmp ne i64 [[TMP5]], -1
; CHECK-NEXT: call void @llvm.assume(i1 [[TMP6]])
; CHECK-NEXT: ret i64 [[TMP5]]
;
%A = alloca i8, i42 %x, align 1
%G1 = getelementptr i8, ptr %A, i8 17
%objsize = call i64 @llvm.objectsize.i64(ptr %G1, i1 false, i1 true, i1 true)
ret i64 %objsize
}
declare ptr @malloc(i64) allocsize(0)
define i64 @test_objectsize_malloc() {
; CHECK-LABEL: @test_objectsize_malloc(
; CHECK-NEXT: [[PTR:%.*]] = call ptr @malloc(i64 16)
; CHECK-NEXT: ret i64 16
;
%ptr = call ptr @malloc(i64 16)
%objsize = call i64 @llvm.objectsize.i64(ptr %ptr, i1 false, i1 true, i1 true)
ret i64 %objsize
}
@gv_weak = weak global i64 zeroinitializer, align 16
define i32 @promote_with_objectsize_min_false() {
; CHECK-LABEL: @promote_with_objectsize_min_false(
; CHECK-NEXT: ret i32 -1
;
%size = call i32 @llvm.objectsize.i32.p0(ptr @gv_weak, i1 false, i1 false, i1 false)
ret i32 %size
}
define i32 @promote_with_objectsize_min_true() {
; CHECK-LABEL: @promote_with_objectsize_min_true(
; CHECK-NEXT: ret i32 8
;
%size = call i32 @llvm.objectsize.i32.p0(ptr @gv_weak, i1 true, i1 false, i1 false)
ret i32 %size
}
@gv_extern = extern_weak global i64, align 16
define i32 @promote_with_objectsize_nullunknown_false() {
; CHECK-LABEL: @promote_with_objectsize_nullunknown_false(
; CHECK-NEXT: ret i32 0
;
%size = call i32 @llvm.objectsize.i32.p0(ptr @gv_extern, i1 true, i1 false, i1 false)
ret i32 %size
}
define i32 @promote_with_objectsize_nullunknown_true() {
; CHECK-LABEL: @promote_with_objectsize_nullunknown_true(
; CHECK-NEXT: ret i32 0
;
%size = call i32 @llvm.objectsize.i32.p0(ptr @gv_extern, i1 true, i1 true, i1 false)
ret i32 %size
}
define i64 @out_of_bound_gep() {
; CHECK-LABEL: @out_of_bound_gep(
; CHECK-NEXT: [[OBJ:%.*]] = alloca i8, i32 4, align 1
; CHECK-NEXT: [[SLIDE:%.*]] = getelementptr i8, ptr [[OBJ]], i8 8
; CHECK-NEXT: ret i64 0
;
%obj = alloca i8, i32 4
%slide = getelementptr i8, ptr %obj, i8 8
%objsize = call i64 @llvm.objectsize.i64(ptr %slide, i1 false, i1 false, i1 false)
ret i64 %objsize
}
define i64 @wrapping_gep(i1 %c) {
; CHECK-LABEL: @wrapping_gep(
; CHECK-NEXT: [[OBJ:%.*]] = alloca i8, i64 4, align 1
; CHECK-NEXT: [[SLIDE:%.*]] = getelementptr i8, ptr [[OBJ]], i64 -9223372036854775807
; CHECK-NEXT: [[SLIDE_BIS:%.*]] = getelementptr i8, ptr [[SLIDE]], i64 -9223372036854775808
; CHECK-NEXT: ret i64 3
;
%obj = alloca i8, i64 4
%slide = getelementptr i8, ptr %obj, i64 9223372036854775809
%slide.bis = getelementptr i8, ptr %slide, i64 9223372036854775808
%objsize = call i64 @llvm.objectsize.i64(ptr %slide.bis, i1 false, i1 false, i1 false)
ret i64 %objsize
}
define i64 @wrapping_gep_neg(i1 %c) {
; CHECK-LABEL: @wrapping_gep_neg(
; CHECK-NEXT: [[OBJ:%.*]] = alloca i8, i64 4, align 1
; CHECK-NEXT: [[SLIDE:%.*]] = getelementptr i8, ptr [[OBJ]], i64 9223372036854775807
; CHECK-NEXT: [[SLIDE_BIS:%.*]] = getelementptr i8, ptr [[SLIDE]], i64 9223372036854775807
; CHECK-NEXT: ret i64 -1
;
%obj = alloca i8, i64 4
%slide = getelementptr i8, ptr %obj, i64 9223372036854775807
%slide.bis = getelementptr i8, ptr %slide, i64 9223372036854775807
%objsize = call i64 @llvm.objectsize.i64(ptr %slide.bis, i1 false, i1 false, i1 false)
ret i64 %objsize
}
define i64 @wrapping_gep_large_alloc(i1 %c) {
; CHECK-LABEL: @wrapping_gep_large_alloc(
; CHECK-NEXT: [[OBJ:%.*]] = alloca i8, i64 9223372036854775807, align 1
; CHECK-NEXT: [[SLIDE:%.*]] = getelementptr i8, ptr [[OBJ]], i64 9223372036854775807
; CHECK-NEXT: [[SLIDE_BIS:%.*]] = getelementptr i8, ptr [[SLIDE]], i64 3
; CHECK-NEXT: [[SLIDE_TER:%.*]] = getelementptr i8, ptr [[SLIDE_BIS]], i64 -4
; CHECK-NEXT: ret i64 1
;
%obj = alloca i8, i64 9223372036854775807
%slide = getelementptr i8, ptr %obj, i64 9223372036854775807
%slide.bis = getelementptr i8, ptr %slide, i64 3
%slide.ter = getelementptr i8, ptr %slide.bis, i64 -4
%objsize = call i64 @llvm.objectsize.i64(ptr %slide.ter, i1 false, i1 false, i1 false)
ret i64 %objsize
}
; We don't analyze allocations larger than platform's ptrdiff_t
define i64 @large_alloca() {
; CHECK-LABEL: @large_alloca(
; CHECK-NEXT: [[OBJ:%.*]] = alloca i8, i64 -9223372036854775808, align 1
; CHECK-NEXT: [[SLIDE:%.*]] = getelementptr i8, ptr [[OBJ]], i64 9223372036854775807
; CHECK-NEXT: ret i64 -1
;
%obj = alloca i8, i64 9223372036854775808
%slide = getelementptr i8, ptr %obj, i64 9223372036854775807
%objsize = call i64 @llvm.objectsize.i64(ptr %slide, i1 false, i1 false, i1 false)
ret i64 %objsize
}
; We don't analyze allocations larger than platform's ptrdiff_t
define i64 @large_malloc() {
; CHECK-LABEL: @large_malloc(
; CHECK-NEXT: [[OBJ:%.*]] = call ptr @malloc(i64 -9223372036854775808)
; CHECK-NEXT: [[SLIDE:%.*]] = getelementptr i8, ptr [[OBJ]], i64 9223372036854775807
; CHECK-NEXT: ret i64 -1
;
%obj = call ptr @malloc(i64 9223372036854775808)
%slide = getelementptr i8, ptr %obj, i64 9223372036854775807
%objsize = call i64 @llvm.objectsize.i64(ptr %slide, i1 false, i1 false, i1 false)
ret i64 %objsize
}
define i64 @out_of_bound_negative_gep(i1 %c) {
; CHECK-LABEL: @out_of_bound_negative_gep(
; CHECK-NEXT: [[OBJ:%.*]] = alloca i8, i32 4, align 1
; CHECK-NEXT: [[SLIDE:%.*]] = getelementptr i8, ptr [[OBJ]], i8 -8
; CHECK-NEXT: ret i64 -1
;
%obj = alloca i8, i32 4
%slide = getelementptr i8, ptr %obj, i8 -8
%objsize = call i64 @llvm.objectsize.i64(ptr %slide, i1 false, i1 false, i1 false)
ret i64 %objsize
}
declare i32 @llvm.objectsize.i32.p0(ptr, i1, i1, i1)
|