summaryrefslogtreecommitdiff
path: root/0298-Mark-prefetch-builtin-as-willreturn.patch
blob: 7a489a5d9b0d7e1c7454a66a02ef59ac805532a6 (plain)
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
From a252bbd11d22481a1e719ed36d800e2192abb369 Mon Sep 17 00:00:00 2001
From: Pronin Alexander <pronin.alexander@huawei.com>
Date: Thu, 31 Oct 2024 15:49:27 +0800
Subject: [PATCH 1/6] Mark prefetch builtin as willreturn

Signed-off-by: Pronin Alexander <pronin.alexander@huawei.com>
---
 gcc/common.opt      |  4 ++++
 gcc/gimple.cc       | 30 ++++++++++++++++++++++++++++++
 gcc/gimple.h        |  1 +
 gcc/tree-ssa-pre.cc |  4 +---
 4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/gcc/common.opt b/gcc/common.opt
index 688d65e4d..be5fcc681 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1313,6 +1313,10 @@ fdelete-null-pointer-checks
 Common Var(flag_delete_null_pointer_checks) Init(-1) Optimization
 Delete useless null pointer checks.
 
+fbuiltin-will-return
+Common Var(flag_builtin_will_return) Optimization
+Consider some of the builtins as definitely returning.
+
 fdevirtualize-at-ltrans
 Common Var(flag_ltrans_devirtualize)
 Stream extra data to support more aggressive devirtualization in LTO local transformation mode.
diff --git a/gcc/gimple.cc b/gcc/gimple.cc
index 9e62da426..04ca9f161 100644
--- a/gcc/gimple.cc
+++ b/gcc/gimple.cc
@@ -2998,6 +2998,36 @@ nonbarrier_call_p (gimple *call)
   return false;
 }
 
+static inline bool
+will_return_builtin_p (gimple *call)
+{
+  if (!flag_builtin_will_return)
+    return false;
+
+  if (!gimple_call_builtin_p (call, BUILT_IN_NORMAL))
+    return false;
+
+  switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call)))
+    {
+    case BUILT_IN_PREFETCH:
+      return true;
+    default:
+      return false;
+    }
+}
+
+bool
+will_return_call_p (gimple *call, function *fun)
+{
+  int flags = gimple_call_flags (call);
+  if (!(flags & (ECF_CONST|ECF_PURE))
+      || (flags & ECF_LOOPING_CONST_OR_PURE)
+      || stmt_can_throw_external (fun, call))
+    return will_return_builtin_p (call);
+
+  return true;
+}
+
 /* Callback for walk_stmt_load_store_ops.
  
    Return TRUE if OP will dereference the tree stored in DATA, FALSE
diff --git a/gcc/gimple.h b/gcc/gimple.h
index 77a5a07e9..bb05a7664 100644
--- a/gcc/gimple.h
+++ b/gcc/gimple.h
@@ -1628,6 +1628,7 @@ extern bool gimple_asm_clobbers_memory_p (const gasm *);
 extern void dump_decl_set (FILE *, bitmap);
 extern bool nonfreeing_call_p (gimple *);
 extern bool nonbarrier_call_p (gimple *);
+extern bool will_return_call_p (gimple *, function *);
 extern bool infer_nonnull_range (gimple *, tree);
 extern bool infer_nonnull_range_by_dereference (gimple *, tree);
 extern bool infer_nonnull_range_by_attribute (gimple *, tree);
diff --git a/gcc/tree-ssa-pre.cc b/gcc/tree-ssa-pre.cc
index 98134b5d3..b5264133a 100644
--- a/gcc/tree-ssa-pre.cc
+++ b/gcc/tree-ssa-pre.cc
@@ -3988,9 +3988,7 @@ compute_avail (function *fun)
 		 that forbids hoisting possibly trapping expressions
 		 before it.  */
 	      int flags = gimple_call_flags (stmt);
-	      if (!(flags & (ECF_CONST|ECF_PURE))
-		  || (flags & ECF_LOOPING_CONST_OR_PURE)
-		  || stmt_can_throw_external (fun, stmt))
+	      if (!will_return_call_p (stmt, fun))
 		/* Defer setting of BB_MAY_NOTRETURN to avoid it
 		   influencing the processing of the call itself.  */
 		set_bb_may_notreturn = true;
-- 
2.33.0