loadpre-context.ll
4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -gvn --basic-aa -S | FileCheck %s
; load may be speculated, adress is not null using context search.
; There is a critical edge.
define i32 @loadpre_critical_edge(i32* align 8 dereferenceable_or_null(48) %arg, i32 %N) {
; CHECK-LABEL: @loadpre_critical_edge(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32* [[ARG:%.*]], null
; CHECK-NEXT: br i1 [[CMP]], label [[NULL_EXIT:%.*]], label [[HEADER:%.*]]
; CHECK: header:
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[HEADER]] ]
; CHECK-NEXT: [[NEW_V:%.*]] = call i32 @foo(i32 [[IV]])
; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[ARG]], align 4
; CHECK-NEXT: [[SUM:%.*]] = add i32 [[NEW_V]], [[V]]
; CHECK-NEXT: store i32 [[SUM]], i32* [[ARG]], align 4
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N:%.*]]
; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[HEADER]]
; CHECK: exit:
; CHECK-NEXT: ret i32 [[SUM]]
; CHECK: null_exit:
; CHECK-NEXT: ret i32 0
;
entry:
%cmp = icmp eq i32* %arg, null
br i1 %cmp, label %null_exit, label %header
header:
%iv = phi i32 [0, %entry], [%iv.next, %header]
%new_v = call i32 @foo(i32 %iv)
%v = load i32, i32* %arg
%sum = add i32 %new_v, %v
store i32 %sum, i32* %arg
%iv.next = add i32 %iv, 1
%cond = icmp eq i32 %iv.next, %N
br i1 %cond, label %exit, label %header
exit:
ret i32 %sum
null_exit:
ret i32 0
}
; load may be speculated, adress is not null using context search.
define i32 @loadpre_basic(i32* align 8 dereferenceable_or_null(48) %arg, i32 %N) {
; CHECK-LABEL: @loadpre_basic(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32* [[ARG:%.*]], null
; CHECK-NEXT: br i1 [[CMP]], label [[NULL_EXIT:%.*]], label [[PREHEADER:%.*]]
; CHECK: preheader:
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[PREHEADER]] ], [ [[IV_NEXT:%.*]], [[HEADER]] ]
; CHECK-NEXT: [[NEW_V:%.*]] = call i32 @foo(i32 [[IV]])
; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[ARG]], align 4
; CHECK-NEXT: [[SUM:%.*]] = add i32 [[NEW_V]], [[V]]
; CHECK-NEXT: store i32 [[SUM]], i32* [[ARG]], align 4
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N:%.*]]
; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[HEADER]]
; CHECK: exit:
; CHECK-NEXT: ret i32 [[SUM]]
; CHECK: null_exit:
; CHECK-NEXT: ret i32 0
;
entry:
%cmp = icmp eq i32* %arg, null
br i1 %cmp, label %null_exit, label %preheader
preheader:
br label %header
header:
%iv = phi i32 [0, %preheader], [%iv.next, %header]
%new_v = call i32 @foo(i32 %iv)
%v = load i32, i32* %arg
%sum = add i32 %new_v, %v
store i32 %sum, i32* %arg
%iv.next = add i32 %iv, 1
%cond = icmp eq i32 %iv.next, %N
br i1 %cond, label %exit, label %header
exit:
ret i32 %sum
null_exit:
ret i32 0
}
; load cannot be speculated, adress is not null check does not dominate the loop.
define i32 @loadpre_maybe_null(i32* align 8 dereferenceable_or_null(48) %arg, i32 %N, i1 %c) {
; CHECK-LABEL: @loadpre_maybe_null(
; CHECK-NEXT: entry:
; CHECK-NEXT: br i1 [[C:%.*]], label [[NULL_CHECK:%.*]], label [[PREHEADER:%.*]]
; CHECK: null_check:
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32* [[ARG:%.*]], null
; CHECK-NEXT: br i1 [[CMP]], label [[NULL_EXIT:%.*]], label [[PREHEADER]]
; CHECK: preheader:
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[PREHEADER]] ], [ [[IV_NEXT:%.*]], [[HEADER]] ]
; CHECK-NEXT: [[NEW_V:%.*]] = call i32 @foo(i32 [[IV]])
; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[ARG]], align 4
; CHECK-NEXT: [[SUM:%.*]] = add i32 [[NEW_V]], [[V]]
; CHECK-NEXT: store i32 [[SUM]], i32* [[ARG]], align 4
; CHECK-NEXT: [[IV_NEXT]] = add i32 [[IV]], 1
; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N:%.*]]
; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[HEADER]]
; CHECK: exit:
; CHECK-NEXT: ret i32 [[SUM]]
; CHECK: null_exit:
; CHECK-NEXT: ret i32 0
;
entry:
br i1 %c, label %null_check, label %preheader
null_check:
%cmp = icmp eq i32* %arg, null
br i1 %cmp, label %null_exit, label %preheader
preheader:
br label %header
header:
%iv = phi i32 [0, %preheader], [%iv.next, %header]
%new_v = call i32 @foo(i32 %iv)
%v = load i32, i32* %arg
%sum = add i32 %new_v, %v
store i32 %sum, i32* %arg
%iv.next = add i32 %iv, 1
%cond = icmp eq i32 %iv.next, %N
br i1 %cond, label %exit, label %header
exit:
ret i32 %sum
null_exit:
ret i32 0
}
; Does not guarantee that returns.
declare i32 @foo(i32) readnone