1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -dse -S %s | FileCheck %s
6 ; Out-of-bounds stores can be considered killing any other stores to the same
7 ; object in the same BB, because they are UB and guaranteed to execute. Note
8 ; that cases in which the BB is exited through unwinding are handled separately
9 ; by DSE and the unwinding call will be considered as clobber.
10 define i32 @test_out_of_bounds_store_local(i1 %c) {
11 ; CHECK-LABEL: @test_out_of_bounds_store_local(
12 ; CHECK-NEXT: [[D:%.*]] = alloca [1 x i32], align 4
13 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[D]], i64 0, i64 0
14 ; CHECK-NEXT: [[LV1:%.*]] = load i32, i32* [[ARRAYIDX1]], align 4
15 ; CHECK-NEXT: call void @use(i32 [[LV1]])
16 ; CHECK-NEXT: ret i32 0
18 %d = alloca [1 x i32], align 4
19 %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 0
20 store i32 10, i32* %arrayidx, align 4
21 %arrayidx.1 = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 1
22 store i32 20, i32* %arrayidx.1, align 4
23 %arrayidx1 = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 0
24 %lv1 = load i32, i32* %arrayidx1, align 4
25 call void @use(i32 %lv1)
29 ; Make sure that out-of-bound stores are not considered killing other stores to
30 ; the same underlying object, if they are in different basic blocks. The
31 ; out-of-bounds store may not be executed.
33 ; Test case from PR48279. FIXME.
34 define i32 @test_out_of_bounds_store_nonlocal(i1 %c) {
35 ; CHECK-LABEL: @test_out_of_bounds_store_nonlocal(
36 ; CHECK-NEXT: [[D:%.*]] = alloca [1 x i32], align 4
37 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
39 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[D]], i64 0, i64 0
40 ; CHECK-NEXT: store i32 10, i32* [[ARRAYIDX]], align 4
41 ; CHECK-NEXT: br label [[FOR_INC:%.*]]
43 ; CHECK-NEXT: br i1 [[C:%.*]], label [[FOR_BODY_1:%.*]], label [[FOR_END:%.*]]
45 ; CHECK-NEXT: ret i32 1
47 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds [1 x i32], [1 x i32]* [[D]], i64 0, i64 0
48 ; CHECK-NEXT: [[LV1:%.*]] = load i32, i32* [[ARRAYIDX1]], align 4
49 ; CHECK-NEXT: call void @use(i32 [[LV1]])
50 ; CHECK-NEXT: ret i32 0
52 %d = alloca [1 x i32], align 4
55 for.body: ; preds = %for.cond
56 %arrayidx = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 0
57 store i32 10, i32* %arrayidx, align 4
60 for.inc: ; preds = %for.body
61 br i1 %c, label %for.body.1, label %for.end
63 for.body.1: ; preds = %for.inc
64 %arrayidx.1 = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 1
65 store i32 20, i32* %arrayidx.1, align 4
68 for.end: ; preds = %for.inc
69 %arrayidx1 = getelementptr inbounds [1 x i32], [1 x i32]* %d, i64 0, i64 0
70 %lv1 = load i32, i32* %arrayidx1, align 4
71 call void @use(i32 %lv1)