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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
|
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -passes=dse -enable-dse-initializes-attr-improvement -S | FileCheck %s
declare void @p1_write_only(ptr nocapture noundef writeonly initializes((0, 2)) dead_on_unwind)
declare void @p1_write_then_read(ptr nocapture noundef initializes((0, 2)) dead_on_unwind)
declare void @p1_clobber(ptr nocapture noundef)
declare void @p2_same_range(ptr nocapture noundef initializes((0, 2)) dead_on_unwind, ptr nocapture noundef initializes((0, 2)) dead_on_unwind)
declare void @p2_no_init(ptr nocapture noundef initializes((0, 2)) dead_on_unwind, ptr nocapture noundef dead_on_unwind)
declare void @p2_no_dead_on_unwind(ptr nocapture noundef initializes((0, 2)) dead_on_unwind, ptr nocapture noundef initializes((0, 2)))
declare void @p2_no_dead_on_unwind_but_nounwind(ptr nocapture noundef initializes((0, 2)) dead_on_unwind, ptr nocapture noundef initializes((0, 2))) nounwind
; Function Attrs: mustprogress nounwind uwtable
define i16 @p1_write_only_caller() {
; CHECK-LABEL: @p1_write_only_caller(
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
; CHECK-NEXT: call void @p1_write_only(ptr [[PTR]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr = alloca i16
store i16 0, ptr %ptr
call void @p1_write_only(ptr %ptr)
%l = load i16, ptr %ptr
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @p1_write_then_read_caller() {
; CHECK-LABEL: @p1_write_then_read_caller(
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
; CHECK-NEXT: call void @p1_write_then_read(ptr [[PTR]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr = alloca i16
store i16 0, ptr %ptr
call void @p1_write_then_read(ptr %ptr)
%l = load i16, ptr %ptr
ret i16 %l
}
declare void @fn_capture(ptr)
define i16 @p1_write_then_read_caller_escape() {
; CHECK-LABEL: @p1_write_then_read_caller_escape(
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
; CHECK-NEXT: store i16 0, ptr [[PTR]], align 2
; CHECK-NEXT: call void @fn_capture(ptr [[PTR]])
; CHECK-NEXT: call void @p1_write_then_read(ptr [[PTR]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr = alloca i16
store i16 0, ptr %ptr
call void @fn_capture(ptr %ptr)
call void @p1_write_then_read(ptr %ptr)
%l = load i16, ptr %ptr
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @p1_write_then_read_caller_with_clobber() {
; CHECK-LABEL: @p1_write_then_read_caller_with_clobber(
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
; CHECK-NEXT: store i16 0, ptr [[PTR]], align 2
; CHECK-NEXT: call void @p1_clobber(ptr [[PTR]])
; CHECK-NEXT: call void @p1_write_then_read(ptr [[PTR]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr = alloca i16
store i16 0, ptr %ptr
call void @p1_clobber(ptr %ptr)
call void @p1_write_then_read(ptr %ptr)
%l = load i16, ptr %ptr
ret i16 %l
}
declare void @p1_write_then_read_raw(ptr nocapture noundef initializes((0, 2)))
define i16 @p1_initializes_invoke() personality ptr undef {
; CHECK-LABEL: @p1_initializes_invoke(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
; CHECK-NEXT: store i16 0, ptr [[PTR]], align 2
; CHECK-NEXT: invoke void @p1_write_then_read_raw(ptr [[PTR]])
; CHECK-NEXT: to label [[BB1:%.*]] unwind label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: ret i16 0
; CHECK: bb2:
; CHECK-NEXT: [[TMP:%.*]] = landingpad { ptr, i32 }
; CHECK-NEXT: cleanup
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
entry:
%ptr = alloca i16
store i16 0, ptr %ptr
invoke void @p1_write_then_read_raw(ptr %ptr) to label %bb1 unwind label %bb2
bb1:
ret i16 0
bb2:
%tmp = landingpad { ptr, i32 }
cleanup
%l = load i16, ptr %ptr
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @p2_same_range_noalias_caller() {
; CHECK-LABEL: @p2_same_range_noalias_caller(
; CHECK-NEXT: [[PTR1:%.*]] = alloca i16, align 2
; CHECK-NEXT: [[PTR2:%.*]] = alloca i16, align 2
; CHECK-NEXT: call void @p2_same_range(ptr [[PTR1]], ptr [[PTR2]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR1]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr1 = alloca i16
%ptr2 = alloca i16
store i16 0, ptr %ptr1
store i16 0, ptr %ptr2
call void @p2_same_range(ptr %ptr1, ptr %ptr2)
%l = load i16, ptr %ptr1
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @p2_same_range_must_alias_caller() {
; CHECK-LABEL: @p2_same_range_must_alias_caller(
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
; CHECK-NEXT: call void @p2_same_range(ptr [[PTR]], ptr [[PTR]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr = alloca i16
store i16 0, ptr %ptr
call void @p2_same_range(ptr %ptr, ptr %ptr)
%l = load i16, ptr %ptr
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @p2_same_range_may_or_partial_alias_caller1(ptr %base, i1 %x) {
; CHECK-LABEL: @p2_same_range_may_or_partial_alias_caller1(
; CHECK-NEXT: [[BASEPLUS:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 1
; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], ptr [[BASEPLUS]], ptr [[BASE]]
; CHECK-NEXT: store i32 0, ptr [[BASE]], align 4
; CHECK-NEXT: call void @p2_same_range(ptr [[BASE]], ptr [[SEL]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[BASE]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%baseplus = getelementptr i8, ptr %base, i64 1
%sel = select i1 %x, ptr %baseplus, ptr %base
store i32 0, ptr %base
call void @p2_same_range(ptr %base, ptr %sel)
%l = load i16, ptr %base
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @p2_same_range_may_or_partial_alias_caller2(ptr %base1, ptr %base2) {
; CHECK-LABEL: @p2_same_range_may_or_partial_alias_caller2(
; CHECK-NEXT: store i32 0, ptr [[BASE1:%.*]], align 4
; CHECK-NEXT: call void @p2_same_range(ptr [[BASE1]], ptr [[BASE2:%.*]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[BASE1]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
store i32 0, ptr %base1
call void @p2_same_range(ptr %base1, ptr %base2)
%l = load i16, ptr %base1
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @p2_no_init_alias_caller() {
; CHECK-LABEL: @p2_no_init_alias_caller(
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
; CHECK-NEXT: store i16 0, ptr [[PTR]], align 2
; CHECK-NEXT: call void @p2_no_init(ptr [[PTR]], ptr [[PTR]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr = alloca i16
store i16 0, ptr %ptr
call void @p2_no_init(ptr %ptr, ptr %ptr)
%l = load i16, ptr %ptr
ret i16 %l
}
; Althrough the 2nd parameter of `p2_no_dead_on_unwind` doesn't have
; the 'dead_on_unwind' attribute, it's invisble to caller on unwind.
; DSE still uses the 'initializes' attribute and kill the dead store.
; Function Attrs: mustprogress nounwind uwtable
define i16 @p2_no_dead_on_unwind_but_invisible_to_caller_alias_caller() {
; CHECK-LABEL: @p2_no_dead_on_unwind_but_invisible_to_caller_alias_caller(
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
; CHECK-NEXT: call void @p2_no_dead_on_unwind(ptr [[PTR]], ptr [[PTR]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr = alloca i16
store i16 0, ptr %ptr
call void @p2_no_dead_on_unwind(ptr %ptr, ptr %ptr)
%l = load i16, ptr %ptr
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @p2_no_dead_on_unwind_alias_caller(ptr %ptr) {
; CHECK-LABEL: @p2_no_dead_on_unwind_alias_caller(
; CHECK-NEXT: store i16 0, ptr [[PTR:%.*]], align 2
; CHECK-NEXT: call void @p2_no_dead_on_unwind(ptr [[PTR]], ptr [[PTR]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
store i16 0, ptr %ptr
call void @p2_no_dead_on_unwind(ptr %ptr, ptr %ptr)
%l = load i16, ptr %ptr
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @p2_no_dead_on_unwind_but_nounwind_alias_caller() {
; CHECK-LABEL: @p2_no_dead_on_unwind_but_nounwind_alias_caller(
; CHECK-NEXT: [[PTR:%.*]] = alloca i16, align 2
; CHECK-NEXT: call void @p2_no_dead_on_unwind_but_nounwind(ptr [[PTR]], ptr [[PTR]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr = alloca i16
store i16 0, ptr %ptr
call void @p2_no_dead_on_unwind_but_nounwind(ptr %ptr, ptr %ptr)
%l = load i16, ptr %ptr
ret i16 %l
}
declare void @llvm.memset.p0.i64(ptr nocapture, i8, i64, i1) nounwind
declare void @large_p1(ptr nocapture noundef initializes((0, 200))) nounwind
declare void @large_p2(ptr nocapture noundef initializes((0, 200)), ptr nocapture noundef initializes((0, 100))) nounwind
; Function Attrs: mustprogress nounwind uwtable
define i16 @large_p1_caller() {
; CHECK-LABEL: @large_p1_caller(
; CHECK-NEXT: [[PTR:%.*]] = alloca [300 x i8], align 1
; CHECK-NEXT: [[TMP:%.*]] = getelementptr i8, ptr [[PTR]], i64 100
; CHECK-NEXT: call void @large_p1(ptr [[TMP]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[TMP]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr = alloca [300 x i8]
%tmp = getelementptr i8, ptr %ptr, i64 100
call void @llvm.memset.p0.i64(ptr %tmp, i8 42, i64 100, i1 false)
call void @large_p1(ptr %tmp)
%l = load i16, ptr %tmp
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @large_p2_nonalias_caller() {
; CHECK-LABEL: @large_p2_nonalias_caller(
; CHECK-NEXT: [[PTR1:%.*]] = alloca [200 x i8], align 1
; CHECK-NEXT: [[PTR2:%.*]] = alloca [100 x i8], align 1
; CHECK-NEXT: call void @large_p2(ptr [[PTR1]], ptr [[PTR2]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR1]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr1 = alloca [200 x i8]
%ptr2 = alloca [100 x i8]
call void @llvm.memset.p0.i64(ptr %ptr1, i8 42, i64 200, i1 false)
call void @llvm.memset.p0.i64(ptr %ptr2, i8 42, i64 100, i1 false)
call void @large_p2(ptr %ptr1, ptr %ptr2)
%l = load i16, ptr %ptr1
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @large_p2_must_alias_caller() {
; CHECK-LABEL: @large_p2_must_alias_caller(
; CHECK-NEXT: [[PTR:%.*]] = alloca [300 x i8], align 1
; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i8, ptr [[PTR]], i64 100
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 1 [[TMP1]], i8 42, i64 200, i1 false)
; CHECK-NEXT: call void @large_p2(ptr [[PTR]], ptr [[PTR]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[PTR]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%ptr = alloca [300 x i8]
call void @llvm.memset.p0.i64(ptr %ptr, i8 42, i64 300, i1 false)
call void @large_p2(ptr %ptr, ptr %ptr)
%l = load i16, ptr %ptr
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @large_p2_may_or_partial_alias_caller1(ptr %base) {
; CHECK-LABEL: @large_p2_may_or_partial_alias_caller1(
; CHECK-NEXT: [[BASEPLUS:%.*]] = getelementptr i8, ptr [[BASE:%.*]], i64 100
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr [[BASE]], i8 42, i64 300, i1 false)
; CHECK-NEXT: call void @large_p2(ptr [[BASE]], ptr [[BASEPLUS]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[BASE]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
%baseplus = getelementptr i8, ptr %base, i64 100
call void @llvm.memset.p0.i64(ptr %base, i8 42, i64 300, i1 false)
call void @large_p2(ptr %base, ptr %baseplus)
%l = load i16, ptr %base
ret i16 %l
}
; Function Attrs: mustprogress nounwind uwtable
define i16 @large_p2_may_or_partial_alias_caller2(ptr %base1, ptr %base2) {
; CHECK-LABEL: @large_p2_may_or_partial_alias_caller2(
; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr [[BASE1:%.*]], i8 42, i64 300, i1 false)
; CHECK-NEXT: call void @large_p2(ptr [[BASE1]], ptr [[BASE2:%.*]])
; CHECK-NEXT: [[L:%.*]] = load i16, ptr [[BASE1]], align 2
; CHECK-NEXT: ret i16 [[L]]
;
call void @llvm.memset.p0.i64(ptr %base1, i8 42, i64 300, i1 false)
call void @large_p2(ptr %base1, ptr %base2)
%l = load i16, ptr %base1
ret i16 %l
}
@g = global i16 123, align 2
declare void @read_global(ptr nocapture noundef initializes((0, 2))) nounwind
memory(read, argmem: write, inaccessiblemem: none) nounwind
define i16 @global_var_alias() {
; CHECK-LABEL: @global_var_alias(
; CHECK-NEXT: store i16 0, ptr @g, align 4
; CHECK-NEXT: call void @read_global(ptr @g)
; CHECK-NEXT: [[L:%.*]] = load i16, ptr @g, align 2
; CHECK-NEXT: ret i16 [[L]]
;
store i16 0, ptr @g, align 4
call void @read_global(ptr @g)
%l = load i16, ptr @g
ret i16 %l
}
declare void @byval_fn(ptr byval(i32) initializes((0, 4)) %am)
define void @test_byval() {
; CHECK-LABEL: @test_byval(
; CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
; CHECK-NEXT: store i32 0, ptr [[A]], align 4
; CHECK-NEXT: call void @byval_fn(ptr [[A]])
; CHECK-NEXT: ret void
;
%a = alloca i32
store i32 0, ptr %a
call void @byval_fn(ptr %a)
ret void
}
|