1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt < %s -dse -S | FileCheck %s
3
4@BUFFER = external dso_local local_unnamed_addr global [0 x i8], align 1
5
6define void @MissedDSEOpportunity(i64 %idx, i1* noalias %cc) {
7;
8; The DSE pass will try to kill the store in the loop exit block using the
9; store in the function exit block. The loop invariant check on the pointer
10; used by the stores should trivially return true because a pointer defined
11; in the entry block of a function is loop invariant by definition. In fact
12; the entry block of a function cannot have predecessors or be part of a loop.
13;
14; CHECK-LABEL: @MissedDSEOpportunity(
15; CHECK-NEXT:  entry:
16; CHECK-NEXT:    [[GEP:%.*]] = getelementptr inbounds [0 x i8], [0 x i8]* @BUFFER, i64 0, i64 [[IDX:%.*]]
17; CHECK-NEXT:    [[BC:%.*]] = bitcast i8* [[GEP]] to i64*
18; CHECK-NEXT:    [[CC0:%.*]] = load volatile i1, i1* [[CC:%.*]], align 1
19; CHECK-NEXT:    br i1 [[CC0]], label [[HEAD:%.*]], label [[EXIT:%.*]]
20; CHECK:       head:
21; CHECK-NEXT:    [[CC1:%.*]] = load volatile i1, i1* [[CC]], align 1
22; CHECK-NEXT:    br i1 [[CC1]], label [[HEAD]], label [[EXIT_LOOPEXIT:%.*]]
23; CHECK:       exit.loopexit:
24; CHECK-NEXT:    br label [[EXIT]]
25; CHECK:       exit:
26; CHECK-NEXT:    store i64 0, i64* [[BC]], align 4
27; CHECK-NEXT:    ret void
28;
29entry:
30  ; The entry block cannot have predecessors or be part of a loop
31  %gep = getelementptr inbounds [0 x i8], [0 x i8]* @BUFFER, i64 0, i64 %idx
32  %bc = bitcast i8* %gep to i64*
33  %cc0 = load volatile i1, i1* %cc, align 1
34  br i1 %cc0, label %head, label %exit
35
36head:                                             ; preds = %entry, %head
37  %cc1 = load volatile i1, i1* %cc, align 1
38  br i1 %cc1, label %head, label %exit.loopexit
39
40exit.loopexit:                                    ; preds = %head
41  ; Dead store
42  store i64 2, i64* %bc, align 4
43  br label %exit
44
45exit:                                             ; preds = %exit.loopexit, %entry
46  ; Killer store
47  store i64 0, i64* %bc, align 4
48  ret void
49}