-
Notifications
You must be signed in to change notification settings - Fork 3
/
x86-always-generate-branch-hint.patch
81 lines (74 loc) · 2.39 KB
/
x86-always-generate-branch-hint.patch
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
From ecb8284b8bec4f9e025d21177efbe13f64f6f11b Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <[email protected]>
Date: Tue, 26 Apr 2022 11:08:55 -0700
Subject: [PATCH] x86: Always generate branch hint
For -mtune-ctrl=branch_prediction_hints, always generate branch hint for
conditional branches.
gcc/
* config/i386/i386.cc (ix86_print_operand): Always generate
branch hint for conditional branches.
gcc/testsuite/
* gcc.target/i386/branch-hint-1.c: New test.
---
gcc/config/i386/i386.cc | 26 +++++--------------
gcc/testsuite/gcc.target/i386/branch-hint-1.c | 16 ++++++++++++
2 files changed, 23 insertions(+), 19 deletions(-)
create mode 100644 gcc/testsuite/gcc.target/i386/branch-hint-1.c
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 52040da8c47f..8246576f7b82 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -13555,25 +13555,13 @@ ix86_print_operand (FILE *file, rtx x, int code)
int pred_val = profile_probability::from_reg_br_prob_note
(XINT (x, 0)).to_reg_br_prob_base ();
- if (pred_val < REG_BR_PROB_BASE * 45 / 100
- || pred_val > REG_BR_PROB_BASE * 55 / 100)
- {
- bool taken = pred_val > REG_BR_PROB_BASE / 2;
- bool cputaken
- = final_forward_branch_p (current_output_insn) == 0;
-
- /* Emit hints only in the case default branch prediction
- heuristics would fail. */
- if (taken != cputaken)
- {
- /* We use 3e (DS) prefix for taken branches and
- 2e (CS) prefix for not taken branches. */
- if (taken)
- fputs ("ds ; ", file);
- else
- fputs ("cs ; ", file);
- }
- }
+ bool taken = pred_val > REG_BR_PROB_BASE / 2;
+ /* We use 3e (DS) prefix for taken branches and
+ 2e (CS) prefix for not taken branches. */
+ if (taken)
+ fputs ("ds ; ", file);
+ else
+ fputs ("cs ; ", file);
}
return;
}
diff --git a/gcc/testsuite/gcc.target/i386/branch-hint-1.c b/gcc/testsuite/gcc.target/i386/branch-hint-1.c
new file mode 100644
index 000000000000..03dd83b05af0
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/branch-hint-1.c
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -dp -mtune-ctrl=branch_prediction_hints" } */
+
+int
+main (int argc, char** argv)
+{
+ if (argc == 1)
+ return 1;
+
+ if (argc == 2)
+ return 2;
+
+ return 3;
+}
+
+/* { dg-final { scan-assembler-not "\tj\[a-z\]\+\[ \\t\]+.* \\*jcc" } } */