1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=dse -S | FileCheck %s
3 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=dse -S | FileCheck %s
9 ; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
10 ; CHECK-NEXT: call void @use(ptr [[A]])
11 ; CHECK-NEXT: [[PTR2:%.*]] = getelementptr i8, ptr [[A]], i32 1
12 ; CHECK-NEXT: store i8 10, ptr [[A]], align 1
13 ; CHECK-NEXT: store i8 20, ptr [[PTR2]], align 1
14 ; CHECK-NEXT: [[LV:%.*]] = load i64, ptr [[A]], align 4
15 ; CHECK-NEXT: store i8 0, ptr [[A]], align 1
16 ; CHECK-NEXT: call void @use(ptr [[A]])
17 ; CHECK-NEXT: ret void
20 call void @use(ptr %a)
21 %ptr2 = getelementptr i8, ptr %a, i32 1
24 store i8 20, ptr %ptr2
25 %lv = load i64, ptr %a
28 call void @use(ptr %a)
32 define void @test2(i1 %arg) {
33 ; CHECK-LABEL: @test2(
34 ; CHECK-NEXT: [[A:%.*]] = alloca i64, align 8
35 ; CHECK-NEXT: call void @use(ptr [[A]])
36 ; CHECK-NEXT: [[PTR2:%.*]] = getelementptr i8, ptr [[A]], i32 1
37 ; CHECK-NEXT: store i8 10, ptr [[A]], align 1
38 ; CHECK-NEXT: store i8 20, ptr [[PTR2]], align 1
39 ; CHECK-NEXT: br i1 %arg, label [[BB1:%.*]], label [[END:%.*]]
41 ; CHECK-NEXT: [[LV:%.*]] = load i64, ptr [[A]], align 4
42 ; CHECK-NEXT: br label [[END]]
44 ; CHECK-NEXT: store i8 0, ptr [[A]], align 1
45 ; CHECK-NEXT: call void @use(ptr [[A]])
46 ; CHECK-NEXT: ret void
49 call void @use(ptr %a)
50 %ptr2 = getelementptr i8, ptr %a, i32 1
53 store i8 20, ptr %ptr2
54 br i1 %arg, label %bb1, label %end
57 %lv = load i64, ptr %a
62 call void @use(ptr %a)
66 ; The store to %a0 is dead, because only %a1 is read later.
67 define void @test3(i1 %c) {
68 ; CHECK-LABEL: @test3(
69 ; CHECK-NEXT: [[A:%.*]] = alloca [2 x i8], align 1
70 ; CHECK-NEXT: [[A1:%.*]] = getelementptr [2 x i8], ptr [[A]], i32 0, i32 1
71 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
73 ; CHECK-NEXT: store [2 x i8] zeroinitializer, ptr [[A]], align 1
74 ; CHECK-NEXT: br label [[ELSE]]
76 ; CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[A1]], align 1
77 ; CHECK-NEXT: ret void
80 %a1 = getelementptr [2 x i8], ptr %a, i32 0, i32 1
82 br i1 %c, label %if, label %else
85 store [2 x i8] zeroinitializer, ptr %a
93 ; Variation on the previous test case, where only the store to %a is dead,
94 ; but not the one to %a1. This tests for a potential caching bug.
95 define void @test4(i1 %c) {
96 ; CHECK-LABEL: @test4(
97 ; CHECK-NEXT: [[A:%.*]] = alloca [2 x i8], align 1
98 ; CHECK-NEXT: [[A1:%.*]] = getelementptr [2 x i8], ptr [[A]], i32 0, i32 1
99 ; CHECK-NEXT: store i8 1, ptr [[A1]], align 1
100 ; CHECK-NEXT: br i1 [[C:%.*]], label [[IF:%.*]], label [[ELSE:%.*]]
102 ; CHECK-NEXT: store [2 x i8] zeroinitializer, ptr [[A]], align 1
103 ; CHECK-NEXT: br label [[ELSE]]
105 ; CHECK-NEXT: [[TMP1:%.*]] = load i8, ptr [[A1]], align 1
106 ; CHECK-NEXT: ret void
109 %a1 = getelementptr [2 x i8], ptr %a, i32 0, i32 1
112 br i1 %c, label %if, label %else
115 store [2 x i8] zeroinitializer, ptr %a