1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=dse %s -S | FileCheck --check-prefixes=CHECK %s
5 %struct.ham = type { [3 x double], [3 x double]}
7 declare void @may_throw()
8 declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg)
10 ; We miss this case, because of an aggressive limit of partial overlap analysis.
11 ; With a larger partial store limit, we remove the memset.
12 define void @overlap1(ptr %arg, i1 %cond) {
13 ; CHECK-LABEL: @overlap1(
15 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds [[STRUCT_HAM:%.*]], ptr [[ARG:%.*]], i64 0, i32 0, i64 2
16 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_HAM]], ptr [[ARG]], i64 0, i32 0, i64 1
17 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [[STRUCT_HAM]], ptr [[ARG]], i64 0, i32 1, i64 2
18 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds [[STRUCT_HAM]], ptr [[ARG]], i64 0, i32 1, i64 1
19 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds [[STRUCT_HAM]], ptr [[ARG]], i64 0, i32 1, i32 0
20 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB7:%.*]], label [[BB8:%.*]]
22 ; CHECK-NEXT: br label [[BB9:%.*]]
24 ; CHECK-NEXT: br label [[BB9]]
26 ; CHECK-NEXT: store double 1.000000e+00, ptr [[ARG]], align 8
27 ; CHECK-NEXT: store double 2.000000e+00, ptr [[TMP1]], align 8
28 ; CHECK-NEXT: store double 3.000000e+00, ptr [[TMP]], align 8
29 ; CHECK-NEXT: store double 4.000000e+00, ptr [[TMP5]], align 8
30 ; CHECK-NEXT: store double 5.000000e+00, ptr [[TMP4]], align 8
31 ; CHECK-NEXT: store double 6.000000e+00, ptr [[TMP3]], align 8
32 ; CHECK-NEXT: ret void
35 %tmp = getelementptr inbounds %struct.ham, ptr %arg, i64 0, i32 0, i64 2
36 %tmp1 = getelementptr inbounds %struct.ham, ptr %arg, i64 0, i32 0, i64 1
37 %tmp3 = getelementptr inbounds %struct.ham, ptr %arg, i64 0,i32 1, i64 2
38 %tmp4 = getelementptr inbounds %struct.ham, ptr %arg, i64 0, i32 1, i64 1
39 %tmp5 = getelementptr inbounds %struct.ham, ptr %arg, i64 0, i32 1, i32 0
40 call void @llvm.memset.p0.i64(ptr nonnull align 8 dereferenceable(48) %arg, i8 0, i64 48, i1 false)
41 br i1 %cond, label %bb7, label %bb8
49 bb9: ; preds = %bb8, %bb7
50 store double 1.0, ptr %arg, align 8
51 store double 2.0, ptr %tmp1, align 8
52 store double 3.0, ptr %tmp, align 8
53 store double 4.0, ptr %tmp5, align 8
54 store double 5.0, ptr %tmp4, align 8
55 store double 6.0, ptr %tmp3, align 8
59 define void @overlap2(ptr %arg, i1 %cond) {
60 ; CHECK-LABEL: @overlap2(
62 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds [[STRUCT_HAM:%.*]], ptr [[ARG:%.*]], i64 0, i32 0, i64 2
63 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds [[STRUCT_HAM]], ptr [[ARG]], i64 0, i32 0, i64 1
64 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds [[STRUCT_HAM]], ptr [[ARG]], i64 0, i32 1, i64 2
65 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds [[STRUCT_HAM]], ptr [[ARG]], i64 0, i32 1, i64 1
66 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds [[STRUCT_HAM]], ptr [[ARG]], i64 0, i32 1, i32 0
67 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr nonnull align 8 dereferenceable(48) [[ARG]], i8 0, i64 48, i1 false)
68 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB7:%.*]], label [[BB8:%.*]]
70 ; CHECK-NEXT: call void @may_throw()
71 ; CHECK-NEXT: br label [[BB9:%.*]]
73 ; CHECK-NEXT: br label [[BB9]]
75 ; CHECK-NEXT: store double 1.000000e+00, ptr [[ARG]], align 8
76 ; CHECK-NEXT: store double 2.000000e+00, ptr [[TMP1]], align 8
77 ; CHECK-NEXT: store double 3.000000e+00, ptr [[TMP]], align 8
78 ; CHECK-NEXT: store double 4.000000e+00, ptr [[TMP5]], align 8
79 ; CHECK-NEXT: store double 5.000000e+00, ptr [[TMP4]], align 8
80 ; CHECK-NEXT: store double 6.000000e+00, ptr [[TMP3]], align 8
81 ; CHECK-NEXT: ret void
84 %tmp = getelementptr inbounds %struct.ham, ptr %arg, i64 0, i32 0, i64 2
85 %tmp1 = getelementptr inbounds %struct.ham, ptr %arg, i64 0, i32 0, i64 1
86 %tmp3 = getelementptr inbounds %struct.ham, ptr %arg, i64 0,i32 1, i64 2
87 %tmp4 = getelementptr inbounds %struct.ham, ptr %arg, i64 0, i32 1, i64 1
88 %tmp5 = getelementptr inbounds %struct.ham, ptr %arg, i64 0, i32 1, i32 0
89 call void @llvm.memset.p0.i64(ptr nonnull align 8 dereferenceable(48) %arg, i8 0, i64 48, i1 false)
90 br i1 %cond, label %bb7, label %bb8
93 call void @may_throw()
99 bb9: ; preds = %bb8, %bb7
100 store double 1.0, ptr %arg, align 8
101 store double 2.0, ptr %tmp1, align 8
102 store double 3.0, ptr %tmp, align 8
103 store double 4.0, ptr %tmp5, align 8
104 store double 5.0, ptr %tmp4, align 8
105 store double 6.0, ptr %tmp3, align 8
109 ; Test case from PR46513. Make sure we do not crash.
110 ; TODO: we should be able to shorten store i32 844283136, ptr %cast.i32 to a
112 define void @overlap_no_dominance(ptr %arg, i1 %c) {
113 ; CHECK-LABEL: @overlap_no_dominance(
115 ; CHECK-NEXT: br i1 [[C:%.*]], label [[BB13:%.*]], label [[BB9:%.*]]
117 ; CHECK-NEXT: store i32 844283136, ptr [[ARG:%.*]], align 4
118 ; CHECK-NEXT: br label [[BB13]]
120 ; CHECK-NEXT: store i16 0, ptr [[ARG]], align 4
121 ; CHECK-NEXT: ret void
124 br i1 %c, label %bb13, label %bb9
127 store i32 844283136, ptr %arg, align 4
130 bb13: ; preds = %bb9, %bb
131 store i16 0, ptr %arg, align 4