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
145
146
147
148
149
150
151
|
From 3d20b13bc2e5af8d52e221a33881423e38c3dfdd Mon Sep 17 00:00:00 2001
From: dingguangya <dingguangya1@huawei.com>
Date: Thu, 17 Feb 2022 21:53:31 +0800
Subject: [PATCH 28/28] [AutoPrefetch] Handle the case that the basic block
branch probability is invalid
When the node branch probability value is not initialized,
the branch probability must be set to 0 to ensure that
the calculation of the basic block execution probability
must be less than or equal to 100%.
---
.../gcc.dg/autoprefetch/autoprefetch.exp | 27 +++++++++++++++++++
.../autoprefetch/branch-weighted-prefetch.c | 22 +++++++++++++++
.../autoprefetch/get-edge-prob-non-init.c | 24 +++++++++++++++++
gcc/tree-ssa-loop-prefetch.c | 17 +++++++++++-
4 files changed, 89 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/autoprefetch/autoprefetch.exp
create mode 100644 gcc/testsuite/gcc.dg/autoprefetch/branch-weighted-prefetch.c
create mode 100644 gcc/testsuite/gcc.dg/autoprefetch/get-edge-prob-non-init.c
diff --git a/gcc/testsuite/gcc.dg/autoprefetch/autoprefetch.exp b/gcc/testsuite/gcc.dg/autoprefetch/autoprefetch.exp
new file mode 100644
index 000000000..a7408e338
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/autoprefetch/autoprefetch.exp
@@ -0,0 +1,27 @@
+# Copyright (C) 1997-2022 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+load_lib gcc-dg.exp
+load_lib target-supports.exp
+
+# Initialize `dg'.
+dg-init
+
+gcc-dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/*.c]] \
+ "" "-fprefetch-loop-arrays"
+
+# All done.
+dg-finish
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.dg/autoprefetch/branch-weighted-prefetch.c b/gcc/testsuite/gcc.dg/autoprefetch/branch-weighted-prefetch.c
new file mode 100644
index 000000000..c63c5e5cb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/autoprefetch/branch-weighted-prefetch.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fprefetch-loop-arrays=2 --param min-insn-to-prefetch-ratio=5 --param simultaneous-prefetches=100 -fdump-tree-aprefetch-details -fdump-tree-optimized" } */
+#define N 10000000
+
+long long a[N];
+
+long long func ()
+{
+ long long i;
+ long long sum = 0;
+
+ for (i = 0; i < N; i+=1) {
+ if (i < 100000)
+ sum += a[i];
+ else
+ continue;
+ }
+
+ return sum;
+}
+/* { dg-final { scan-tree-dump-times "Ahead 40" 1 "aprefetch" } } */
+/* { dg-final { scan-tree-dump-times "builtin_prefetch" 1 "optimized" } } */
\ No newline at end of file
diff --git a/gcc/testsuite/gcc.dg/autoprefetch/get-edge-prob-non-init.c b/gcc/testsuite/gcc.dg/autoprefetch/get-edge-prob-non-init.c
new file mode 100644
index 000000000..f55481008
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/autoprefetch/get-edge-prob-non-init.c
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-Ofast -fprefetch-loop-arrays=2 -fdump-tree-aprefetch-details" } */
+
+int a, c, f;
+static int *b = &a;
+int *d;
+int e[0];
+void g() {
+ int h;
+ for (;;) {
+ h = 1;
+ for (; h >= 0; h--) {
+ c = 2;
+ for (; c; c--)
+ if (e[0])
+ if (e[c])
+ *b = 0;
+ f || (*d = 0);
+ }
+ }
+}
+int main() {}
+
+/* { dg-final } */
diff --git a/gcc/tree-ssa-loop-prefetch.c b/gcc/tree-ssa-loop-prefetch.c
index 3a5aef0fc..673f453a4 100644
--- a/gcc/tree-ssa-loop-prefetch.c
+++ b/gcc/tree-ssa-loop-prefetch.c
@@ -2132,7 +2132,7 @@ get_edge_prob (edge e)
{
/* Limit the minimum probability value. */
const float MINNUM_PROB = 0.00001f;
- float fvalue = 1;
+ float fvalue = 0;
profile_probability probability = e->probability;
if (probability.initialized_p ())
@@ -2143,6 +2143,21 @@ get_edge_prob (edge e)
fvalue = MINNUM_PROB;
}
}
+ else
+ {
+ /* When the node branch probability value is not initialized, the branch
+ probability must be set to 0 to ensure that the calculation of the
+ basic block execution probability must be less than or equal to 100%.
+ i.e,
+ ...
+ <bb 3> [local count: 20000]
+ if (f_2 != 0)
+ goto <bb 6>; [INV]
+ else
+ goto <bb 7>; [100.00%]
+ ... */
+ fvalue = 0;
+ }
return fvalue;
}
--
2.27.0.windows.1
|