1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=ipsccp -S %s | FileCheck %s
4 ; A few test cases exposing crashes with the initial range implementation.
6 @global.2 = external dso_local unnamed_addr constant [25 x i8], align 1
7 @global = internal local_unnamed_addr global i32 0, align 4
8 @global.3 = internal local_unnamed_addr global i32 0, align 4
10 define void @main(ptr %arg) {
13 ; CHECK-NEXT: [[TMP:%.*]] = getelementptr inbounds ptr, ptr [[ARG:%.*]], i64 undef
14 ; CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[TMP]], align 8
15 ; CHECK-NEXT: [[TMP2:%.*]] = load i8, ptr [[TMP1]], align 1
16 ; CHECK-NEXT: [[TMP3:%.*]] = sext i8 [[TMP2]] to i32
17 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ne i32 [[TMP3]], 45
18 ; CHECK-NEXT: [[TMP5:%.*]] = select i1 [[TMP4]], i32 2, i32 4
19 ; CHECK-NEXT: ret void
22 %tmp = getelementptr inbounds ptr, ptr %arg, i64 undef
23 %tmp1 = load ptr, ptr %tmp, align 8
24 %tmp2 = load i8, ptr %tmp1, align 1
25 %tmp3 = sext i8 %tmp2 to i32
26 %tmp4 = icmp ne i32 %tmp3, 45
27 %tmp5 = select i1 %tmp4, i32 2, i32 4
31 define void @ham() local_unnamed_addr {
34 ; CHECK-NEXT: br label [[BB1:%.*]]
36 ; CHECK-NEXT: [[TMP:%.*]] = icmp slt i32 undef, 40
37 ; CHECK-NEXT: br i1 [[TMP]], label [[BB2:%.*]], label [[BB4:%.*]]
39 ; CHECK-NEXT: br label [[BB7:%.*]]
41 ; CHECK-NEXT: br label [[BB4]]
43 ; CHECK-NEXT: [[TMP5:%.*]] = phi i64 [ 0, [[BB1]] ], [ 15, [[BB3:%.*]] ]
44 ; CHECK-NEXT: [[TMP6:%.*]] = add i64 [[TMP5]], add (i64 xor (i64 ptrtoint (ptr @global.2 to i64), i64 -1), i64 1)
45 ; CHECK-NEXT: unreachable
47 ; CHECK-NEXT: br label [[BB3]]
53 %tmp = icmp slt i32 undef, 40
54 br i1 %tmp, label %bb2, label %bb4
62 bb4: ; preds = %bb3, %bb1
63 %tmp5 = phi i64 [ 0, %bb1 ], [ %tmp10, %bb3 ]
64 %tmp6 = add i64 %tmp5, add (i64 xor (i64 ptrtoint (ptr @global.2 to i64), i64 -1), i64 1)
69 %tmp9 = add i64 %tmp8, 0
70 %tmp10 = add i64 %tmp9, 0
74 declare i32 @barney.4()
76 define void @wobble() {
77 ; CHECK-LABEL: @wobble(
79 ; CHECK-NEXT: [[TMP:%.*]] = load i32, ptr @global, align 4
80 ; CHECK-NEXT: store i32 [[TMP]], ptr @global.3, align 4
81 ; CHECK-NEXT: ret void
84 %tmp = load i32, ptr @global, align 4
85 store i32 %tmp, ptr @global.3, align 4
89 define i32 @wobble.5(i32 %arg) {
91 %tmp = load i32, ptr @global.3, align 4
92 %tmp1 = sdiv i32 0, %tmp
99 ; CHECK-NEXT: br label [[BB1:%.*]]
101 ; CHECK-NEXT: [[TMP:%.*]] = phi i32 [ 0, [[BB:%.*]] ], [ [[TMP2:%.*]], [[BB1]] ]
102 ; CHECK-NEXT: [[TMP2]] = add nsw i32 [[TMP]], 1
103 ; CHECK-NEXT: [[TMP3:%.*]] = call i32 @barney.4()
104 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i32 [[TMP3]], 1
105 ; CHECK-NEXT: br i1 [[TMP4]], label [[BB1]], label [[BB5:%.*]]
107 ; CHECK-NEXT: store i32 [[TMP2]], ptr @global, align 4
108 ; CHECK-NEXT: ret void
113 bb1: ; preds = %bb1, %bb
114 %tmp = phi i32 [ 0, %bb ], [ %tmp2, %bb1 ]
115 %tmp2 = add nsw i32 %tmp, 1
116 %tmp3 = call i32 @barney.4()
117 %tmp4 = icmp eq i32 %tmp3, 1
118 br i1 %tmp4, label %bb1, label %bb5
121 store i32 %tmp2, ptr @global, align 4
125 declare ptr @bar(i32) local_unnamed_addr #3
127 ; Function Attrs: nounwind ssp uwtable
128 define { i8, ptr } @struct_crash(i32 %BitWidth) local_unnamed_addr #0 align 2 {
129 ; CHECK-LABEL: @struct_crash(
131 ; CHECK-NEXT: switch i32 [[BITWIDTH:%.*]], label [[IF_END:%.*]] [
132 ; CHECK-NEXT: i32 1, label [[CLEANUP:%.*]]
133 ; CHECK-NEXT: i32 8, label [[SW_BB1_I:%.*]]
136 ; CHECK-NEXT: br label [[CLEANUP]]
138 ; CHECK-NEXT: [[CALL_I:%.*]] = tail call ptr @bar(i32 [[BITWIDTH]])
139 ; CHECK-NEXT: br label [[CLEANUP]]
141 ; CHECK-NEXT: [[V1:%.*]] = phi ptr [ [[CALL_I]], [[IF_END]] ], [ null, [[SW_BB1_I]] ], [ null, [[ENTRY:%.*]] ]
142 ; CHECK-NEXT: [[V2:%.*]] = phi i8 [ 0, [[IF_END]] ], [ 3, [[SW_BB1_I]] ], [ 2, [[ENTRY]] ]
143 ; CHECK-NEXT: [[DOTFCA_0_INSERT:%.*]] = insertvalue { i8, ptr } undef, i8 [[V2]], 0
144 ; CHECK-NEXT: [[DOTFCA_1_INSERT:%.*]] = insertvalue { i8, ptr } [[DOTFCA_0_INSERT]], ptr [[V1]], 1
145 ; CHECK-NEXT: ret { i8, ptr } [[DOTFCA_1_INSERT]]
148 switch i32 %BitWidth, label %if.end [
149 i32 1, label %cleanup
150 i32 8, label %sw.bb1.i
153 sw.bb1.i: ; preds = %entry
156 if.end: ; preds = %entry
157 %call.i = tail call ptr @bar(i32 %BitWidth)
160 cleanup: ; preds = %entry, %sw.bb1.i, %sw.bb2.i, %sw.bb3.i, %sw.bb4.i, %sw.bb5.i, %if.end
161 %v1 = phi ptr [ %call.i, %if.end ], [ null, %sw.bb1.i ], [ null, %entry ]
162 %v2 = phi i8 [ 0, %if.end ], [ 3, %sw.bb1.i ], [ 2, %entry ]
163 %.fca.0.insert = insertvalue { i8, ptr } undef, i8 %v2, 0
164 %.fca.1.insert = insertvalue { i8, ptr } %.fca.0.insert, ptr %v1, 1
165 ret { i8, ptr } %.fca.1.insert
168 define i64 @crash_ctpop(i1 %cond, ptr %addr) {
169 ; CHECK-LABEL: @crash_ctpop(
171 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[IF_THEN:%.*]], label [[IF_ELSE:%.*]]
173 ; CHECK-NEXT: ret i64 0
175 ; CHECK-NEXT: [[LV:%.*]] = load i32, ptr [[ADDR:%.*]], align 8
176 ; CHECK-NEXT: [[ANDV:%.*]] = and i32 [[LV]], 16777215
177 ; CHECK-NEXT: [[TRUNCV:%.*]] = zext nneg i32 [[ANDV]] to i64
178 ; CHECK-NEXT: [[RES:%.*]] = tail call i64 @llvm.ctpop.i64(i64 [[TRUNCV]])
179 ; CHECK-NEXT: ret i64 [[RES]]
182 br i1 %cond, label %if.then, label %if.else
184 if.then: ; preds = %entry
187 if.else: ; preds = %entry
188 %lv = load i32, ptr %addr, align 8
189 %andv = and i32 %lv, 16777215
190 %truncv = zext i32 %andv to i64
191 %res = tail call i64 @llvm.ctpop.i64(i64 %truncv)
195 declare i64 @llvm.ctpop.i64(i64)