1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -dse -S %s | FileCheck %s
3
4declare void @use(i32)
5
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.
10define 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
17;
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)
26  ret i32 0
27}
28
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.
32;
33; Test case from PR48279. FIXME.
34define 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:%.*]]
38; CHECK:       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:%.*]]
42; CHECK:       for.inc:
43; CHECK-NEXT:    br i1 [[C:%.*]], label [[FOR_BODY_1:%.*]], label [[FOR_END:%.*]]
44; CHECK:       for.body.1:
45; CHECK-NEXT:    ret i32 1
46; CHECK:       for.end:
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
51;
52  %d = alloca [1 x i32], align 4
53  br label %for.body
54
55for.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
58  br label %for.inc
59
60for.inc:                                          ; preds = %for.body
61  br i1 %c, label %for.body.1, label %for.end
62
63for.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
66  ret i32 1
67
68for.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)
72  ret i32 0
73}
74