1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=dse -S | FileCheck %s
4 target datalayout = "e-p:64:64:64"
6 declare void @free(ptr nocapture) allockind("free")
7 declare noalias ptr @malloc(i64) allockind("alloc,uninitialized")
9 define void @test(ptr %Q, ptr %P) {
11 ; CHECK-NEXT: tail call void @free(ptr [[P:%.*]]) [[ATTR0:#.*]]
12 ; CHECK-NEXT: ret void
14 %DEAD = load i32, ptr %Q ; <i32> [#uses=1]
15 store i32 %DEAD, ptr %P
16 tail call void @free(ptr %P) nounwind
20 define void @test2(ptr %P) {
21 ; CHECK-LABEL: @test2(
22 ; CHECK-NEXT: tail call void @free(ptr [[P:%.*]]) [[ATTR0]]
23 ; CHECK-NEXT: ret void
25 %Q = getelementptr {i32, i32}, ptr %P, i32 0, i32 1
27 tail call void @free(ptr %P) nounwind
31 define void @test3() {
32 ; CHECK-LABEL: @test3(
33 ; CHECK-NEXT: [[M:%.*]] = call ptr @malloc(i64 24)
34 ; CHECK-NEXT: call void @free(ptr [[M]]) [[ATTR0]]
35 ; CHECK-NEXT: ret void
37 %m = call ptr @malloc(i64 24)
39 %m1 = getelementptr i8, ptr %m, i64 1
41 call void @free(ptr %m) nounwind
46 define void @test4(i1 %x) nounwind {
47 ; CHECK-LABEL: @test4(
49 ; CHECK-NEXT: [[ALLOC1:%.*]] = tail call noalias ptr @malloc(i64 4) [[ATTR0]]
50 ; CHECK-NEXT: br i1 [[X:%.*]], label [[SKIPINIT1:%.*]], label [[INIT1:%.*]]
52 ; CHECK-NEXT: br label [[SKIPINIT1]]
54 ; CHECK-NEXT: tail call void @free(ptr [[ALLOC1]]) [[ATTR0]]
55 ; CHECK-NEXT: ret void
58 %alloc1 = tail call noalias ptr @malloc(i64 4) nounwind
59 br i1 %x, label %skipinit1, label %init1
62 store i8 1, ptr %alloc1
66 tail call void @free(ptr %alloc1) nounwind
70 define void @test5() {
71 ; CHECK-LABEL: @test5(
72 ; CHECK-NEXT: br label [[BB:%.*]]
74 ; CHECK-NEXT: tail call void @free(ptr undef) [[ATTR0]]
75 ; CHECK-NEXT: br label [[BB]]
80 tail call void @free(ptr undef) nounwind
85 %struct = type { i32 , i32 }
87 ; Test case inspired by PR48036.
88 define void @delete_field_after(ptr %ptr) {
90 ; CHECK-LABEL: @delete_field_after(
91 ; CHECK-NEXT: [[PTR_F0:%.*]] = getelementptr [[STRUCT:%.*]], ptr [[PTR:%.*]], i32 1
92 ; CHECK-NEXT: [[PTR_F1:%.*]] = getelementptr [[STRUCT]], ptr [[PTR]], i32 0, i32 1
93 ; CHECK-NEXT: store i32 0, ptr [[PTR_F1]], align 4
94 ; CHECK-NEXT: call void @free(ptr [[PTR_F0]])
95 ; CHECK-NEXT: ret void
97 %ptr.f0 = getelementptr %struct, ptr %ptr, i32 1
98 %ptr.f1 = getelementptr %struct, ptr %ptr, i32 0, i32 1
99 store i32 0, ptr %ptr.f1
100 call void @free(ptr %ptr.f0)
104 ; Test case inspired by PR48036.
105 define void @delete_field_before(ptr %ptr) {
106 ; CHECK-LABEL: @delete_field_before(
107 ; CHECK-NEXT: call void @free(ptr [[PTR:%.*]])
108 ; CHECK-NEXT: ret void
110 %ptr.f1 = getelementptr %struct, ptr %ptr, i32 1, i32 1
111 store i32 0, ptr %ptr.f1
112 call void @free(ptr %ptr)