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
|
; 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
}
declare i32 @llvm.objectsize.i32.p0(ptr, i1, i1, i1)
|