1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -basic-aa -dse -S | FileCheck %s
4 target datalayout = "e-p:64:64:64"
6 declare void @free(i8* nocapture)
7 declare noalias i8* @malloc(i64)
9 define void @test(i32* %Q, i32* %P) {
11 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast i32* [[P:%.*]] to i8*
12 ; CHECK-NEXT: tail call void @free(i8* [[TMP1]]) [[ATTR0:#.*]]
13 ; CHECK-NEXT: ret void
15 %DEAD = load i32, i32* %Q ; <i32> [#uses=1]
16 store i32 %DEAD, i32* %P
17 %1 = bitcast i32* %P to i8*
18 tail call void @free(i8* %1) nounwind
22 define void @test2({i32, i32}* %P) {
23 ; CHECK-LABEL: @test2(
24 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast { i32, i32 }* [[P:%.*]] to i8*
25 ; CHECK-NEXT: tail call void @free(i8* [[TMP1]]) [[ATTR0]]
26 ; CHECK-NEXT: ret void
28 %Q = getelementptr {i32, i32}, {i32, i32} *%P, i32 0, i32 1
30 %1 = bitcast {i32, i32}* %P to i8*
31 tail call void @free(i8* %1) nounwind
35 define void @test3() {
36 ; CHECK-LABEL: @test3(
37 ; CHECK-NEXT: [[M:%.*]] = call i8* @malloc(i64 24)
38 ; CHECK-NEXT: call void @free(i8* [[M]]) [[ATTR0]]
39 ; CHECK-NEXT: ret void
41 %m = call i8* @malloc(i64 24)
43 %m1 = getelementptr i8, i8* %m, i64 1
45 call void @free(i8* %m) nounwind
50 define void @test4(i1 %x) nounwind {
51 ; CHECK-LABEL: @test4(
53 ; CHECK-NEXT: [[ALLOC1:%.*]] = tail call noalias i8* @malloc(i64 4) [[ATTR0]]
54 ; CHECK-NEXT: br i1 [[X:%.*]], label [[SKIPINIT1:%.*]], label [[INIT1:%.*]]
56 ; CHECK-NEXT: br label [[SKIPINIT1]]
58 ; CHECK-NEXT: tail call void @free(i8* [[ALLOC1]]) [[ATTR0]]
59 ; CHECK-NEXT: ret void
62 %alloc1 = tail call noalias i8* @malloc(i64 4) nounwind
63 br i1 %x, label %skipinit1, label %init1
66 store i8 1, i8* %alloc1
70 tail call void @free(i8* %alloc1) nounwind
74 define void @test5() {
75 ; CHECK-LABEL: @test5(
76 ; CHECK-NEXT: br label [[BB:%.*]]
78 ; CHECK-NEXT: tail call void @free(i8* undef) [[ATTR0]]
79 ; CHECK-NEXT: br label [[BB]]
84 tail call void @free(i8* undef) nounwind
89 %struct = type { i32 , i32 }
91 ; Test case inspired by PR48036.
92 define void @delete_field_after(%struct* %ptr) {
94 ; CHECK-LABEL: @delete_field_after(
95 ; CHECK-NEXT: [[PTR_F0:%.*]] = getelementptr [[STRUCT:%.*]], %struct* [[PTR:%.*]], i32 1
96 ; CHECK-NEXT: [[BC:%.*]] = bitcast %struct* [[PTR_F0]] to i8*
97 ; CHECK-NEXT: [[PTR_F1:%.*]] = getelementptr [[STRUCT]], %struct* [[PTR]], i32 0, i32 1
98 ; CHECK-NEXT: store i32 0, i32* [[PTR_F1]], align 4
99 ; CHECK-NEXT: call void @free(i8* [[BC]])
100 ; CHECK-NEXT: ret void
102 %ptr.f0 = getelementptr %struct, %struct* %ptr, i32 1
103 %bc = bitcast %struct* %ptr.f0 to i8*
104 %ptr.f1 = getelementptr %struct, %struct* %ptr, i32 0, i32 1
105 store i32 0, i32* %ptr.f1
106 call void @free(i8* %bc)
110 ; Test case inspired by PR48036.
111 define void @delete_field_before(%struct* %ptr) {
112 ; CHECK-LABEL: @delete_field_before(
113 ; CHECK-NEXT: [[PTR_F0:%.*]] = getelementptr [[STRUCT:%.*]], %struct* [[PTR:%.*]], i32 0
114 ; CHECK-NEXT: [[BC:%.*]] = bitcast %struct* [[PTR_F0]] to i8*
115 ; CHECK-NEXT: call void @free(i8* [[BC]])
116 ; CHECK-NEXT: ret void
118 %ptr.f0 = getelementptr %struct, %struct* %ptr, i32 0
119 %bc = bitcast %struct* %ptr.f0 to i8*
120 %ptr.f1 = getelementptr %struct, %struct* %ptr, i32 1, i32 1
121 store i32 0, i32* %ptr.f1
122 call void @free(i8* %bc)