annotate gcc/tree-call-cdce.c @ 136:4627f235cf2a

fix c-next example
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:11:56 +0900
parents 84e7813d76e9
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 /* Conditional Dead Call Elimination pass for the GNU compiler.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 2008-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 Contributed by Xinliang David Li <davidxl@google.com>
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 This file is part of GCC.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
6
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 Free Software Foundation; either version 3, or (at your option) any
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 later version.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
11
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 for more details.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
16
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 #include "coretypes.h"
111
kono
parents: 67
diff changeset
24 #include "backend.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "tree.h"
111
kono
parents: 67
diff changeset
26 #include "gimple.h"
kono
parents: 67
diff changeset
27 #include "cfghooks.h"
kono
parents: 67
diff changeset
28 #include "tree-pass.h"
kono
parents: 67
diff changeset
29 #include "ssa.h"
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
30 #include "gimple-pretty-print.h"
111
kono
parents: 67
diff changeset
31 #include "fold-const.h"
kono
parents: 67
diff changeset
32 #include "stor-layout.h"
kono
parents: 67
diff changeset
33 #include "gimple-iterator.h"
kono
parents: 67
diff changeset
34 #include "tree-cfg.h"
kono
parents: 67
diff changeset
35 #include "tree-into-ssa.h"
kono
parents: 67
diff changeset
36 #include "builtins.h"
kono
parents: 67
diff changeset
37 #include "internal-fn.h"
kono
parents: 67
diff changeset
38 #include "tree-dfa.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40
111
kono
parents: 67
diff changeset
41 /* This pass serves two closely-related purposes:
kono
parents: 67
diff changeset
42
kono
parents: 67
diff changeset
43 1. It conditionally executes calls that set errno if (a) the result of
kono
parents: 67
diff changeset
44 the call is unused and (b) a simple range check on the arguments can
kono
parents: 67
diff changeset
45 detect most cases where errno does not need to be set.
kono
parents: 67
diff changeset
46
kono
parents: 67
diff changeset
47 This is the "conditional dead-code elimination" that gave the pass
kono
parents: 67
diff changeset
48 its original name, since the call is dead for most argument values.
kono
parents: 67
diff changeset
49 The calls for which it helps are usually part of the C++ abstraction
kono
parents: 67
diff changeset
50 penalty exposed after inlining.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
111
kono
parents: 67
diff changeset
52 2. It looks for calls to built-in functions that set errno and whose
kono
parents: 67
diff changeset
53 result is used. It checks whether there is an associated internal
kono
parents: 67
diff changeset
54 function that doesn't set errno and whether the target supports
kono
parents: 67
diff changeset
55 that internal function. If so, the pass uses the internal function
kono
parents: 67
diff changeset
56 to compute the result of the built-in function but still arranges
kono
parents: 67
diff changeset
57 for errno to be set when necessary. There are two ways of setting
kono
parents: 67
diff changeset
58 errno:
kono
parents: 67
diff changeset
59
kono
parents: 67
diff changeset
60 a. by protecting the original call with the same argument checks as (1)
kono
parents: 67
diff changeset
61
kono
parents: 67
diff changeset
62 b. by protecting the original call with a check that the result
kono
parents: 67
diff changeset
63 of the internal function is not equal to itself (i.e. is NaN).
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
64
111
kono
parents: 67
diff changeset
65 (b) requires that NaNs are the only erroneous results. It is not
kono
parents: 67
diff changeset
66 appropriate for functions like log, which returns ERANGE for zero
kono
parents: 67
diff changeset
67 arguments. (b) is also likely to perform worse than (a) because it
kono
parents: 67
diff changeset
68 requires the result to be calculated first. The pass therefore uses
kono
parents: 67
diff changeset
69 (a) when it can and uses (b) as a fallback.
kono
parents: 67
diff changeset
70
kono
parents: 67
diff changeset
71 For (b) the pass can replace the original call with a call to
kono
parents: 67
diff changeset
72 IFN_SET_EDOM, if the target supports direct assignments to errno.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
73
111
kono
parents: 67
diff changeset
74 In both cases, arguments that require errno to be set should occur
kono
parents: 67
diff changeset
75 rarely in practice. Checks of the errno result should also be rare,
kono
parents: 67
diff changeset
76 but the compiler would need powerful interprocedural analysis to
kono
parents: 67
diff changeset
77 prove that errno is not checked. It's much easier to add argument
kono
parents: 67
diff changeset
78 checks or result checks instead.
kono
parents: 67
diff changeset
79
kono
parents: 67
diff changeset
80 An example of (1) is:
kono
parents: 67
diff changeset
81
kono
parents: 67
diff changeset
82 log (x); // Mostly dead call
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
83 ==>
111
kono
parents: 67
diff changeset
84 if (__builtin_islessequal (x, 0))
kono
parents: 67
diff changeset
85 log (x);
kono
parents: 67
diff changeset
86
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
87 With this change, call to log (x) is effectively eliminated, as
111
kono
parents: 67
diff changeset
88 in the majority of the cases, log won't be called with x out of
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
89 range. The branch is totally predictable, so the branch cost
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
90 is low.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
91
111
kono
parents: 67
diff changeset
92 An example of (2) is:
kono
parents: 67
diff changeset
93
kono
parents: 67
diff changeset
94 y = sqrt (x);
kono
parents: 67
diff changeset
95 ==>
kono
parents: 67
diff changeset
96 y = IFN_SQRT (x);
kono
parents: 67
diff changeset
97 if (__builtin_isless (x, 0))
kono
parents: 67
diff changeset
98 sqrt (x);
kono
parents: 67
diff changeset
99
kono
parents: 67
diff changeset
100 In the vast majority of cases we should then never need to call sqrt.
kono
parents: 67
diff changeset
101
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
102 Note that library functions are not supposed to clear errno to zero without
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103 error. See IEEE Std 1003.1, section 2.3 Error Numbers, and section 7.5:3 of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
104 ISO/IEC 9899 (C99).
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
105
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
106 The condition wrapping the builtin call is conservatively set to avoid too
111
kono
parents: 67
diff changeset
107 aggressive (wrong) shrink wrapping. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
108
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
109
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
110 /* A structure for representing input domain of
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
111 a function argument in integer. If the lower
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
112 bound is -inf, has_lb is set to false. If the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
113 upper bound is +inf, has_ub is false.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
114 is_lb_inclusive and is_ub_inclusive are flags
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
115 to indicate if lb and ub value are inclusive
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
116 respectively. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
117
111
kono
parents: 67
diff changeset
118 struct inp_domain
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120 int lb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 int ub;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
122 bool has_lb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
123 bool has_ub;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124 bool is_lb_inclusive;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
125 bool is_ub_inclusive;
111
kono
parents: 67
diff changeset
126 };
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
127
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
128 /* A helper function to construct and return an input
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
129 domain object. LB is the lower bound, HAS_LB is
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 a boolean flag indicating if the lower bound exists,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
131 and LB_INCLUSIVE is a boolean flag indicating if the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
132 lower bound is inclusive or not. UB, HAS_UB, and
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
133 UB_INCLUSIVE have the same meaning, but for upper
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
134 bound of the domain. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
135
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
136 static inp_domain
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
137 get_domain (int lb, bool has_lb, bool lb_inclusive,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
138 int ub, bool has_ub, bool ub_inclusive)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
139 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140 inp_domain domain;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 domain.lb = lb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 domain.has_lb = has_lb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 domain.is_lb_inclusive = lb_inclusive;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 domain.ub = ub;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 domain.has_ub = has_ub;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 domain.is_ub_inclusive = ub_inclusive;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 return domain;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
150 /* A helper function to check the target format for the
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 argument type. In this implementation, only IEEE formats
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
152 are supported. ARG is the call argument to be checked.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 Returns true if the format is supported. To support other
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 target formats, function get_no_error_domain needs to be
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
155 enhanced to have range bounds properly computed. Since
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
156 the check is cheap (very small number of candidates
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 to be checked), the result is not cached for each float type. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 static bool
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 check_target_format (tree arg)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 tree type;
111
kono
parents: 67
diff changeset
163 machine_mode mode;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 const struct real_format *rfmt;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
165
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 type = TREE_TYPE (arg);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 mode = TYPE_MODE (type);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 rfmt = REAL_MODE_FORMAT (mode);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 if ((mode == SFmode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
170 && (rfmt == &ieee_single_format || rfmt == &mips_single_format
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 || rfmt == &motorola_single_format))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 || (mode == DFmode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 && (rfmt == &ieee_double_format || rfmt == &mips_double_format
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 || rfmt == &motorola_double_format))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 /* For long double, we can not really check XFmode
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
176 which is only defined on intel platforms.
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
177 Candidate pre-selection using builtin function
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
178 code guarantees that we are checking formats
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 for long double modes: double, quad, and extended. */
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
180 || (mode != SFmode && mode != DFmode
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 && (rfmt == &ieee_quad_format
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 || rfmt == &mips_quad_format
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 || rfmt == &ieee_extended_motorola_format
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
184 || rfmt == &ieee_extended_intel_96_format
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
185 || rfmt == &ieee_extended_intel_128_format
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 || rfmt == &ieee_extended_intel_96_round_53_format)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
188
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
189 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
190 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
191
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
192
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
193 /* A helper function to help select calls to pow that are suitable for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
194 conditional DCE transformation. It looks for pow calls that can be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 guided with simple conditions. Such calls either have constant base
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
196 values or base values converted from integers. Returns true if
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 the pow call POW_CALL is a candidate. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199 /* The maximum integer bit size for base argument of a pow call
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 that is suitable for shrink-wrapping transformation. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 #define MAX_BASE_INT_BIT_SIZE 32
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 static bool
111
kono
parents: 67
diff changeset
204 check_pow (gcall *pow_call)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
206 tree base, expn;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
207 enum tree_code bc, ec;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
208
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
209 if (gimple_call_num_args (pow_call) != 2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
210 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
211
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212 base = gimple_call_arg (pow_call, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
213 expn = gimple_call_arg (pow_call, 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
214
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
215 if (!check_target_format (expn))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
216 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
217
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
218 bc = TREE_CODE (base);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
219 ec = TREE_CODE (expn);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
220
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 /* Folding candidates are not interesting.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
222 Can actually assert that it is already folded. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
223 if (ec == REAL_CST && bc == REAL_CST)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
224 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
225
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
226 if (bc == REAL_CST)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
227 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
228 /* Only handle a fixed range of constant. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
229 REAL_VALUE_TYPE mv;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
230 REAL_VALUE_TYPE bcv = TREE_REAL_CST (base);
111
kono
parents: 67
diff changeset
231 if (real_equal (&bcv, &dconst1))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
232 return false;
111
kono
parents: 67
diff changeset
233 if (real_less (&bcv, &dconst1))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
234 return false;
111
kono
parents: 67
diff changeset
235 real_from_integer (&mv, TYPE_MODE (TREE_TYPE (base)), 256, UNSIGNED);
kono
parents: 67
diff changeset
236 if (real_less (&mv, &bcv))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 else if (bc == SSA_NAME)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 {
111
kono
parents: 67
diff changeset
242 tree base_val0, type;
kono
parents: 67
diff changeset
243 gimple *base_def;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 int bit_sz;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
245
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
246 /* Only handles cases where base value is converted
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
247 from integer values. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
248 base_def = SSA_NAME_DEF_STMT (base);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
249 if (gimple_code (base_def) != GIMPLE_ASSIGN)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
250 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
251
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
252 if (gimple_assign_rhs_code (base_def) != FLOAT_EXPR)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 base_val0 = gimple_assign_rhs1 (base_def);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255
111
kono
parents: 67
diff changeset
256 type = TREE_TYPE (base_val0);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257 if (TREE_CODE (type) != INTEGER_TYPE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 bit_sz = TYPE_PRECISION (type);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 /* If the type of the base is too wide,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 the resulting shrink wrapping condition
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 will be too conservative. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
263 if (bit_sz > MAX_BASE_INT_BIT_SIZE)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
267 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
268 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
269 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
270 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
271
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
272 /* A helper function to help select candidate function calls that are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
273 suitable for conditional DCE. Candidate functions must have single
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 valid input domain in this implementation except for pow (see check_pow).
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 Returns true if the function call is a candidate. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 static bool
111
kono
parents: 67
diff changeset
278 check_builtin_call (gcall *bcall)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 tree arg;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 arg = gimple_call_arg (bcall, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 return check_target_format (arg);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285
111
kono
parents: 67
diff changeset
286 /* Return true if built-in function call CALL calls a math function
kono
parents: 67
diff changeset
287 and if we know how to test the range of its arguments to detect _most_
kono
parents: 67
diff changeset
288 situations in which errno is not set. The test must err on the side
kono
parents: 67
diff changeset
289 of treating non-erroneous values as potentially erroneous. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291 static bool
111
kono
parents: 67
diff changeset
292 can_test_argument_range (gcall *call)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 {
111
kono
parents: 67
diff changeset
294 switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 /* Trig functions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 CASE_FLT_FN (BUILT_IN_ACOS):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 CASE_FLT_FN (BUILT_IN_ASIN):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 /* Hyperbolic functions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 CASE_FLT_FN (BUILT_IN_ACOSH):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 CASE_FLT_FN (BUILT_IN_ATANH):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 CASE_FLT_FN (BUILT_IN_COSH):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 CASE_FLT_FN (BUILT_IN_SINH):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 /* Log functions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 CASE_FLT_FN (BUILT_IN_LOG):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 CASE_FLT_FN (BUILT_IN_LOG2):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 CASE_FLT_FN (BUILT_IN_LOG10):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 CASE_FLT_FN (BUILT_IN_LOG1P):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
309 /* Exp functions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
310 CASE_FLT_FN (BUILT_IN_EXP):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
311 CASE_FLT_FN (BUILT_IN_EXP2):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
312 CASE_FLT_FN (BUILT_IN_EXP10):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 CASE_FLT_FN (BUILT_IN_EXPM1):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 CASE_FLT_FN (BUILT_IN_POW10):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 /* Sqrt. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 CASE_FLT_FN (BUILT_IN_SQRT):
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
317 CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT):
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 return check_builtin_call (call);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 /* Special one: two argument pow. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 case BUILT_IN_POW:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 return check_pow (call);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 return false;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328
111
kono
parents: 67
diff changeset
329 /* Return true if CALL can produce a domain error (EDOM) but can never
kono
parents: 67
diff changeset
330 produce a pole, range overflow or range underflow error (all ERANGE).
kono
parents: 67
diff changeset
331 This means that we can tell whether a function would have set errno
kono
parents: 67
diff changeset
332 by testing whether the result is a NaN. */
kono
parents: 67
diff changeset
333
kono
parents: 67
diff changeset
334 static bool
kono
parents: 67
diff changeset
335 edom_only_function (gcall *call)
kono
parents: 67
diff changeset
336 {
kono
parents: 67
diff changeset
337 switch (DECL_FUNCTION_CODE (gimple_call_fndecl (call)))
kono
parents: 67
diff changeset
338 {
kono
parents: 67
diff changeset
339 CASE_FLT_FN (BUILT_IN_ACOS):
kono
parents: 67
diff changeset
340 CASE_FLT_FN (BUILT_IN_ASIN):
kono
parents: 67
diff changeset
341 CASE_FLT_FN (BUILT_IN_ATAN):
kono
parents: 67
diff changeset
342 CASE_FLT_FN (BUILT_IN_COS):
kono
parents: 67
diff changeset
343 CASE_FLT_FN (BUILT_IN_SIGNIFICAND):
kono
parents: 67
diff changeset
344 CASE_FLT_FN (BUILT_IN_SIN):
kono
parents: 67
diff changeset
345 CASE_FLT_FN (BUILT_IN_SQRT):
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
346 CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT):
111
kono
parents: 67
diff changeset
347 CASE_FLT_FN (BUILT_IN_FMOD):
kono
parents: 67
diff changeset
348 CASE_FLT_FN (BUILT_IN_REMAINDER):
kono
parents: 67
diff changeset
349 return true;
kono
parents: 67
diff changeset
350
kono
parents: 67
diff changeset
351 default:
kono
parents: 67
diff changeset
352 return false;
kono
parents: 67
diff changeset
353 }
kono
parents: 67
diff changeset
354 }
kono
parents: 67
diff changeset
355
kono
parents: 67
diff changeset
356 /* Return true if it is structurally possible to guard CALL. */
kono
parents: 67
diff changeset
357
kono
parents: 67
diff changeset
358 static bool
kono
parents: 67
diff changeset
359 can_guard_call_p (gimple *call)
kono
parents: 67
diff changeset
360 {
kono
parents: 67
diff changeset
361 return (!stmt_ends_bb_p (call)
kono
parents: 67
diff changeset
362 || find_fallthru_edge (gimple_bb (call)->succs));
kono
parents: 67
diff changeset
363 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364
111
kono
parents: 67
diff changeset
365 /* A helper function to generate gimple statements for one bound
kono
parents: 67
diff changeset
366 comparison, so that the built-in function is called whenever
kono
parents: 67
diff changeset
367 TCODE <ARG, LBUB> is *false*. TEMP_NAME1/TEMP_NAME2 are names
kono
parents: 67
diff changeset
368 of the temporaries, CONDS is a vector holding the produced GIMPLE
kono
parents: 67
diff changeset
369 statements, and NCONDS points to the variable holding the number of
kono
parents: 67
diff changeset
370 logical comparisons. CONDS is either empty or a list ended with a
kono
parents: 67
diff changeset
371 null tree. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
372
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
373 static void
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
374 gen_one_condition (tree arg, int lbub,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 enum tree_code tcode,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 const char *temp_name1,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 const char *temp_name2,
111
kono
parents: 67
diff changeset
378 vec<gimple *> conds,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 unsigned *nconds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
380 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
381 tree lbub_real_cst, lbub_cst, float_type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 tree temp, tempn, tempc, tempcn;
111
kono
parents: 67
diff changeset
383 gassign *stmt1;
kono
parents: 67
diff changeset
384 gassign *stmt2;
kono
parents: 67
diff changeset
385 gcond *stmt3;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
386
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
387 float_type = TREE_TYPE (arg);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
388 lbub_cst = build_int_cst (integer_type_node, lbub);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389 lbub_real_cst = build_real_from_int_cst (float_type, lbub_cst);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 temp = create_tmp_var (float_type, temp_name1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 stmt1 = gimple_build_assign (temp, arg);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
393 tempn = make_ssa_name (temp, stmt1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394 gimple_assign_set_lhs (stmt1, tempn);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 tempc = create_tmp_var (boolean_type_node, temp_name2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
397 stmt2 = gimple_build_assign (tempc,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 fold_build2 (tcode,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 boolean_type_node,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400 tempn, lbub_real_cst));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 tempcn = make_ssa_name (tempc, stmt2);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
402 gimple_assign_set_lhs (stmt2, tempcn);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
403
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
404 stmt3 = gimple_build_cond_from_tree (tempcn, NULL_TREE, NULL_TREE);
111
kono
parents: 67
diff changeset
405 conds.quick_push (stmt1);
kono
parents: 67
diff changeset
406 conds.quick_push (stmt2);
kono
parents: 67
diff changeset
407 conds.quick_push (stmt3);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
408 (*nconds)++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
409 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
410
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
411 /* A helper function to generate GIMPLE statements for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
412 out of input domain check. ARG is the call argument
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
413 to be runtime checked, DOMAIN holds the valid domain
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
414 for the given function, CONDS points to the vector
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
415 holding the result GIMPLE statements. *NCONDS is
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
416 the number of logical comparisons. This function
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
417 produces no more than two logical comparisons, one
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
418 for lower bound check, one for upper bound check. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
419
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
420 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
421 gen_conditions_for_domain (tree arg, inp_domain domain,
111
kono
parents: 67
diff changeset
422 vec<gimple *> conds,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
423 unsigned *nconds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
424 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
425 if (domain.has_lb)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
426 gen_one_condition (arg, domain.lb,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
427 (domain.is_lb_inclusive
111
kono
parents: 67
diff changeset
428 ? UNGE_EXPR : UNGT_EXPR),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
429 "DCE_COND_LB", "DCE_COND_LB_TEST",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
430 conds, nconds);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
431
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
432 if (domain.has_ub)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
434 /* Now push a separator. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
435 if (domain.has_lb)
111
kono
parents: 67
diff changeset
436 conds.quick_push (NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
437
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
438 gen_one_condition (arg, domain.ub,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
439 (domain.is_ub_inclusive
111
kono
parents: 67
diff changeset
440 ? UNLE_EXPR : UNLT_EXPR),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
441 "DCE_COND_UB", "DCE_COND_UB_TEST",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 conds, nconds);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
443 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
444 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
445
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
446
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
447 /* A helper function to generate condition
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
448 code for the y argument in call pow (some_const, y).
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
449 See candidate selection in check_pow. Since the
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 candidates' base values have a limited range,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
451 the guarded code generated for y are simple:
111
kono
parents: 67
diff changeset
452 if (__builtin_isgreater (y, max_y))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
453 pow (const, y);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
454 Note max_y can be computed separately for each
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 const base, but in this implementation, we
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
456 choose to compute it using the max base
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
457 in the allowed range for the purpose of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
458 simplicity. BASE is the constant base value,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
459 EXPN is the expression for the exponent argument,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
460 *CONDS is the vector to hold resulting statements,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
461 and *NCONDS is the number of logical conditions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
462
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
463 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
464 gen_conditions_for_pow_cst_base (tree base, tree expn,
111
kono
parents: 67
diff changeset
465 vec<gimple *> conds,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
466 unsigned *nconds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
467 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
468 inp_domain exp_domain;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
469 /* Validate the range of the base constant to make
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
470 sure it is consistent with check_pow. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
471 REAL_VALUE_TYPE mv;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
472 REAL_VALUE_TYPE bcv = TREE_REAL_CST (base);
111
kono
parents: 67
diff changeset
473 gcc_assert (!real_equal (&bcv, &dconst1)
kono
parents: 67
diff changeset
474 && !real_less (&bcv, &dconst1));
kono
parents: 67
diff changeset
475 real_from_integer (&mv, TYPE_MODE (TREE_TYPE (base)), 256, UNSIGNED);
kono
parents: 67
diff changeset
476 gcc_assert (!real_less (&mv, &bcv));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
477
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 exp_domain = get_domain (0, false, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 127, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
480
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
481 gen_conditions_for_domain (expn, exp_domain,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
482 conds, nconds);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
483 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
484
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
485 /* Generate error condition code for pow calls with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
486 non constant base values. The candidates selected
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
487 have their base argument value converted from
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 integer (see check_pow) value (1, 2, 4 bytes), and
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
489 the max exp value is computed based on the size
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
490 of the integer type (i.e. max possible base value).
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 The resulting input domain for exp argument is thus
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
492 conservative (smaller than the max value allowed by
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
493 the runtime value of the base). BASE is the integer
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
494 base value, EXPN is the expression for the exponent
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
495 argument, *CONDS is the vector to hold resulting
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
496 statements, and *NCONDS is the number of logical
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
497 conditions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
498
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
499 static void
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 gen_conditions_for_pow_int_base (tree base, tree expn,
111
kono
parents: 67
diff changeset
501 vec<gimple *> conds,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 unsigned *nconds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 {
111
kono
parents: 67
diff changeset
504 gimple *base_def;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
505 tree base_val0;
111
kono
parents: 67
diff changeset
506 tree int_type;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 tree temp, tempn;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 tree cst0;
111
kono
parents: 67
diff changeset
509 gimple *stmt1, *stmt2;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 int bit_sz, max_exp;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 inp_domain exp_domain;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 base_def = SSA_NAME_DEF_STMT (base);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 base_val0 = gimple_assign_rhs1 (base_def);
111
kono
parents: 67
diff changeset
515 int_type = TREE_TYPE (base_val0);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
516 bit_sz = TYPE_PRECISION (int_type);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
517 gcc_assert (bit_sz > 0
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 && bit_sz <= MAX_BASE_INT_BIT_SIZE);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
520 /* Determine the max exp argument value according to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
521 the size of the base integer. The max exp value
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
522 is conservatively estimated assuming IEEE754 double
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 precision format. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 if (bit_sz == 8)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 max_exp = 128;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 else if (bit_sz == 16)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 max_exp = 64;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 else
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
529 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
530 gcc_assert (bit_sz == MAX_BASE_INT_BIT_SIZE);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
531 max_exp = 32;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
532 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
533
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 /* For pow ((double)x, y), generate the following conditions:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 cond 1:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
536 temp1 = x;
111
kono
parents: 67
diff changeset
537 if (__builtin_islessequal (temp1, 0))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
538
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
539 cond 2:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 temp2 = y;
111
kono
parents: 67
diff changeset
541 if (__builtin_isgreater (temp2, max_exp_real_cst)) */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 /* Generate condition in reverse order -- first
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 the condition for the exp argument. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 exp_domain = get_domain (0, false, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 max_exp, true, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 gen_conditions_for_domain (expn, exp_domain,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 conds, nconds);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 /* Now generate condition for the base argument.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 Note it does not use the helper function
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 gen_conditions_for_domain because the base
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
555 type is integer. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 /* Push a separator. */
111
kono
parents: 67
diff changeset
558 conds.quick_push (NULL);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
559
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 temp = create_tmp_var (int_type, "DCE_COND1");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
561 cst0 = build_int_cst (int_type, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 stmt1 = gimple_build_assign (temp, base_val0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
563 tempn = make_ssa_name (temp, stmt1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
564 gimple_assign_set_lhs (stmt1, tempn);
111
kono
parents: 67
diff changeset
565 stmt2 = gimple_build_cond (GT_EXPR, tempn, cst0, NULL_TREE, NULL_TREE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
566
111
kono
parents: 67
diff changeset
567 conds.quick_push (stmt1);
kono
parents: 67
diff changeset
568 conds.quick_push (stmt2);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 (*nconds)++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 /* Method to generate conditional statements for guarding conditionally
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 dead calls to pow. One or more statements can be generated for
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574 each logical condition. Statement groups of different conditions
111
kono
parents: 67
diff changeset
575 are separated by a NULL tree and they are stored in the vec
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
576 conds. The number of logical conditions are stored in *nconds.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
578 See C99 standard, 7.12.7.4:2, for description of pow (x, y).
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 The precise condition for domain errors are complex. In this
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
580 implementation, a simplified (but conservative) valid domain
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
581 for x and y are used: x is positive to avoid dom errors, while
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 y is smaller than a upper bound (depending on x) to avoid range
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
583 errors. Runtime code is generated to check x (if not constant)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
584 and y against the valid domain. If it is out, jump to the call,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
585 otherwise the call is bypassed. POW_CALL is the call statement,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 *CONDS is a vector holding the resulting condition statements,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 and *NCONDS is the number of logical conditions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 static void
111
kono
parents: 67
diff changeset
590 gen_conditions_for_pow (gcall *pow_call, vec<gimple *> conds,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591 unsigned *nconds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
593 tree base, expn;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
594 enum tree_code bc;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
595
67
f6334be47118 update gcc from gcc-4.6-20100522 to gcc-4.6-20110318
nobuyasu <dimolto@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
596 gcc_checking_assert (check_pow (pow_call));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
597
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
598 *nconds = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
600 base = gimple_call_arg (pow_call, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
601 expn = gimple_call_arg (pow_call, 1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
602
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 bc = TREE_CODE (base);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 if (bc == REAL_CST)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
606 gen_conditions_for_pow_cst_base (base, expn, conds, nconds);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 else if (bc == SSA_NAME)
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
608 gen_conditions_for_pow_int_base (base, expn, conds, nconds);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
610 gcc_unreachable ();
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 /* A helper routine to help computing the valid input domain
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
614 for a builtin function. See C99 7.12.7 for details. In this
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 implementation, we only handle single region domain. The
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
616 resulting region can be conservative (smaller) than the actual
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
617 one and rounded to integers. Some of the bounds are documented
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
618 in the standard, while other limit constants are computed
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
619 assuming IEEE floating point format (for SF and DF modes).
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
620 Since IEEE only sets minimum requirements for long double format,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
621 different long double formats exist under different implementations
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
622 (e.g, 64 bit double precision (DF), 80 bit double-extended
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
623 precision (XF), and 128 bit quad precision (QF) ). For simplicity,
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
624 in this implementation, the computed bounds for long double assume
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
625 64 bit format (DF), and are therefore conservative. Another
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 assumption is that single precision float type is always SF mode,
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
627 and double type is DF mode. This function is quite
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 implementation specific, so it may not be suitable to be part of
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 builtins.c. This needs to be revisited later to see if it can
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 be leveraged in x87 assembly expansion. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
631
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
632 static inp_domain
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
633 get_no_error_domain (enum built_in_function fnc)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
634 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635 switch (fnc)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 /* Trig functions: return [-1, +1] */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 CASE_FLT_FN (BUILT_IN_ACOS):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
639 CASE_FLT_FN (BUILT_IN_ASIN):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
640 return get_domain (-1, true, true,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
641 1, true, true);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
642 /* Hyperbolic functions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
643 CASE_FLT_FN (BUILT_IN_ACOSH):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
644 /* acosh: [1, +inf) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
645 return get_domain (1, true, true,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
646 1, false, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
647 CASE_FLT_FN (BUILT_IN_ATANH):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
648 /* atanh: (-1, +1) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
649 return get_domain (-1, true, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
650 1, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
651 case BUILT_IN_COSHF:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
652 case BUILT_IN_SINHF:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
653 /* coshf: (-89, +89) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
654 return get_domain (-89, true, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
655 89, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
656 case BUILT_IN_COSH:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
657 case BUILT_IN_SINH:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
658 case BUILT_IN_COSHL:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
659 case BUILT_IN_SINHL:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
660 /* cosh: (-710, +710) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
661 return get_domain (-710, true, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
662 710, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
663 /* Log functions: (0, +inf) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
664 CASE_FLT_FN (BUILT_IN_LOG):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
665 CASE_FLT_FN (BUILT_IN_LOG2):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
666 CASE_FLT_FN (BUILT_IN_LOG10):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
667 return get_domain (0, true, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
668 0, false, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
669 CASE_FLT_FN (BUILT_IN_LOG1P):
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
670 return get_domain (-1, true, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 0, false, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 /* Exp functions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 case BUILT_IN_EXPF:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
674 case BUILT_IN_EXPM1F:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 /* expf: (-inf, 88) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 return get_domain (-1, false, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677 88, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 case BUILT_IN_EXP:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 case BUILT_IN_EXPM1:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 case BUILT_IN_EXPL:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 case BUILT_IN_EXPM1L:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
682 /* exp: (-inf, 709) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 return get_domain (-1, false, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684 709, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
685 case BUILT_IN_EXP2F:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
686 /* exp2f: (-inf, 128) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
687 return get_domain (-1, false, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
688 128, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
689 case BUILT_IN_EXP2:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
690 case BUILT_IN_EXP2L:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 /* exp2: (-inf, 1024) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
692 return get_domain (-1, false, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
693 1024, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
694 case BUILT_IN_EXP10F:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 case BUILT_IN_POW10F:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696 /* exp10f: (-inf, 38) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 return get_domain (-1, false, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 38, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 case BUILT_IN_EXP10:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 case BUILT_IN_POW10:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 case BUILT_IN_EXP10L:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 case BUILT_IN_POW10L:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703 /* exp10: (-inf, 308) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 return get_domain (-1, false, false,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 308, true, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 /* sqrt: [0, +inf) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 CASE_FLT_FN (BUILT_IN_SQRT):
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
708 CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT):
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 return get_domain (0, true, true,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 0, false, false);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 default:
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
712 gcc_unreachable ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
715 gcc_unreachable ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
716 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
717
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 /* The function to generate shrink wrap conditions for a partially
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 dead builtin call whose return value is not used anywhere,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 but has to be kept live due to potential error condition.
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
721 BI_CALL is the builtin call, CONDS is the vector of statements
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
722 for condition code, NCODES is the pointer to the number of
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 logical conditions. Statements belonging to different logical
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 condition are separated by NULL tree in the vector. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
725
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 static void
111
kono
parents: 67
diff changeset
727 gen_shrink_wrap_conditions (gcall *bi_call, vec<gimple *> conds,
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 unsigned int *nconds)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 {
111
kono
parents: 67
diff changeset
730 gcall *call;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 tree fn;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 enum built_in_function fnc;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733
111
kono
parents: 67
diff changeset
734 gcc_assert (nconds && conds.exists ());
kono
parents: 67
diff changeset
735 gcc_assert (conds.length () == 0);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736 gcc_assert (is_gimple_call (bi_call));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 call = bi_call;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 fn = gimple_call_fndecl (call);
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
740 gcc_assert (fn && fndecl_built_in_p (fn));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 fnc = DECL_FUNCTION_CODE (fn);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
742 *nconds = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
743
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
744 if (fnc == BUILT_IN_POW)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
745 gen_conditions_for_pow (call, conds, nconds);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
746 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
747 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
748 tree arg;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
749 inp_domain domain = get_no_error_domain (fnc);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750 *nconds = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 arg = gimple_call_arg (bi_call, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 gen_conditions_for_domain (arg, domain, conds, nconds);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 return;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757
111
kono
parents: 67
diff changeset
758 /* Shrink-wrap BI_CALL so that it is only called when one of the NCONDS
kono
parents: 67
diff changeset
759 conditions in CONDS is false. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760
111
kono
parents: 67
diff changeset
761 static void
kono
parents: 67
diff changeset
762 shrink_wrap_one_built_in_call_with_conds (gcall *bi_call, vec <gimple *> conds,
kono
parents: 67
diff changeset
763 unsigned int nconds)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 gimple_stmt_iterator bi_call_bsi;
111
kono
parents: 67
diff changeset
766 basic_block bi_call_bb, join_tgt_bb, guard_bb;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 edge join_tgt_in_edge_from_call, join_tgt_in_edge_fall_thru;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 edge bi_call_in_edge0, guard_bb_in_edge;
111
kono
parents: 67
diff changeset
769 unsigned tn_cond_stmts;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770 unsigned ci;
111
kono
parents: 67
diff changeset
771 gimple *cond_expr = NULL;
kono
parents: 67
diff changeset
772 gimple *cond_expr_start;
kono
parents: 67
diff changeset
773
kono
parents: 67
diff changeset
774 /* The cfg we want to create looks like this:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
775
111
kono
parents: 67
diff changeset
776 [guard n-1] <- guard_bb (old block)
kono
parents: 67
diff changeset
777 | \
kono
parents: 67
diff changeset
778 | [guard n-2] }
kono
parents: 67
diff changeset
779 | / \ }
kono
parents: 67
diff changeset
780 | / ... } new blocks
kono
parents: 67
diff changeset
781 | / [guard 0] }
kono
parents: 67
diff changeset
782 | / / | }
kono
parents: 67
diff changeset
783 [ call ] | <- bi_call_bb }
kono
parents: 67
diff changeset
784 | \ |
kono
parents: 67
diff changeset
785 | \ |
kono
parents: 67
diff changeset
786 | [ join ] <- join_tgt_bb (old iff call must end bb)
kono
parents: 67
diff changeset
787 |
kono
parents: 67
diff changeset
788 possible EH edges (only if [join] is old)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
789
111
kono
parents: 67
diff changeset
790 When [join] is new, the immediate dominators for these blocks are:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
791
111
kono
parents: 67
diff changeset
792 1. [guard n-1]: unchanged
kono
parents: 67
diff changeset
793 2. [call]: [guard n-1]
kono
parents: 67
diff changeset
794 3. [guard m]: [guard m+1] for 0 <= m <= n-2
kono
parents: 67
diff changeset
795 4. [join]: [guard n-1]
kono
parents: 67
diff changeset
796
kono
parents: 67
diff changeset
797 We punt for the more complex case case of [join] being old and
kono
parents: 67
diff changeset
798 simply free the dominance info. We also punt on postdominators,
kono
parents: 67
diff changeset
799 which aren't expected to be available at this point anyway. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
800 bi_call_bb = gimple_bb (bi_call);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
801
111
kono
parents: 67
diff changeset
802 /* Now find the join target bb -- split bi_call_bb if needed. */
kono
parents: 67
diff changeset
803 if (stmt_ends_bb_p (bi_call))
kono
parents: 67
diff changeset
804 {
kono
parents: 67
diff changeset
805 /* We checked that there was a fallthrough edge in
kono
parents: 67
diff changeset
806 can_guard_call_p. */
kono
parents: 67
diff changeset
807 join_tgt_in_edge_from_call = find_fallthru_edge (bi_call_bb->succs);
kono
parents: 67
diff changeset
808 gcc_assert (join_tgt_in_edge_from_call);
kono
parents: 67
diff changeset
809 /* We don't want to handle PHIs. */
kono
parents: 67
diff changeset
810 if (EDGE_COUNT (join_tgt_in_edge_from_call->dest->preds) > 1)
kono
parents: 67
diff changeset
811 join_tgt_bb = split_edge (join_tgt_in_edge_from_call);
kono
parents: 67
diff changeset
812 else
kono
parents: 67
diff changeset
813 {
kono
parents: 67
diff changeset
814 join_tgt_bb = join_tgt_in_edge_from_call->dest;
kono
parents: 67
diff changeset
815 /* We may have degenerate PHIs in the destination. Propagate
kono
parents: 67
diff changeset
816 those out. */
kono
parents: 67
diff changeset
817 for (gphi_iterator i = gsi_start_phis (join_tgt_bb); !gsi_end_p (i);)
kono
parents: 67
diff changeset
818 {
kono
parents: 67
diff changeset
819 gphi *phi = i.phi ();
kono
parents: 67
diff changeset
820 replace_uses_by (gimple_phi_result (phi),
kono
parents: 67
diff changeset
821 gimple_phi_arg_def (phi, 0));
kono
parents: 67
diff changeset
822 remove_phi_node (&i, true);
kono
parents: 67
diff changeset
823 }
kono
parents: 67
diff changeset
824 }
kono
parents: 67
diff changeset
825 }
kono
parents: 67
diff changeset
826 else
kono
parents: 67
diff changeset
827 {
kono
parents: 67
diff changeset
828 join_tgt_in_edge_from_call = split_block (bi_call_bb, bi_call);
kono
parents: 67
diff changeset
829 join_tgt_bb = join_tgt_in_edge_from_call->dest;
kono
parents: 67
diff changeset
830 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
831
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
832 bi_call_bsi = gsi_for_stmt (bi_call);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
833
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
834 /* Now it is time to insert the first conditional expression
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
835 into bi_call_bb and split this bb so that bi_call is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
836 shrink-wrapped. */
111
kono
parents: 67
diff changeset
837 tn_cond_stmts = conds.length ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
838 cond_expr = NULL;
111
kono
parents: 67
diff changeset
839 cond_expr_start = conds[0];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
840 for (ci = 0; ci < tn_cond_stmts; ci++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
841 {
111
kono
parents: 67
diff changeset
842 gimple *c = conds[ci];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
843 gcc_assert (c || ci != 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
844 if (!c)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
845 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
846 gsi_insert_before (&bi_call_bsi, c, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
847 cond_expr = c;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
848 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
849 ci++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
850 gcc_assert (cond_expr && gimple_code (cond_expr) == GIMPLE_COND);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
851
111
kono
parents: 67
diff changeset
852 typedef std::pair<edge, edge> edge_pair;
kono
parents: 67
diff changeset
853 auto_vec<edge_pair, 8> edges;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
854
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
855 bi_call_in_edge0 = split_block (bi_call_bb, cond_expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
856 bi_call_in_edge0->flags &= ~EDGE_FALLTHRU;
111
kono
parents: 67
diff changeset
857 bi_call_in_edge0->flags |= EDGE_FALSE_VALUE;
kono
parents: 67
diff changeset
858 guard_bb = bi_call_bb;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
859 bi_call_bb = bi_call_in_edge0->dest;
111
kono
parents: 67
diff changeset
860 join_tgt_in_edge_fall_thru = make_edge (guard_bb, join_tgt_bb,
kono
parents: 67
diff changeset
861 EDGE_TRUE_VALUE);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
862
111
kono
parents: 67
diff changeset
863 edges.reserve (nconds);
kono
parents: 67
diff changeset
864 edges.quick_push (edge_pair (bi_call_in_edge0, join_tgt_in_edge_fall_thru));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
866 /* Code generation for the rest of the conditions */
111
kono
parents: 67
diff changeset
867 for (unsigned int i = 1; i < nconds; ++i)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
868 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
869 unsigned ci0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
870 edge bi_call_in_edge;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
871 gimple_stmt_iterator guard_bsi = gsi_for_stmt (cond_expr_start);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
872 ci0 = ci;
111
kono
parents: 67
diff changeset
873 cond_expr_start = conds[ci0];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
874 for (; ci < tn_cond_stmts; ci++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
875 {
111
kono
parents: 67
diff changeset
876 gimple *c = conds[ci];
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
877 gcc_assert (c || ci != ci0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
878 if (!c)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
879 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
880 gsi_insert_before (&guard_bsi, c, GSI_SAME_STMT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
881 cond_expr = c;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
882 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
883 ci++;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
884 gcc_assert (cond_expr && gimple_code (cond_expr) == GIMPLE_COND);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
885 guard_bb_in_edge = split_block (guard_bb, cond_expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
886 guard_bb_in_edge->flags &= ~EDGE_FALLTHRU;
111
kono
parents: 67
diff changeset
887 guard_bb_in_edge->flags |= EDGE_TRUE_VALUE;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
888
111
kono
parents: 67
diff changeset
889 bi_call_in_edge = make_edge (guard_bb, bi_call_bb, EDGE_FALSE_VALUE);
kono
parents: 67
diff changeset
890 edges.quick_push (edge_pair (bi_call_in_edge, guard_bb_in_edge));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
891 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
892
111
kono
parents: 67
diff changeset
893 /* Now update the probability and profile information, processing the
kono
parents: 67
diff changeset
894 guards in order of execution.
kono
parents: 67
diff changeset
895
kono
parents: 67
diff changeset
896 There are two approaches we could take here. On the one hand we
kono
parents: 67
diff changeset
897 could assign a probability of X to the call block and distribute
kono
parents: 67
diff changeset
898 that probability among its incoming edges. On the other hand we
kono
parents: 67
diff changeset
899 could assign a probability of X to each individual call edge.
kono
parents: 67
diff changeset
900
kono
parents: 67
diff changeset
901 The choice only affects calls that have more than one condition.
kono
parents: 67
diff changeset
902 In those cases, the second approach would give the call block
kono
parents: 67
diff changeset
903 a greater probability than the first. However, the difference
kono
parents: 67
diff changeset
904 is only small, and our chosen X is a pure guess anyway.
kono
parents: 67
diff changeset
905
kono
parents: 67
diff changeset
906 Here we take the second approach because it's slightly simpler
kono
parents: 67
diff changeset
907 and because it's easy to see that it doesn't lose profile counts. */
kono
parents: 67
diff changeset
908 bi_call_bb->count = profile_count::zero ();
kono
parents: 67
diff changeset
909 while (!edges.is_empty ())
kono
parents: 67
diff changeset
910 {
kono
parents: 67
diff changeset
911 edge_pair e = edges.pop ();
kono
parents: 67
diff changeset
912 edge call_edge = e.first;
kono
parents: 67
diff changeset
913 edge nocall_edge = e.second;
kono
parents: 67
diff changeset
914 basic_block src_bb = call_edge->src;
kono
parents: 67
diff changeset
915 gcc_assert (src_bb == nocall_edge->src);
kono
parents: 67
diff changeset
916
kono
parents: 67
diff changeset
917 call_edge->probability = profile_probability::very_unlikely ();
kono
parents: 67
diff changeset
918 nocall_edge->probability = profile_probability::always ()
kono
parents: 67
diff changeset
919 - call_edge->probability;
kono
parents: 67
diff changeset
920
kono
parents: 67
diff changeset
921 bi_call_bb->count += call_edge->count ();
kono
parents: 67
diff changeset
922
kono
parents: 67
diff changeset
923 if (nocall_edge->dest != join_tgt_bb)
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
924 nocall_edge->dest->count = src_bb->count - bi_call_bb->count;
111
kono
parents: 67
diff changeset
925 }
kono
parents: 67
diff changeset
926
kono
parents: 67
diff changeset
927 if (dom_info_available_p (CDI_DOMINATORS))
kono
parents: 67
diff changeset
928 {
kono
parents: 67
diff changeset
929 /* The split_blocks leave [guard 0] as the immediate dominator
kono
parents: 67
diff changeset
930 of [call] and [call] as the immediate dominator of [join].
kono
parents: 67
diff changeset
931 Fix them up. */
kono
parents: 67
diff changeset
932 set_immediate_dominator (CDI_DOMINATORS, bi_call_bb, guard_bb);
kono
parents: 67
diff changeset
933 set_immediate_dominator (CDI_DOMINATORS, join_tgt_bb, guard_bb);
kono
parents: 67
diff changeset
934 }
kono
parents: 67
diff changeset
935
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
936 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
937 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
938 location_t loc;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
939 loc = gimple_location (bi_call);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
940 fprintf (dump_file,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941 "%s:%d: note: function call is shrink-wrapped"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
942 " into error conditions.\n",
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
943 LOCATION_FILE (loc), LOCATION_LINE (loc));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
944 }
111
kono
parents: 67
diff changeset
945 }
kono
parents: 67
diff changeset
946
kono
parents: 67
diff changeset
947 /* Shrink-wrap BI_CALL so that it is only called when it might set errno
kono
parents: 67
diff changeset
948 (but is always called if it would set errno). */
kono
parents: 67
diff changeset
949
kono
parents: 67
diff changeset
950 static void
kono
parents: 67
diff changeset
951 shrink_wrap_one_built_in_call (gcall *bi_call)
kono
parents: 67
diff changeset
952 {
kono
parents: 67
diff changeset
953 unsigned nconds = 0;
kono
parents: 67
diff changeset
954 auto_vec<gimple *, 12> conds;
kono
parents: 67
diff changeset
955 gen_shrink_wrap_conditions (bi_call, conds, &nconds);
kono
parents: 67
diff changeset
956 gcc_assert (nconds != 0);
kono
parents: 67
diff changeset
957 shrink_wrap_one_built_in_call_with_conds (bi_call, conds, nconds);
kono
parents: 67
diff changeset
958 }
kono
parents: 67
diff changeset
959
kono
parents: 67
diff changeset
960 /* Return true if built-in function call CALL could be implemented using
kono
parents: 67
diff changeset
961 a combination of an internal function to compute the result and a
kono
parents: 67
diff changeset
962 separate call to set errno. */
kono
parents: 67
diff changeset
963
kono
parents: 67
diff changeset
964 static bool
kono
parents: 67
diff changeset
965 can_use_internal_fn (gcall *call)
kono
parents: 67
diff changeset
966 {
kono
parents: 67
diff changeset
967 /* Only replace calls that set errno. */
kono
parents: 67
diff changeset
968 if (!gimple_vdef (call))
kono
parents: 67
diff changeset
969 return false;
kono
parents: 67
diff changeset
970
kono
parents: 67
diff changeset
971 /* See whether there is an internal function for this built-in. */
kono
parents: 67
diff changeset
972 if (replacement_internal_fn (call) == IFN_LAST)
kono
parents: 67
diff changeset
973 return false;
kono
parents: 67
diff changeset
974
kono
parents: 67
diff changeset
975 /* See whether we can catch all cases where errno would be set,
kono
parents: 67
diff changeset
976 while still avoiding the call in most cases. */
kono
parents: 67
diff changeset
977 if (!can_test_argument_range (call)
kono
parents: 67
diff changeset
978 && !edom_only_function (call))
kono
parents: 67
diff changeset
979 return false;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
980
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
981 return true;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
982 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983
111
kono
parents: 67
diff changeset
984 /* Implement built-in function call CALL using an internal function. */
kono
parents: 67
diff changeset
985
kono
parents: 67
diff changeset
986 static void
kono
parents: 67
diff changeset
987 use_internal_fn (gcall *call)
kono
parents: 67
diff changeset
988 {
kono
parents: 67
diff changeset
989 /* We'll be inserting another call with the same arguments after the
kono
parents: 67
diff changeset
990 lhs has been set, so prevent any possible coalescing failure from
kono
parents: 67
diff changeset
991 having both values live at once. See PR 71020. */
kono
parents: 67
diff changeset
992 replace_abnormal_ssa_names (call);
kono
parents: 67
diff changeset
993
kono
parents: 67
diff changeset
994 unsigned nconds = 0;
kono
parents: 67
diff changeset
995 auto_vec<gimple *, 12> conds;
kono
parents: 67
diff changeset
996 if (can_test_argument_range (call))
kono
parents: 67
diff changeset
997 {
kono
parents: 67
diff changeset
998 gen_shrink_wrap_conditions (call, conds, &nconds);
kono
parents: 67
diff changeset
999 gcc_assert (nconds != 0);
kono
parents: 67
diff changeset
1000 }
kono
parents: 67
diff changeset
1001 else
kono
parents: 67
diff changeset
1002 gcc_assert (edom_only_function (call));
kono
parents: 67
diff changeset
1003
kono
parents: 67
diff changeset
1004 internal_fn ifn = replacement_internal_fn (call);
kono
parents: 67
diff changeset
1005 gcc_assert (ifn != IFN_LAST);
kono
parents: 67
diff changeset
1006
kono
parents: 67
diff changeset
1007 /* Construct the new call, with the same arguments as the original one. */
kono
parents: 67
diff changeset
1008 auto_vec <tree, 16> args;
kono
parents: 67
diff changeset
1009 unsigned int nargs = gimple_call_num_args (call);
kono
parents: 67
diff changeset
1010 for (unsigned int i = 0; i < nargs; ++i)
kono
parents: 67
diff changeset
1011 args.safe_push (gimple_call_arg (call, i));
kono
parents: 67
diff changeset
1012 gcall *new_call = gimple_build_call_internal_vec (ifn, args);
kono
parents: 67
diff changeset
1013 gimple_set_location (new_call, gimple_location (call));
kono
parents: 67
diff changeset
1014 gimple_call_set_nothrow (new_call, gimple_call_nothrow_p (call));
kono
parents: 67
diff changeset
1015
kono
parents: 67
diff changeset
1016 /* Transfer the LHS to the new call. */
kono
parents: 67
diff changeset
1017 tree lhs = gimple_call_lhs (call);
kono
parents: 67
diff changeset
1018 gimple_call_set_lhs (new_call, lhs);
kono
parents: 67
diff changeset
1019 gimple_call_set_lhs (call, NULL_TREE);
kono
parents: 67
diff changeset
1020 SSA_NAME_DEF_STMT (lhs) = new_call;
kono
parents: 67
diff changeset
1021
kono
parents: 67
diff changeset
1022 /* Insert the new call. */
kono
parents: 67
diff changeset
1023 gimple_stmt_iterator gsi = gsi_for_stmt (call);
kono
parents: 67
diff changeset
1024 gsi_insert_before (&gsi, new_call, GSI_SAME_STMT);
kono
parents: 67
diff changeset
1025
kono
parents: 67
diff changeset
1026 if (nconds == 0)
kono
parents: 67
diff changeset
1027 {
kono
parents: 67
diff changeset
1028 /* Skip the call if LHS == LHS. If we reach here, EDOM is the only
kono
parents: 67
diff changeset
1029 valid errno value and it is used iff the result is NaN. */
kono
parents: 67
diff changeset
1030 conds.quick_push (gimple_build_cond (EQ_EXPR, lhs, lhs,
kono
parents: 67
diff changeset
1031 NULL_TREE, NULL_TREE));
kono
parents: 67
diff changeset
1032 nconds++;
kono
parents: 67
diff changeset
1033
kono
parents: 67
diff changeset
1034 /* Try replacing the original call with a direct assignment to
kono
parents: 67
diff changeset
1035 errno, via an internal function. */
kono
parents: 67
diff changeset
1036 if (set_edom_supported_p () && !stmt_ends_bb_p (call))
kono
parents: 67
diff changeset
1037 {
kono
parents: 67
diff changeset
1038 gimple_stmt_iterator gsi = gsi_for_stmt (call);
kono
parents: 67
diff changeset
1039 gcall *new_call = gimple_build_call_internal (IFN_SET_EDOM, 0);
kono
parents: 67
diff changeset
1040 gimple_set_vuse (new_call, gimple_vuse (call));
kono
parents: 67
diff changeset
1041 gimple_set_vdef (new_call, gimple_vdef (call));
kono
parents: 67
diff changeset
1042 SSA_NAME_DEF_STMT (gimple_vdef (new_call)) = new_call;
kono
parents: 67
diff changeset
1043 gimple_set_location (new_call, gimple_location (call));
kono
parents: 67
diff changeset
1044 gsi_replace (&gsi, new_call, false);
kono
parents: 67
diff changeset
1045 call = new_call;
kono
parents: 67
diff changeset
1046 }
kono
parents: 67
diff changeset
1047 }
kono
parents: 67
diff changeset
1048
kono
parents: 67
diff changeset
1049 shrink_wrap_one_built_in_call_with_conds (call, conds, nconds);
kono
parents: 67
diff changeset
1050 }
kono
parents: 67
diff changeset
1051
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 /* The top level function for conditional dead code shrink
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1053 wrapping transformation. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1054
111
kono
parents: 67
diff changeset
1055 static void
kono
parents: 67
diff changeset
1056 shrink_wrap_conditional_dead_built_in_calls (vec<gcall *> calls)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1057 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1058 unsigned i = 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1059
111
kono
parents: 67
diff changeset
1060 unsigned n = calls.length ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1061 for (; i < n ; i++)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062 {
111
kono
parents: 67
diff changeset
1063 gcall *bi_call = calls[i];
kono
parents: 67
diff changeset
1064 if (gimple_call_lhs (bi_call))
kono
parents: 67
diff changeset
1065 use_internal_fn (bi_call);
kono
parents: 67
diff changeset
1066 else
kono
parents: 67
diff changeset
1067 shrink_wrap_one_built_in_call (bi_call);
kono
parents: 67
diff changeset
1068 }
kono
parents: 67
diff changeset
1069 }
kono
parents: 67
diff changeset
1070
kono
parents: 67
diff changeset
1071 namespace {
kono
parents: 67
diff changeset
1072
kono
parents: 67
diff changeset
1073 const pass_data pass_data_call_cdce =
kono
parents: 67
diff changeset
1074 {
kono
parents: 67
diff changeset
1075 GIMPLE_PASS, /* type */
kono
parents: 67
diff changeset
1076 "cdce", /* name */
kono
parents: 67
diff changeset
1077 OPTGROUP_NONE, /* optinfo_flags */
kono
parents: 67
diff changeset
1078 TV_TREE_CALL_CDCE, /* tv_id */
kono
parents: 67
diff changeset
1079 ( PROP_cfg | PROP_ssa ), /* properties_required */
kono
parents: 67
diff changeset
1080 0, /* properties_provided */
kono
parents: 67
diff changeset
1081 0, /* properties_destroyed */
kono
parents: 67
diff changeset
1082 0, /* todo_flags_start */
kono
parents: 67
diff changeset
1083 0, /* todo_flags_finish */
kono
parents: 67
diff changeset
1084 };
kono
parents: 67
diff changeset
1085
kono
parents: 67
diff changeset
1086 class pass_call_cdce : public gimple_opt_pass
kono
parents: 67
diff changeset
1087 {
kono
parents: 67
diff changeset
1088 public:
kono
parents: 67
diff changeset
1089 pass_call_cdce (gcc::context *ctxt)
kono
parents: 67
diff changeset
1090 : gimple_opt_pass (pass_data_call_cdce, ctxt)
kono
parents: 67
diff changeset
1091 {}
kono
parents: 67
diff changeset
1092
kono
parents: 67
diff changeset
1093 /* opt_pass methods: */
kono
parents: 67
diff changeset
1094 virtual bool gate (function *)
kono
parents: 67
diff changeset
1095 {
kono
parents: 67
diff changeset
1096 /* The limit constants used in the implementation
kono
parents: 67
diff changeset
1097 assume IEEE floating point format. Other formats
kono
parents: 67
diff changeset
1098 can be supported in the future if needed. */
kono
parents: 67
diff changeset
1099 return flag_tree_builtin_call_dce != 0;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1100 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1101
111
kono
parents: 67
diff changeset
1102 virtual unsigned int execute (function *);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1103
111
kono
parents: 67
diff changeset
1104 }; // class pass_call_cdce
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1105
111
kono
parents: 67
diff changeset
1106 unsigned int
kono
parents: 67
diff changeset
1107 pass_call_cdce::execute (function *fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1108 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1109 basic_block bb;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1110 gimple_stmt_iterator i;
111
kono
parents: 67
diff changeset
1111 auto_vec<gcall *> cond_dead_built_in_calls;
kono
parents: 67
diff changeset
1112 FOR_EACH_BB_FN (bb, fun)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1113 {
111
kono
parents: 67
diff changeset
1114 /* Skip blocks that are being optimized for size, since our
kono
parents: 67
diff changeset
1115 transformation always increases code size. */
kono
parents: 67
diff changeset
1116 if (optimize_bb_for_size_p (bb))
kono
parents: 67
diff changeset
1117 continue;
kono
parents: 67
diff changeset
1118
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1119 /* Collect dead call candidates. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1120 for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1121 {
111
kono
parents: 67
diff changeset
1122 gcall *stmt = dyn_cast <gcall *> (gsi_stmt (i));
kono
parents: 67
diff changeset
1123 if (stmt
kono
parents: 67
diff changeset
1124 && gimple_call_builtin_p (stmt, BUILT_IN_NORMAL)
kono
parents: 67
diff changeset
1125 && (gimple_call_lhs (stmt)
kono
parents: 67
diff changeset
1126 ? can_use_internal_fn (stmt)
kono
parents: 67
diff changeset
1127 : can_test_argument_range (stmt))
kono
parents: 67
diff changeset
1128 && can_guard_call_p (stmt))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1129 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1130 if (dump_file && (dump_flags & TDF_DETAILS))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1131 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1132 fprintf (dump_file, "Found conditional dead call: ");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133 print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1134 fprintf (dump_file, "\n");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1135 }
111
kono
parents: 67
diff changeset
1136 if (!cond_dead_built_in_calls.exists ())
kono
parents: 67
diff changeset
1137 cond_dead_built_in_calls.create (64);
kono
parents: 67
diff changeset
1138 cond_dead_built_in_calls.safe_push (stmt);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1139 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1140 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1141 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1142
111
kono
parents: 67
diff changeset
1143 if (!cond_dead_built_in_calls.exists ())
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144 return 0;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1145
111
kono
parents: 67
diff changeset
1146 shrink_wrap_conditional_dead_built_in_calls (cond_dead_built_in_calls);
kono
parents: 67
diff changeset
1147 free_dominance_info (CDI_POST_DOMINATORS);
kono
parents: 67
diff changeset
1148 /* As we introduced new control-flow we need to insert PHI-nodes
kono
parents: 67
diff changeset
1149 for the call-clobbers of the remaining call. */
kono
parents: 67
diff changeset
1150 mark_virtual_operands_for_renaming (fun);
kono
parents: 67
diff changeset
1151 return TODO_update_ssa;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1152 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1153
111
kono
parents: 67
diff changeset
1154 } // anon namespace
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1155
111
kono
parents: 67
diff changeset
1156 gimple_opt_pass *
kono
parents: 67
diff changeset
1157 make_pass_call_cdce (gcc::context *ctxt)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 {
111
kono
parents: 67
diff changeset
1159 return new pass_call_cdce (ctxt);
kono
parents: 67
diff changeset
1160 }