1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=dse -S | FileCheck %s
4 @BUFFER = external dso_local local_unnamed_addr global [0 x i8], align 1
6 define void @MissedDSEOpportunity(i64 %idx, ptr noalias %cc) {
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.
14 ; CHECK-LABEL: @MissedDSEOpportunity(
16 ; CHECK-NEXT: [[GEP:%.*]] = getelementptr inbounds [0 x i8], ptr @BUFFER, i64 0, i64 [[IDX:%.*]]
17 ; CHECK-NEXT: [[CC0:%.*]] = load volatile i1, ptr [[CC:%.*]], align 1
18 ; CHECK-NEXT: br i1 [[CC0]], label [[HEAD:%.*]], label [[EXIT:%.*]]
20 ; CHECK-NEXT: [[CC1:%.*]] = load volatile i1, ptr [[CC]], align 1
21 ; CHECK-NEXT: br i1 [[CC1]], label [[HEAD]], label [[EXIT_LOOPEXIT:%.*]]
22 ; CHECK: exit.loopexit:
23 ; CHECK-NEXT: br label [[EXIT]]
25 ; CHECK-NEXT: store i64 0, ptr [[GEP]], align 4
26 ; CHECK-NEXT: ret void
29 ; The entry block cannot have predecessors or be part of a loop
30 %gep = getelementptr inbounds [0 x i8], ptr @BUFFER, i64 0, i64 %idx
31 %cc0 = load volatile i1, ptr %cc, align 1
32 br i1 %cc0, label %head, label %exit
34 head: ; preds = %entry, %head
35 %cc1 = load volatile i1, ptr %cc, align 1
36 br i1 %cc1, label %head, label %exit.loopexit
38 exit.loopexit: ; preds = %head
40 store i64 2, ptr %gep, align 4
43 exit: ; preds = %exit.loopexit, %entry
45 store i64 0, ptr %gep, align 4