1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -basic-aa -dse -S | FileCheck %s
3 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=dse -S | FileCheck %s
5 declare void @use(i64*)
9 ; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
10 ; CHECK-NEXT: call void @use(i64* [[A]])
11 ; CHECK-NEXT: [[PTR1:%.*]] = bitcast i64* [[A]] to i8*
12 ; CHECK-NEXT: [[PTR2:%.*]] = getelementptr i8, i8* [[PTR1]], i32 1
13 ; CHECK-NEXT: store i8 10, i8* [[PTR1]], align 1
14 ; CHECK-NEXT: store i8 20, i8* [[PTR2]], align 1
15 ; CHECK-NEXT: [[LV:%.*]] = load i64, i64* [[A]], align 4
16 ; CHECK-NEXT: store i8 0, i8* [[PTR1]], align 1
17 ; CHECK-NEXT: call void @use(i64* [[A]])
18 ; CHECK-NEXT: ret void
21 call void @use(i64* %a)
22 %ptr1 = bitcast i64* %a to i8*
23 %ptr2 = getelementptr i8, i8* %ptr1, i32 1
25 store i8 10, i8* %ptr1
26 store i8 20, i8* %ptr2
27 %lv = load i64, i64* %a
30 call void @use(i64* %a)
34 define void @test2() {
35 ; CHECK-LABEL: @test2(
36 ; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
37 ; CHECK-NEXT: call void @use(i64* [[A]])
38 ; CHECK-NEXT: [[PTR1:%.*]] = bitcast i64* [[A]] to i8*
39 ; CHECK-NEXT: [[PTR2:%.*]] = getelementptr i8, i8* [[PTR1]], i32 1
40 ; CHECK-NEXT: store i8 10, i8* [[PTR1]], align 1
41 ; CHECK-NEXT: store i8 20, i8* [[PTR2]], align 1
42 ; CHECK-NEXT: br i1 undef, label [[BB1:%.*]], label [[END:%.*]]
44 ; CHECK-NEXT: [[LV:%.*]] = load i64, i64* [[A]], align 4
45 ; CHECK-NEXT: br label [[END]]
47 ; CHECK-NEXT: store i8 0, i8* [[PTR1]], align 1
48 ; CHECK-NEXT: call void @use(i64* [[A]])
49 ; CHECK-NEXT: ret void
52 call void @use(i64* %a)
53 %ptr1 = bitcast i64* %a to i8*
54 %ptr2 = getelementptr i8, i8* %ptr1, i32 1
56 store i8 10, i8* %ptr1
57 store i8 20, i8* %ptr2
58 br i1 undef, label %bb1, label %end
61 %lv = load i64, i64* %a
66 call void @use(i64* %a)
70 ; The store to %a0 is dead, because only %a1 is read later.
71 define void @test3(i1 %c) {
72 ; CHECK-LABEL: @test3(
73 ; CHECK-NEXT: [[A:%.*]] = alloca [2 x i8], align 1
74 ; CHECK-NEXT: [[A1:%.*]] = getelementptr [2 x i8], [2 x i8]* [[A]], i32 0, i32 1
75 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
77 ; CHECK-NEXT: store [2 x i8] zeroinitializer, [2 x i8]* [[A]], align 1
78 ; CHECK-NEXT: br label [[ELSE]]
80 ; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[A1]], align 1
81 ; CHECK-NEXT: ret void
84 %a0 = getelementptr [2 x i8], [2 x i8]* %a, i32 0, i32 0
85 %a1 = getelementptr [2 x i8], [2 x i8]* %a, i32 0, i32 1
87 br i1 %c, label %if, label %else
90 store [2 x i8] zeroinitializer, [2 x i8]* %a
98 ; Variation on the previous test case, where only the store to %a0 is dead,
99 ; but not the one to %a1. This tests for a potential caching bug.
100 define void @test4(i1 %c) {
101 ; CHECK-LABEL: @test4(
102 ; CHECK-NEXT: [[A:%.*]] = alloca [2 x i8], align 1
103 ; CHECK-NEXT: [[A1:%.*]] = getelementptr [2 x i8], [2 x i8]* [[A]], i32 0, i32 1
104 ; CHECK-NEXT: store i8 1, i8* [[A1]], align 1
105 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
107 ; CHECK-NEXT: store [2 x i8] zeroinitializer, [2 x i8]* [[A]], align 1
108 ; CHECK-NEXT: br label [[ELSE]]
110 ; CHECK-NEXT: [[TMP1:%.*]] = load i8, i8* [[A1]], align 1
111 ; CHECK-NEXT: ret void
114 %a0 = getelementptr [2 x i8], [2 x i8]* %a, i32 0, i32 0
115 %a1 = getelementptr [2 x i8], [2 x i8]* %a, i32 0, i32 1
118 br i1 %c, label %if, label %else
121 store [2 x i8] zeroinitializer, [2 x i8]* %a