annotate gcc/convert.c @ 138:fc828634a951

merge
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 08 Nov 2018 14:17:14 +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 /* Utility routines for data type conversion for GCC.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2 Copyright (C) 1987-2018 Free Software Foundation, Inc.
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 This file is part of GCC.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 GCC is free software; you can redistribute it and/or modify it under
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 the terms of the GNU General Public License as published by the Free
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 Software Foundation; either version 3, or (at your option) any later
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 version.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 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
14 for more details.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 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
17 along with GCC; see the file COPYING3. If not see
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 <http://www.gnu.org/licenses/>. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19
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 /* These routines are somewhat language-independent utility function
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 intended to be called by the language-specific convert () functions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 #include "config.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 #include "system.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 #include "coretypes.h"
111
kono
parents: 67
diff changeset
27 #include "target.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 #include "tree.h"
111
kono
parents: 67
diff changeset
29 #include "diagnostic-core.h"
kono
parents: 67
diff changeset
30 #include "fold-const.h"
kono
parents: 67
diff changeset
31 #include "stor-layout.h"
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 #include "convert.h"
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 #include "langhooks.h"
111
kono
parents: 67
diff changeset
34 #include "builtins.h"
kono
parents: 67
diff changeset
35 #include "ubsan.h"
kono
parents: 67
diff changeset
36 #include "stringpool.h"
kono
parents: 67
diff changeset
37 #include "attribs.h"
kono
parents: 67
diff changeset
38 #include "asan.h"
kono
parents: 67
diff changeset
39
kono
parents: 67
diff changeset
40 #define maybe_fold_build1_loc(FOLD_P, LOC, CODE, TYPE, EXPR) \
kono
parents: 67
diff changeset
41 ((FOLD_P) ? fold_build1_loc (LOC, CODE, TYPE, EXPR) \
kono
parents: 67
diff changeset
42 : build1_loc (LOC, CODE, TYPE, EXPR))
kono
parents: 67
diff changeset
43 #define maybe_fold_build2_loc(FOLD_P, LOC, CODE, TYPE, EXPR1, EXPR2) \
kono
parents: 67
diff changeset
44 ((FOLD_P) ? fold_build2_loc (LOC, CODE, TYPE, EXPR1, EXPR2) \
kono
parents: 67
diff changeset
45 : build2_loc (LOC, CODE, TYPE, EXPR1, EXPR2))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 /* Convert EXPR to some pointer or reference type TYPE.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 EXPR must be pointer, reference, integer, enumeral, or literal zero;
111
kono
parents: 67
diff changeset
49 in other cases error is called. If FOLD_P is true, try to fold the
kono
parents: 67
diff changeset
50 expression. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
51
111
kono
parents: 67
diff changeset
52 static tree
kono
parents: 67
diff changeset
53 convert_to_pointer_1 (tree type, tree expr, bool fold_p)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 {
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
55 location_t loc = EXPR_LOCATION (expr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 if (TREE_TYPE (expr) == type)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 return expr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
58
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 switch (TREE_CODE (TREE_TYPE (expr)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 case POINTER_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 case REFERENCE_TYPE:
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
63 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
64 /* If the pointers point to different address spaces, conversion needs
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
65 to be done via a ADDR_SPACE_CONVERT_EXPR instead of a NOP_EXPR. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
66 addr_space_t to_as = TYPE_ADDR_SPACE (TREE_TYPE (type));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
67 addr_space_t from_as = TYPE_ADDR_SPACE (TREE_TYPE (TREE_TYPE (expr)));
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
68
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
69 if (to_as == from_as)
111
kono
parents: 67
diff changeset
70 return maybe_fold_build1_loc (fold_p, loc, NOP_EXPR, type, expr);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
71 else
111
kono
parents: 67
diff changeset
72 return maybe_fold_build1_loc (fold_p, loc, ADDR_SPACE_CONVERT_EXPR,
kono
parents: 67
diff changeset
73 type, expr);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
74 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
75
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
76 case INTEGER_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
77 case ENUMERAL_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
78 case BOOLEAN_TYPE:
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
79 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
80 /* If the input precision differs from the target pointer type
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
81 precision, first convert the input expression to an integer type of
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
82 the target precision. Some targets, e.g. VMS, need several pointer
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
83 sizes to coexist so the latter isn't necessarily POINTER_SIZE. */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
84 unsigned int pprec = TYPE_PRECISION (type);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
85 unsigned int eprec = TYPE_PRECISION (TREE_TYPE (expr));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
86
111
kono
parents: 67
diff changeset
87 if (eprec != pprec)
kono
parents: 67
diff changeset
88 expr
kono
parents: 67
diff changeset
89 = maybe_fold_build1_loc (fold_p, loc, NOP_EXPR,
kono
parents: 67
diff changeset
90 lang_hooks.types.type_for_size (pprec, 0),
kono
parents: 67
diff changeset
91 expr);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
92 }
111
kono
parents: 67
diff changeset
93 return maybe_fold_build1_loc (fold_p, loc, CONVERT_EXPR, type, expr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
94
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
95 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
96 error ("cannot convert to a pointer type");
111
kono
parents: 67
diff changeset
97 return convert_to_pointer_1 (type, integer_zero_node, fold_p);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
100
111
kono
parents: 67
diff changeset
101 /* A wrapper around convert_to_pointer_1 that always folds the
kono
parents: 67
diff changeset
102 expression. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
103
111
kono
parents: 67
diff changeset
104 tree
kono
parents: 67
diff changeset
105 convert_to_pointer (tree type, tree expr)
kono
parents: 67
diff changeset
106 {
kono
parents: 67
diff changeset
107 return convert_to_pointer_1 (type, expr, true);
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
111
kono
parents: 67
diff changeset
110 /* A wrapper around convert_to_pointer_1 that only folds the
kono
parents: 67
diff changeset
111 expression if DOFOLD, or if it is CONSTANT_CLASS_P. */
kono
parents: 67
diff changeset
112
kono
parents: 67
diff changeset
113 tree
kono
parents: 67
diff changeset
114 convert_to_pointer_maybe_fold (tree type, tree expr, bool dofold)
kono
parents: 67
diff changeset
115 {
kono
parents: 67
diff changeset
116 return convert_to_pointer_1 (type, expr, dofold || CONSTANT_CLASS_P (expr));
kono
parents: 67
diff changeset
117 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
118
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 /* Convert EXPR to some floating-point type TYPE.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
121 EXPR must be float, fixed-point, integer, or enumeral;
111
kono
parents: 67
diff changeset
122 in other cases error is called. If FOLD_P is true, try to fold
kono
parents: 67
diff changeset
123 the expression. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
124
111
kono
parents: 67
diff changeset
125 static tree
kono
parents: 67
diff changeset
126 convert_to_real_1 (tree type, tree expr, bool fold_p)
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 enum built_in_function fcode = builtin_mathfn_code (expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
129 tree itype = TREE_TYPE (expr);
111
kono
parents: 67
diff changeset
130 location_t loc = EXPR_LOCATION (expr);
kono
parents: 67
diff changeset
131
kono
parents: 67
diff changeset
132 if (TREE_CODE (expr) == COMPOUND_EXPR)
kono
parents: 67
diff changeset
133 {
kono
parents: 67
diff changeset
134 tree t = convert_to_real_1 (type, TREE_OPERAND (expr, 1), fold_p);
kono
parents: 67
diff changeset
135 if (t == TREE_OPERAND (expr, 1))
kono
parents: 67
diff changeset
136 return expr;
kono
parents: 67
diff changeset
137 return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (t),
kono
parents: 67
diff changeset
138 TREE_OPERAND (expr, 0), t);
kono
parents: 67
diff changeset
139 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
140
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
141 /* Disable until we figure out how to decide whether the functions are
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
142 present in runtime. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
143 /* Convert (float)sqrt((double)x) where x is float into sqrtf(x) */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
144 if (optimize
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
145 && (TYPE_MODE (type) == TYPE_MODE (double_type_node)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
146 || TYPE_MODE (type) == TYPE_MODE (float_type_node)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
147 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
148 switch (fcode)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
149 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
150 #define CASE_MATHFN(FN) case BUILT_IN_##FN: case BUILT_IN_##FN##L:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
151 CASE_MATHFN (COSH)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
152 CASE_MATHFN (EXP)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 CASE_MATHFN (EXP10)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
154 CASE_MATHFN (EXP2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
155 CASE_MATHFN (EXPM1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
156 CASE_MATHFN (GAMMA)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
157 CASE_MATHFN (J0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
158 CASE_MATHFN (J1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
159 CASE_MATHFN (LGAMMA)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
160 CASE_MATHFN (POW10)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
161 CASE_MATHFN (SINH)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
162 CASE_MATHFN (TGAMMA)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
163 CASE_MATHFN (Y0)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
164 CASE_MATHFN (Y1)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
165 /* The above functions may set errno differently with float
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
166 input or output so this transformation is not safe with
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
167 -fmath-errno. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
168 if (flag_errno_math)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
169 break;
111
kono
parents: 67
diff changeset
170 gcc_fallthrough ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
171 CASE_MATHFN (ACOS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
172 CASE_MATHFN (ACOSH)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
173 CASE_MATHFN (ASIN)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
174 CASE_MATHFN (ASINH)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
175 CASE_MATHFN (ATAN)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
176 CASE_MATHFN (ATANH)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
177 CASE_MATHFN (CBRT)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
178 CASE_MATHFN (COS)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
179 CASE_MATHFN (ERF)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
180 CASE_MATHFN (ERFC)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
181 CASE_MATHFN (LOG)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
182 CASE_MATHFN (LOG10)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
183 CASE_MATHFN (LOG2)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
184 CASE_MATHFN (LOG1P)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185 CASE_MATHFN (SIN)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
186 CASE_MATHFN (TAN)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
187 CASE_MATHFN (TANH)
111
kono
parents: 67
diff changeset
188 /* The above functions are not safe to do this conversion. */
kono
parents: 67
diff changeset
189 if (!flag_unsafe_math_optimizations)
kono
parents: 67
diff changeset
190 break;
kono
parents: 67
diff changeset
191 gcc_fallthrough ();
kono
parents: 67
diff changeset
192 CASE_MATHFN (SQRT)
kono
parents: 67
diff changeset
193 CASE_MATHFN (FABS)
kono
parents: 67
diff changeset
194 CASE_MATHFN (LOGB)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
195 #undef CASE_MATHFN
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
196 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
197 tree arg0 = strip_float_extensions (CALL_EXPR_ARG (expr, 0));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
198 tree newtype = type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
199
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
200 /* We have (outertype)sqrt((innertype)x). Choose the wider mode from
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
201 the both as the safe type for operation. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
202 if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
203 newtype = TREE_TYPE (arg0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
204
111
kono
parents: 67
diff changeset
205 /* We consider to convert
kono
parents: 67
diff changeset
206
kono
parents: 67
diff changeset
207 (T1) sqrtT2 ((T2) exprT3)
kono
parents: 67
diff changeset
208 to
kono
parents: 67
diff changeset
209 (T1) sqrtT4 ((T4) exprT3)
kono
parents: 67
diff changeset
210
kono
parents: 67
diff changeset
211 , where T1 is TYPE, T2 is ITYPE, T3 is TREE_TYPE (ARG0),
kono
parents: 67
diff changeset
212 and T4 is NEWTYPE. All those types are of floating point types.
kono
parents: 67
diff changeset
213 T4 (NEWTYPE) should be narrower than T2 (ITYPE). This conversion
kono
parents: 67
diff changeset
214 is safe only if P1 >= P2*2+2, where P1 and P2 are precisions of
kono
parents: 67
diff changeset
215 T2 and T4. See the following URL for a reference:
kono
parents: 67
diff changeset
216 http://stackoverflow.com/questions/9235456/determining-
kono
parents: 67
diff changeset
217 floating-point-square-root
kono
parents: 67
diff changeset
218 */
kono
parents: 67
diff changeset
219 if ((fcode == BUILT_IN_SQRT || fcode == BUILT_IN_SQRTL)
kono
parents: 67
diff changeset
220 && !flag_unsafe_math_optimizations)
kono
parents: 67
diff changeset
221 {
kono
parents: 67
diff changeset
222 /* The following conversion is unsafe even the precision condition
kono
parents: 67
diff changeset
223 below is satisfied:
kono
parents: 67
diff changeset
224
kono
parents: 67
diff changeset
225 (float) sqrtl ((long double) double_val) -> (float) sqrt (double_val)
kono
parents: 67
diff changeset
226 */
kono
parents: 67
diff changeset
227 if (TYPE_MODE (type) != TYPE_MODE (newtype))
kono
parents: 67
diff changeset
228 break;
kono
parents: 67
diff changeset
229
kono
parents: 67
diff changeset
230 int p1 = REAL_MODE_FORMAT (TYPE_MODE (itype))->p;
kono
parents: 67
diff changeset
231 int p2 = REAL_MODE_FORMAT (TYPE_MODE (newtype))->p;
kono
parents: 67
diff changeset
232 if (p1 < p2 * 2 + 2)
kono
parents: 67
diff changeset
233 break;
kono
parents: 67
diff changeset
234 }
kono
parents: 67
diff changeset
235
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
236 /* Be careful about integer to fp conversions.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
237 These may overflow still. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
238 if (FLOAT_TYPE_P (TREE_TYPE (arg0))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
239 && TYPE_PRECISION (newtype) < TYPE_PRECISION (itype)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
240 && (TYPE_MODE (newtype) == TYPE_MODE (double_type_node)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
241 || TYPE_MODE (newtype) == TYPE_MODE (float_type_node)))
111
kono
parents: 67
diff changeset
242 {
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
243 tree fn = mathfn_built_in (newtype, fcode);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
244 if (fn)
111
kono
parents: 67
diff changeset
245 {
kono
parents: 67
diff changeset
246 tree arg = convert_to_real_1 (newtype, arg0, fold_p);
kono
parents: 67
diff changeset
247 expr = build_call_expr (fn, 1, arg);
kono
parents: 67
diff changeset
248 if (newtype == type)
kono
parents: 67
diff changeset
249 return expr;
kono
parents: 67
diff changeset
250 }
0
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 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
253 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
254 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
255 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
256 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
257
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
258 /* Propagate the cast into the operation. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
259 if (itype != type && FLOAT_TYPE_P (type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
260 switch (TREE_CODE (expr))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
261 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
262 /* Convert (float)-x into -(float)x. This is safe for
111
kono
parents: 67
diff changeset
263 round-to-nearest rounding mode when the inner type is float. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
264 case ABS_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
265 case NEGATE_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
266 if (!flag_rounding_math
111
kono
parents: 67
diff changeset
267 && FLOAT_TYPE_P (itype)
kono
parents: 67
diff changeset
268 && TYPE_PRECISION (type) < TYPE_PRECISION (itype))
kono
parents: 67
diff changeset
269 {
kono
parents: 67
diff changeset
270 tree arg = convert_to_real_1 (type, TREE_OPERAND (expr, 0),
kono
parents: 67
diff changeset
271 fold_p);
kono
parents: 67
diff changeset
272 return build1 (TREE_CODE (expr), type, arg);
kono
parents: 67
diff changeset
273 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
274 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
275 /* Convert (outertype)((innertype0)a+(innertype1)b)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
276 into ((newtype)a+(newtype)b) where newtype
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
277 is the widest mode from all of these. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
278 case PLUS_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
279 case MINUS_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
280 case MULT_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
281 case RDIV_EXPR:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
282 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
283 tree arg0 = strip_float_extensions (TREE_OPERAND (expr, 0));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
284 tree arg1 = strip_float_extensions (TREE_OPERAND (expr, 1));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
285
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
286 if (FLOAT_TYPE_P (TREE_TYPE (arg0))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
287 && FLOAT_TYPE_P (TREE_TYPE (arg1))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
288 && DECIMAL_FLOAT_TYPE_P (itype) == DECIMAL_FLOAT_TYPE_P (type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
289 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
290 tree newtype = type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
291
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
292 if (TYPE_MODE (TREE_TYPE (arg0)) == SDmode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
293 || TYPE_MODE (TREE_TYPE (arg1)) == SDmode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
294 || TYPE_MODE (type) == SDmode)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
295 newtype = dfloat32_type_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
296 if (TYPE_MODE (TREE_TYPE (arg0)) == DDmode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
297 || TYPE_MODE (TREE_TYPE (arg1)) == DDmode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
298 || TYPE_MODE (type) == DDmode)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
299 newtype = dfloat64_type_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
300 if (TYPE_MODE (TREE_TYPE (arg0)) == TDmode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
301 || TYPE_MODE (TREE_TYPE (arg1)) == TDmode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
302 || TYPE_MODE (type) == TDmode)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
303 newtype = dfloat128_type_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
304 if (newtype == dfloat32_type_node
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
305 || newtype == dfloat64_type_node
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
306 || newtype == dfloat128_type_node)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
307 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
308 expr = build2 (TREE_CODE (expr), newtype,
111
kono
parents: 67
diff changeset
309 convert_to_real_1 (newtype, arg0,
kono
parents: 67
diff changeset
310 fold_p),
kono
parents: 67
diff changeset
311 convert_to_real_1 (newtype, arg1,
kono
parents: 67
diff changeset
312 fold_p));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
313 if (newtype == type)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
314 return expr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
315 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
317
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
318 if (TYPE_PRECISION (TREE_TYPE (arg0)) > TYPE_PRECISION (newtype))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 newtype = TREE_TYPE (arg0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
320 if (TYPE_PRECISION (TREE_TYPE (arg1)) > TYPE_PRECISION (newtype))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
321 newtype = TREE_TYPE (arg1);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 /* Sometimes this transformation is safe (cannot
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
323 change results through affecting double rounding
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
324 cases) and sometimes it is not. If NEWTYPE is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
325 wider than TYPE, e.g. (float)((long double)double
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
326 + (long double)double) converted to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
327 (float)(double + double), the transformation is
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
328 unsafe regardless of the details of the types
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
329 involved; double rounding can arise if the result
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330 of NEWTYPE arithmetic is a NEWTYPE value half way
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
331 between two representable TYPE values but the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
332 exact value is sufficiently different (in the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
333 right direction) for this difference to be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
334 visible in ITYPE arithmetic. If NEWTYPE is the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
335 same as TYPE, however, the transformation may be
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 safe depending on the types involved: it is safe
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
337 if the ITYPE has strictly more than twice as many
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 mantissa bits as TYPE, can represent infinities
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
339 and NaNs if the TYPE can, and has sufficient
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 exponent range for the product or ratio of two
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
341 values representable in the TYPE to be within the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
342 range of normal values of ITYPE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
343 if (TYPE_PRECISION (newtype) < TYPE_PRECISION (itype)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
344 && (flag_unsafe_math_optimizations
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
345 || (TYPE_PRECISION (newtype) == TYPE_PRECISION (type)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 && real_can_shorten_arithmetic (TYPE_MODE (itype),
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
347 TYPE_MODE (type))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
348 && !excess_precision_type (newtype))))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
350 expr = build2 (TREE_CODE (expr), newtype,
111
kono
parents: 67
diff changeset
351 convert_to_real_1 (newtype, arg0,
kono
parents: 67
diff changeset
352 fold_p),
kono
parents: 67
diff changeset
353 convert_to_real_1 (newtype, arg1,
kono
parents: 67
diff changeset
354 fold_p));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 if (newtype == type)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
356 return expr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
357 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
358 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
359 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
360 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
361 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
362 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
363 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
364
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
365 switch (TREE_CODE (TREE_TYPE (expr)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
366 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
367 case REAL_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
368 /* Ignore the conversion if we don't need to store intermediate
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
369 results and neither type is a decimal float. */
111
kono
parents: 67
diff changeset
370 return build1_loc (loc,
kono
parents: 67
diff changeset
371 (flag_float_store
kono
parents: 67
diff changeset
372 || DECIMAL_FLOAT_TYPE_P (type)
kono
parents: 67
diff changeset
373 || DECIMAL_FLOAT_TYPE_P (itype))
kono
parents: 67
diff changeset
374 ? CONVERT_EXPR : NOP_EXPR, type, expr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
375
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
376 case INTEGER_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 case ENUMERAL_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
378 case BOOLEAN_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
379 return build1 (FLOAT_EXPR, type, expr);
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 case FIXED_POINT_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
382 return build1 (FIXED_CONVERT_EXPR, type, expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
383
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
384 case COMPLEX_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
385 return convert (type,
111
kono
parents: 67
diff changeset
386 maybe_fold_build1_loc (fold_p, loc, REALPART_EXPR,
kono
parents: 67
diff changeset
387 TREE_TYPE (TREE_TYPE (expr)),
kono
parents: 67
diff changeset
388 expr));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
389
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
390 case POINTER_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
391 case REFERENCE_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
392 error ("pointer value used where a floating point value was expected");
111
kono
parents: 67
diff changeset
393 return convert_to_real_1 (type, integer_zero_node, fold_p);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
394
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
395 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
396 error ("aggregate value used where a float was expected");
111
kono
parents: 67
diff changeset
397 return convert_to_real_1 (type, integer_zero_node, fold_p);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
398 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
399 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
400
111
kono
parents: 67
diff changeset
401 /* A wrapper around convert_to_real_1 that always folds the
kono
parents: 67
diff changeset
402 expression. */
kono
parents: 67
diff changeset
403
kono
parents: 67
diff changeset
404 tree
kono
parents: 67
diff changeset
405 convert_to_real (tree type, tree expr)
kono
parents: 67
diff changeset
406 {
kono
parents: 67
diff changeset
407 return convert_to_real_1 (type, expr, true);
kono
parents: 67
diff changeset
408 }
kono
parents: 67
diff changeset
409
kono
parents: 67
diff changeset
410 /* A wrapper around convert_to_real_1 that only folds the
kono
parents: 67
diff changeset
411 expression if DOFOLD, or if it is CONSTANT_CLASS_P. */
kono
parents: 67
diff changeset
412
kono
parents: 67
diff changeset
413 tree
kono
parents: 67
diff changeset
414 convert_to_real_maybe_fold (tree type, tree expr, bool dofold)
kono
parents: 67
diff changeset
415 {
kono
parents: 67
diff changeset
416 return convert_to_real_1 (type, expr, dofold || CONSTANT_CLASS_P (expr));
kono
parents: 67
diff changeset
417 }
kono
parents: 67
diff changeset
418
kono
parents: 67
diff changeset
419 /* Try to narrow EX_FORM ARG0 ARG1 in narrowed arg types producing a
kono
parents: 67
diff changeset
420 result in TYPE. */
kono
parents: 67
diff changeset
421
kono
parents: 67
diff changeset
422 static tree
kono
parents: 67
diff changeset
423 do_narrow (location_t loc,
kono
parents: 67
diff changeset
424 enum tree_code ex_form, tree type, tree arg0, tree arg1,
kono
parents: 67
diff changeset
425 tree expr, unsigned inprec, unsigned outprec, bool dofold)
kono
parents: 67
diff changeset
426 {
kono
parents: 67
diff changeset
427 /* Do the arithmetic in type TYPEX,
kono
parents: 67
diff changeset
428 then convert result to TYPE. */
kono
parents: 67
diff changeset
429 tree typex = type;
kono
parents: 67
diff changeset
430
kono
parents: 67
diff changeset
431 /* Can't do arithmetic in enumeral types
kono
parents: 67
diff changeset
432 so use an integer type that will hold the values. */
kono
parents: 67
diff changeset
433 if (TREE_CODE (typex) == ENUMERAL_TYPE)
kono
parents: 67
diff changeset
434 typex = lang_hooks.types.type_for_size (TYPE_PRECISION (typex),
kono
parents: 67
diff changeset
435 TYPE_UNSIGNED (typex));
kono
parents: 67
diff changeset
436
kono
parents: 67
diff changeset
437 /* The type demotion below might cause doing unsigned arithmetic
kono
parents: 67
diff changeset
438 instead of signed, and thus hide overflow bugs. */
kono
parents: 67
diff changeset
439 if ((ex_form == PLUS_EXPR || ex_form == MINUS_EXPR)
kono
parents: 67
diff changeset
440 && !TYPE_UNSIGNED (typex)
kono
parents: 67
diff changeset
441 && sanitize_flags_p (SANITIZE_SI_OVERFLOW))
kono
parents: 67
diff changeset
442 return NULL_TREE;
kono
parents: 67
diff changeset
443
kono
parents: 67
diff changeset
444 /* But now perhaps TYPEX is as wide as INPREC.
kono
parents: 67
diff changeset
445 In that case, do nothing special here.
kono
parents: 67
diff changeset
446 (Otherwise would recurse infinitely in convert. */
kono
parents: 67
diff changeset
447 if (TYPE_PRECISION (typex) != inprec)
kono
parents: 67
diff changeset
448 {
kono
parents: 67
diff changeset
449 /* Don't do unsigned arithmetic where signed was wanted,
kono
parents: 67
diff changeset
450 or vice versa.
kono
parents: 67
diff changeset
451 Exception: if both of the original operands were
kono
parents: 67
diff changeset
452 unsigned then we can safely do the work as unsigned.
kono
parents: 67
diff changeset
453 Exception: shift operations take their type solely
kono
parents: 67
diff changeset
454 from the first argument.
kono
parents: 67
diff changeset
455 Exception: the LSHIFT_EXPR case above requires that
kono
parents: 67
diff changeset
456 we perform this operation unsigned lest we produce
kono
parents: 67
diff changeset
457 signed-overflow undefinedness.
kono
parents: 67
diff changeset
458 And we may need to do it as unsigned
kono
parents: 67
diff changeset
459 if we truncate to the original size. */
kono
parents: 67
diff changeset
460 if (TYPE_UNSIGNED (TREE_TYPE (expr))
kono
parents: 67
diff changeset
461 || (TYPE_UNSIGNED (TREE_TYPE (arg0))
kono
parents: 67
diff changeset
462 && (TYPE_UNSIGNED (TREE_TYPE (arg1))
kono
parents: 67
diff changeset
463 || ex_form == LSHIFT_EXPR
kono
parents: 67
diff changeset
464 || ex_form == RSHIFT_EXPR
kono
parents: 67
diff changeset
465 || ex_form == LROTATE_EXPR
kono
parents: 67
diff changeset
466 || ex_form == RROTATE_EXPR))
kono
parents: 67
diff changeset
467 || ex_form == LSHIFT_EXPR
kono
parents: 67
diff changeset
468 /* If we have !flag_wrapv, and either ARG0 or
kono
parents: 67
diff changeset
469 ARG1 is of a signed type, we have to do
kono
parents: 67
diff changeset
470 PLUS_EXPR, MINUS_EXPR or MULT_EXPR in an unsigned
kono
parents: 67
diff changeset
471 type in case the operation in outprec precision
kono
parents: 67
diff changeset
472 could overflow. Otherwise, we would introduce
kono
parents: 67
diff changeset
473 signed-overflow undefinedness. */
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
474 || ((!(INTEGRAL_TYPE_P (TREE_TYPE (arg0))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
475 && TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg0)))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
476 || !(INTEGRAL_TYPE_P (TREE_TYPE (arg1))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
477 && TYPE_OVERFLOW_WRAPS (TREE_TYPE (arg1))))
111
kono
parents: 67
diff changeset
478 && ((TYPE_PRECISION (TREE_TYPE (arg0)) * 2u
kono
parents: 67
diff changeset
479 > outprec)
kono
parents: 67
diff changeset
480 || (TYPE_PRECISION (TREE_TYPE (arg1)) * 2u
kono
parents: 67
diff changeset
481 > outprec))
kono
parents: 67
diff changeset
482 && (ex_form == PLUS_EXPR
kono
parents: 67
diff changeset
483 || ex_form == MINUS_EXPR
kono
parents: 67
diff changeset
484 || ex_form == MULT_EXPR)))
kono
parents: 67
diff changeset
485 {
kono
parents: 67
diff changeset
486 if (!TYPE_UNSIGNED (typex))
kono
parents: 67
diff changeset
487 typex = unsigned_type_for (typex);
kono
parents: 67
diff changeset
488 }
kono
parents: 67
diff changeset
489 else
kono
parents: 67
diff changeset
490 {
kono
parents: 67
diff changeset
491 if (TYPE_UNSIGNED (typex))
kono
parents: 67
diff changeset
492 typex = signed_type_for (typex);
kono
parents: 67
diff changeset
493 }
kono
parents: 67
diff changeset
494 /* We should do away with all this once we have a proper
kono
parents: 67
diff changeset
495 type promotion/demotion pass, see PR45397. */
kono
parents: 67
diff changeset
496 expr = maybe_fold_build2_loc (dofold, loc, ex_form, typex,
kono
parents: 67
diff changeset
497 convert (typex, arg0),
kono
parents: 67
diff changeset
498 convert (typex, arg1));
kono
parents: 67
diff changeset
499 return convert (type, expr);
kono
parents: 67
diff changeset
500 }
kono
parents: 67
diff changeset
501
kono
parents: 67
diff changeset
502 return NULL_TREE;
kono
parents: 67
diff changeset
503 }
kono
parents: 67
diff changeset
504
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 /* Convert EXPR to some integer (or enum) type TYPE.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
506
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 EXPR must be pointer, integer, discrete (enum, char, or bool), float,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 fixed-point or vector; in other cases error is called.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
509
111
kono
parents: 67
diff changeset
510 If DOFOLD is TRUE, we try to simplify newly-created patterns by folding.
kono
parents: 67
diff changeset
511
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
512 The result of this is always supposed to be a newly created tree node
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 not in use in any existing structure. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
514
111
kono
parents: 67
diff changeset
515 static tree
kono
parents: 67
diff changeset
516 convert_to_integer_1 (tree type, tree expr, bool dofold)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
518 enum tree_code ex_form = TREE_CODE (expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 tree intype = TREE_TYPE (expr);
111
kono
parents: 67
diff changeset
520 unsigned int inprec = element_precision (intype);
kono
parents: 67
diff changeset
521 unsigned int outprec = element_precision (type);
kono
parents: 67
diff changeset
522 location_t loc = EXPR_LOCATION (expr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
523
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
524 /* An INTEGER_TYPE cannot be incomplete, but an ENUMERAL_TYPE can
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
525 be. Consider `enum E = { a, b = (enum E) 3 };'. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
526 if (!COMPLETE_TYPE_P (type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
527 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
528 error ("conversion to incomplete type");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
529 return error_mark_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
530 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
531
111
kono
parents: 67
diff changeset
532 if (ex_form == COMPOUND_EXPR)
kono
parents: 67
diff changeset
533 {
kono
parents: 67
diff changeset
534 tree t = convert_to_integer_1 (type, TREE_OPERAND (expr, 1), dofold);
kono
parents: 67
diff changeset
535 if (t == TREE_OPERAND (expr, 1))
kono
parents: 67
diff changeset
536 return expr;
kono
parents: 67
diff changeset
537 return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR, TREE_TYPE (t),
kono
parents: 67
diff changeset
538 TREE_OPERAND (expr, 0), t);
kono
parents: 67
diff changeset
539 }
kono
parents: 67
diff changeset
540
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
541 /* Convert e.g. (long)round(d) -> lround(d). */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 /* If we're converting to char, we may encounter differing behavior
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 between converting from double->char vs double->long->char.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 We're in "undefined" territory but we prefer to be conservative,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
545 so only proceed in "unsafe" math mode. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
546 if (optimize
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
547 && (flag_unsafe_math_optimizations
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
548 || (long_integer_type_node
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
549 && outprec >= TYPE_PRECISION (long_integer_type_node))))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
550 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
551 tree s_expr = strip_float_extensions (expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
552 tree s_intype = TREE_TYPE (s_expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
553 const enum built_in_function fcode = builtin_mathfn_code (s_expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
554 tree fn = 0;
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
555
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
556 switch (fcode)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
557 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
558 CASE_FLT_FN (BUILT_IN_CEIL):
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
559 CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL):
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
560 /* Only convert in ISO C99 mode. */
111
kono
parents: 67
diff changeset
561 if (!targetm.libc_has_function (function_c99_misc))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
562 break;
111
kono
parents: 67
diff changeset
563 if (outprec < TYPE_PRECISION (integer_type_node)
kono
parents: 67
diff changeset
564 || (outprec == TYPE_PRECISION (integer_type_node)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
565 && !TYPE_UNSIGNED (type)))
111
kono
parents: 67
diff changeset
566 fn = mathfn_built_in (s_intype, BUILT_IN_ICEIL);
kono
parents: 67
diff changeset
567 else if (outprec == TYPE_PRECISION (long_integer_type_node)
kono
parents: 67
diff changeset
568 && !TYPE_UNSIGNED (type))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
569 fn = mathfn_built_in (s_intype, BUILT_IN_LCEIL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
570 else if (outprec == TYPE_PRECISION (long_long_integer_type_node)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
571 && !TYPE_UNSIGNED (type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
572 fn = mathfn_built_in (s_intype, BUILT_IN_LLCEIL);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
573 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
574
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
575 CASE_FLT_FN (BUILT_IN_FLOOR):
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
576 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR):
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
577 /* Only convert in ISO C99 mode. */
111
kono
parents: 67
diff changeset
578 if (!targetm.libc_has_function (function_c99_misc))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
579 break;
111
kono
parents: 67
diff changeset
580 if (outprec < TYPE_PRECISION (integer_type_node)
kono
parents: 67
diff changeset
581 || (outprec == TYPE_PRECISION (integer_type_node)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
582 && !TYPE_UNSIGNED (type)))
111
kono
parents: 67
diff changeset
583 fn = mathfn_built_in (s_intype, BUILT_IN_IFLOOR);
kono
parents: 67
diff changeset
584 else if (outprec == TYPE_PRECISION (long_integer_type_node)
kono
parents: 67
diff changeset
585 && !TYPE_UNSIGNED (type))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
586 fn = mathfn_built_in (s_intype, BUILT_IN_LFLOOR);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
587 else if (outprec == TYPE_PRECISION (long_long_integer_type_node)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
588 && !TYPE_UNSIGNED (type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
589 fn = mathfn_built_in (s_intype, BUILT_IN_LLFLOOR);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
590 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
591
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
592 CASE_FLT_FN (BUILT_IN_ROUND):
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
593 CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND):
111
kono
parents: 67
diff changeset
594 /* Only convert in ISO C99 mode and with -fno-math-errno. */
kono
parents: 67
diff changeset
595 if (!targetm.libc_has_function (function_c99_misc) || flag_errno_math)
kono
parents: 67
diff changeset
596 break;
kono
parents: 67
diff changeset
597 if (outprec < TYPE_PRECISION (integer_type_node)
kono
parents: 67
diff changeset
598 || (outprec == TYPE_PRECISION (integer_type_node)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
599 && !TYPE_UNSIGNED (type)))
111
kono
parents: 67
diff changeset
600 fn = mathfn_built_in (s_intype, BUILT_IN_IROUND);
kono
parents: 67
diff changeset
601 else if (outprec == TYPE_PRECISION (long_integer_type_node)
kono
parents: 67
diff changeset
602 && !TYPE_UNSIGNED (type))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
603 fn = mathfn_built_in (s_intype, BUILT_IN_LROUND);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
604 else if (outprec == TYPE_PRECISION (long_long_integer_type_node)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
605 && !TYPE_UNSIGNED (type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
606 fn = mathfn_built_in (s_intype, BUILT_IN_LLROUND);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
607 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
608
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
609 CASE_FLT_FN (BUILT_IN_NEARBYINT):
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
610 CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT):
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
611 /* Only convert nearbyint* if we can ignore math exceptions. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
612 if (flag_trapping_math)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
613 break;
111
kono
parents: 67
diff changeset
614 gcc_fallthrough ();
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
615 CASE_FLT_FN (BUILT_IN_RINT):
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
616 CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT):
111
kono
parents: 67
diff changeset
617 /* Only convert in ISO C99 mode and with -fno-math-errno. */
kono
parents: 67
diff changeset
618 if (!targetm.libc_has_function (function_c99_misc) || flag_errno_math)
kono
parents: 67
diff changeset
619 break;
kono
parents: 67
diff changeset
620 if (outprec < TYPE_PRECISION (integer_type_node)
kono
parents: 67
diff changeset
621 || (outprec == TYPE_PRECISION (integer_type_node)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
622 && !TYPE_UNSIGNED (type)))
111
kono
parents: 67
diff changeset
623 fn = mathfn_built_in (s_intype, BUILT_IN_IRINT);
kono
parents: 67
diff changeset
624 else if (outprec == TYPE_PRECISION (long_integer_type_node)
kono
parents: 67
diff changeset
625 && !TYPE_UNSIGNED (type))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
626 fn = mathfn_built_in (s_intype, BUILT_IN_LRINT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
627 else if (outprec == TYPE_PRECISION (long_long_integer_type_node)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
628 && !TYPE_UNSIGNED (type))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
629 fn = mathfn_built_in (s_intype, BUILT_IN_LLRINT);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
630 break;
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 CASE_FLT_FN (BUILT_IN_TRUNC):
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
633 CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC):
111
kono
parents: 67
diff changeset
634 return convert_to_integer_1 (type, CALL_EXPR_ARG (s_expr, 0), dofold);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
635
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
636 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
637 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
638 }
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
639
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
640 if (fn)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
641 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
642 tree newexpr = build_call_expr (fn, 1, CALL_EXPR_ARG (s_expr, 0));
111
kono
parents: 67
diff changeset
643 return convert_to_integer_1 (type, newexpr, dofold);
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
644 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
645 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
646
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
647 /* Convert (int)logb(d) -> ilogb(d). */
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
648 if (optimize
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
649 && flag_unsafe_math_optimizations
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
650 && !flag_trapping_math && !flag_errno_math && flag_finite_math_only
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
651 && integer_type_node
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
652 && (outprec > TYPE_PRECISION (integer_type_node)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
653 || (outprec == TYPE_PRECISION (integer_type_node)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
654 && !TYPE_UNSIGNED (type))))
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
655 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
656 tree s_expr = strip_float_extensions (expr);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
657 tree s_intype = TREE_TYPE (s_expr);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
658 const enum built_in_function fcode = builtin_mathfn_code (s_expr);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
659 tree fn = 0;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
660
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
661 switch (fcode)
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
662 {
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
663 CASE_FLT_FN (BUILT_IN_LOGB):
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
664 fn = mathfn_built_in (s_intype, BUILT_IN_ILOGB);
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
665 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
666
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
667 default:
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
668 break;
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
669 }
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
670
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
671 if (fn)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
672 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
673 tree newexpr = build_call_expr (fn, 1, CALL_EXPR_ARG (s_expr, 0));
111
kono
parents: 67
diff changeset
674 return convert_to_integer_1 (type, newexpr, dofold);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
675 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
676 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
677
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
678 switch (TREE_CODE (intype))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
679 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
680 case POINTER_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
681 case REFERENCE_TYPE:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
682 if (integer_zerop (expr) && !TREE_OVERFLOW (expr))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
683 return build_int_cst (type, 0);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
684
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
685 /* Convert to an unsigned integer of the correct width first, and from
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
686 there widen/truncate to the required type. Some targets support the
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
687 coexistence of multiple valid pointer sizes, so fetch the one we need
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
688 from the type. */
111
kono
parents: 67
diff changeset
689 if (!dofold)
kono
parents: 67
diff changeset
690 return build1 (CONVERT_EXPR, type, expr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
691 expr = fold_build1 (CONVERT_EXPR,
55
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
692 lang_hooks.types.type_for_size
77e2b8dfacca update it from 4.4.3 to 4.5.0
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 19
diff changeset
693 (TYPE_PRECISION (intype), 0),
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
694 expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
695 return fold_convert (type, expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
696
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
697 case INTEGER_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
698 case ENUMERAL_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
699 case BOOLEAN_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
700 case OFFSET_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
701 /* If this is a logical operation, which just returns 0 or 1, we can
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
702 change the type of the expression. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
703
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
704 if (TREE_CODE_CLASS (ex_form) == tcc_comparison)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
705 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
706 expr = copy_node (expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
707 TREE_TYPE (expr) = type;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
708 return expr;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
709 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
710
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
711 /* If we are widening the type, put in an explicit conversion.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
712 Similarly if we are not changing the width. After this, we know
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 we are truncating EXPR. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
714
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
715 else if (outprec >= inprec)
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 enum tree_code code;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
718
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 /* If the precision of the EXPR's type is K bits and the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 destination mode has more bits, and the sign is changing,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
721 it is not safe to use a NOP_EXPR. For example, suppose
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 that EXPR's type is a 3-bit unsigned integer type, the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 TYPE is a 3-bit signed integer type, and the machine mode
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 for the types is 8-bit QImode. In that case, the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 conversion necessitates an explicit sign-extension. In
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 the signed-to-unsigned case the high-order bits have to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 be cleared. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 if (TYPE_UNSIGNED (type) != TYPE_UNSIGNED (TREE_TYPE (expr))
111
kono
parents: 67
diff changeset
729 && !type_has_mode_precision_p (TREE_TYPE (expr)))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 code = CONVERT_EXPR;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 code = NOP_EXPR;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
733
111
kono
parents: 67
diff changeset
734 return maybe_fold_build1_loc (dofold, loc, code, type, expr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
735 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
736
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
737 /* If TYPE is an enumeral type or a type with a precision less
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
738 than the number of bits in its mode, do the conversion to the
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
739 type corresponding to its mode, then do a nop conversion
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
740 to TYPE. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
741 else if (TREE_CODE (type) == ENUMERAL_TYPE
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
742 || maybe_ne (outprec, GET_MODE_PRECISION (TYPE_MODE (type))))
111
kono
parents: 67
diff changeset
743 {
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
744 expr
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
745 = convert_to_integer_1 (lang_hooks.types.type_for_mode
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
746 (TYPE_MODE (type), TYPE_UNSIGNED (type)),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
747 expr, dofold);
111
kono
parents: 67
diff changeset
748 return maybe_fold_build1_loc (dofold, loc, NOP_EXPR, type, expr);
kono
parents: 67
diff changeset
749 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
750
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
751 /* Here detect when we can distribute the truncation down past some
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
752 arithmetic. For example, if adding two longs and converting to an
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
753 int, we can equally well convert both to ints and then add.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
754 For the operations handled here, such truncation distribution
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
755 is always safe.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
756 It is desirable in these cases:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
757 1) when truncating down to full-word from a larger size
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
758 2) when truncating takes no work.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
759 3) when at least one operand of the arithmetic has been extended
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
760 (as by C's default conversions). In this case we need two conversions
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
761 if we do the arithmetic as already requested, so we might as well
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
762 truncate both and then combine. Perhaps that way we need only one.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
763
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
764 Note that in general we cannot do the arithmetic in a type
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
765 shorter than the desired result of conversion, even if the operands
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
766 are both extended from a shorter type, because they might overflow
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
767 if combined in that type. The exceptions to this--the times when
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
768 two narrow values can be combined in their narrow type even to
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
769 make a wider result--are handled by "shorten" in build_binary_op. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
770
111
kono
parents: 67
diff changeset
771 if (dofold)
kono
parents: 67
diff changeset
772 switch (ex_form)
kono
parents: 67
diff changeset
773 {
kono
parents: 67
diff changeset
774 case RSHIFT_EXPR:
kono
parents: 67
diff changeset
775 /* We can pass truncation down through right shifting
kono
parents: 67
diff changeset
776 when the shift count is a nonpositive constant. */
kono
parents: 67
diff changeset
777 if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
kono
parents: 67
diff changeset
778 && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) <= 0)
kono
parents: 67
diff changeset
779 goto trunc1;
kono
parents: 67
diff changeset
780 break;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
781
111
kono
parents: 67
diff changeset
782 case LSHIFT_EXPR:
kono
parents: 67
diff changeset
783 /* We can pass truncation down through left shifting
kono
parents: 67
diff changeset
784 when the shift count is a nonnegative constant and
kono
parents: 67
diff changeset
785 the target type is unsigned. */
kono
parents: 67
diff changeset
786 if (TREE_CODE (TREE_OPERAND (expr, 1)) == INTEGER_CST
kono
parents: 67
diff changeset
787 && tree_int_cst_sgn (TREE_OPERAND (expr, 1)) >= 0
kono
parents: 67
diff changeset
788 && TYPE_UNSIGNED (type)
kono
parents: 67
diff changeset
789 && TREE_CODE (TYPE_SIZE (type)) == INTEGER_CST)
kono
parents: 67
diff changeset
790 {
kono
parents: 67
diff changeset
791 /* If shift count is less than the width of the truncated type,
kono
parents: 67
diff changeset
792 really shift. */
kono
parents: 67
diff changeset
793 if (tree_int_cst_lt (TREE_OPERAND (expr, 1), TYPE_SIZE (type)))
kono
parents: 67
diff changeset
794 /* In this case, shifting is like multiplication. */
kono
parents: 67
diff changeset
795 goto trunc1;
kono
parents: 67
diff changeset
796 else
kono
parents: 67
diff changeset
797 {
kono
parents: 67
diff changeset
798 /* If it is >= that width, result is zero.
kono
parents: 67
diff changeset
799 Handling this with trunc1 would give the wrong result:
kono
parents: 67
diff changeset
800 (int) ((long long) a << 32) is well defined (as 0)
kono
parents: 67
diff changeset
801 but (int) a << 32 is undefined and would get a
kono
parents: 67
diff changeset
802 warning. */
kono
parents: 67
diff changeset
803
kono
parents: 67
diff changeset
804 tree t = build_int_cst (type, 0);
kono
parents: 67
diff changeset
805
kono
parents: 67
diff changeset
806 /* If the original expression had side-effects, we must
kono
parents: 67
diff changeset
807 preserve it. */
kono
parents: 67
diff changeset
808 if (TREE_SIDE_EFFECTS (expr))
kono
parents: 67
diff changeset
809 return build2 (COMPOUND_EXPR, type, expr, t);
kono
parents: 67
diff changeset
810 else
kono
parents: 67
diff changeset
811 return t;
kono
parents: 67
diff changeset
812 }
kono
parents: 67
diff changeset
813 }
kono
parents: 67
diff changeset
814 break;
kono
parents: 67
diff changeset
815
kono
parents: 67
diff changeset
816 case TRUNC_DIV_EXPR:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
817 {
111
kono
parents: 67
diff changeset
818 tree arg0 = get_unwidened (TREE_OPERAND (expr, 0), NULL_TREE);
kono
parents: 67
diff changeset
819 tree arg1 = get_unwidened (TREE_OPERAND (expr, 1), NULL_TREE);
kono
parents: 67
diff changeset
820
kono
parents: 67
diff changeset
821 /* Don't distribute unless the output precision is at least as
kono
parents: 67
diff changeset
822 big as the actual inputs and it has the same signedness. */
kono
parents: 67
diff changeset
823 if (outprec >= TYPE_PRECISION (TREE_TYPE (arg0))
kono
parents: 67
diff changeset
824 && outprec >= TYPE_PRECISION (TREE_TYPE (arg1))
kono
parents: 67
diff changeset
825 /* If signedness of arg0 and arg1 don't match,
kono
parents: 67
diff changeset
826 we can't necessarily find a type to compare them in. */
kono
parents: 67
diff changeset
827 && (TYPE_UNSIGNED (TREE_TYPE (arg0))
kono
parents: 67
diff changeset
828 == TYPE_UNSIGNED (TREE_TYPE (arg1)))
kono
parents: 67
diff changeset
829 /* Do not change the sign of the division. */
kono
parents: 67
diff changeset
830 && (TYPE_UNSIGNED (TREE_TYPE (expr))
kono
parents: 67
diff changeset
831 == TYPE_UNSIGNED (TREE_TYPE (arg0)))
kono
parents: 67
diff changeset
832 /* Either require unsigned division or a division by
kono
parents: 67
diff changeset
833 a constant that is not -1. */
kono
parents: 67
diff changeset
834 && (TYPE_UNSIGNED (TREE_TYPE (arg0))
kono
parents: 67
diff changeset
835 || (TREE_CODE (arg1) == INTEGER_CST
kono
parents: 67
diff changeset
836 && !integer_all_onesp (arg1))))
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
837 {
111
kono
parents: 67
diff changeset
838 tree tem = do_narrow (loc, ex_form, type, arg0, arg1,
kono
parents: 67
diff changeset
839 expr, inprec, outprec, dofold);
kono
parents: 67
diff changeset
840 if (tem)
kono
parents: 67
diff changeset
841 return tem;
kono
parents: 67
diff changeset
842 }
kono
parents: 67
diff changeset
843 break;
kono
parents: 67
diff changeset
844 }
kono
parents: 67
diff changeset
845
kono
parents: 67
diff changeset
846 case MAX_EXPR:
kono
parents: 67
diff changeset
847 case MIN_EXPR:
kono
parents: 67
diff changeset
848 case MULT_EXPR:
kono
parents: 67
diff changeset
849 {
kono
parents: 67
diff changeset
850 tree arg0 = get_unwidened (TREE_OPERAND (expr, 0), type);
kono
parents: 67
diff changeset
851 tree arg1 = get_unwidened (TREE_OPERAND (expr, 1), type);
kono
parents: 67
diff changeset
852
kono
parents: 67
diff changeset
853 /* Don't distribute unless the output precision is at least as
kono
parents: 67
diff changeset
854 big as the actual inputs. Otherwise, the comparison of the
kono
parents: 67
diff changeset
855 truncated values will be wrong. */
kono
parents: 67
diff changeset
856 if (outprec >= TYPE_PRECISION (TREE_TYPE (arg0))
kono
parents: 67
diff changeset
857 && outprec >= TYPE_PRECISION (TREE_TYPE (arg1))
kono
parents: 67
diff changeset
858 /* If signedness of arg0 and arg1 don't match,
kono
parents: 67
diff changeset
859 we can't necessarily find a type to compare them in. */
kono
parents: 67
diff changeset
860 && (TYPE_UNSIGNED (TREE_TYPE (arg0))
kono
parents: 67
diff changeset
861 == TYPE_UNSIGNED (TREE_TYPE (arg1))))
kono
parents: 67
diff changeset
862 goto trunc1;
kono
parents: 67
diff changeset
863 break;
kono
parents: 67
diff changeset
864 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
865
111
kono
parents: 67
diff changeset
866 case PLUS_EXPR:
kono
parents: 67
diff changeset
867 case MINUS_EXPR:
kono
parents: 67
diff changeset
868 case BIT_AND_EXPR:
kono
parents: 67
diff changeset
869 case BIT_IOR_EXPR:
kono
parents: 67
diff changeset
870 case BIT_XOR_EXPR:
kono
parents: 67
diff changeset
871 trunc1:
kono
parents: 67
diff changeset
872 {
kono
parents: 67
diff changeset
873 tree arg0 = get_unwidened (TREE_OPERAND (expr, 0), type);
kono
parents: 67
diff changeset
874 tree arg1 = get_unwidened (TREE_OPERAND (expr, 1), type);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
875
111
kono
parents: 67
diff changeset
876 /* Do not try to narrow operands of pointer subtraction;
kono
parents: 67
diff changeset
877 that will interfere with other folding. */
kono
parents: 67
diff changeset
878 if (ex_form == MINUS_EXPR
kono
parents: 67
diff changeset
879 && CONVERT_EXPR_P (arg0)
kono
parents: 67
diff changeset
880 && CONVERT_EXPR_P (arg1)
kono
parents: 67
diff changeset
881 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (arg0, 0)))
kono
parents: 67
diff changeset
882 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (arg1, 0))))
kono
parents: 67
diff changeset
883 break;
kono
parents: 67
diff changeset
884
kono
parents: 67
diff changeset
885 if (outprec >= BITS_PER_WORD
kono
parents: 67
diff changeset
886 || targetm.truly_noop_truncation (outprec, inprec)
kono
parents: 67
diff changeset
887 || inprec > TYPE_PRECISION (TREE_TYPE (arg0))
kono
parents: 67
diff changeset
888 || inprec > TYPE_PRECISION (TREE_TYPE (arg1)))
kono
parents: 67
diff changeset
889 {
kono
parents: 67
diff changeset
890 tree tem = do_narrow (loc, ex_form, type, arg0, arg1,
kono
parents: 67
diff changeset
891 expr, inprec, outprec, dofold);
kono
parents: 67
diff changeset
892 if (tem)
kono
parents: 67
diff changeset
893 return tem;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
894 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
895 }
111
kono
parents: 67
diff changeset
896 break;
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
897
111
kono
parents: 67
diff changeset
898 case NEGATE_EXPR:
kono
parents: 67
diff changeset
899 /* Using unsigned arithmetic for signed types may hide overflow
kono
parents: 67
diff changeset
900 bugs. */
kono
parents: 67
diff changeset
901 if (!TYPE_UNSIGNED (TREE_TYPE (TREE_OPERAND (expr, 0)))
kono
parents: 67
diff changeset
902 && sanitize_flags_p (SANITIZE_SI_OVERFLOW))
kono
parents: 67
diff changeset
903 break;
kono
parents: 67
diff changeset
904 /* Fall through. */
kono
parents: 67
diff changeset
905 case BIT_NOT_EXPR:
kono
parents: 67
diff changeset
906 /* This is not correct for ABS_EXPR,
kono
parents: 67
diff changeset
907 since we must test the sign before truncation. */
kono
parents: 67
diff changeset
908 {
kono
parents: 67
diff changeset
909 /* Do the arithmetic in type TYPEX,
kono
parents: 67
diff changeset
910 then convert result to TYPE. */
kono
parents: 67
diff changeset
911 tree typex = type;
kono
parents: 67
diff changeset
912
kono
parents: 67
diff changeset
913 /* Can't do arithmetic in enumeral types
kono
parents: 67
diff changeset
914 so use an integer type that will hold the values. */
kono
parents: 67
diff changeset
915 if (TREE_CODE (typex) == ENUMERAL_TYPE)
kono
parents: 67
diff changeset
916 typex
kono
parents: 67
diff changeset
917 = lang_hooks.types.type_for_size (TYPE_PRECISION (typex),
kono
parents: 67
diff changeset
918 TYPE_UNSIGNED (typex));
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
919
111
kono
parents: 67
diff changeset
920 if (!TYPE_UNSIGNED (typex))
kono
parents: 67
diff changeset
921 typex = unsigned_type_for (typex);
kono
parents: 67
diff changeset
922 return convert (type,
kono
parents: 67
diff changeset
923 fold_build1 (ex_form, typex,
kono
parents: 67
diff changeset
924 convert (typex,
kono
parents: 67
diff changeset
925 TREE_OPERAND (expr, 0))));
kono
parents: 67
diff changeset
926 }
63
b7f97abdc517 update gcc from gcc-4.5.0 to gcc-4.6
ryoma <e075725@ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
927
111
kono
parents: 67
diff changeset
928 CASE_CONVERT:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
929 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
930 tree argtype = TREE_TYPE (TREE_OPERAND (expr, 0));
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
931 /* Don't introduce a "can't convert between vector values
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
932 of different size" error. */
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
933 if (TREE_CODE (argtype) == VECTOR_TYPE
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
934 && maybe_ne (GET_MODE_SIZE (TYPE_MODE (argtype)),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
935 GET_MODE_SIZE (TYPE_MODE (type))))
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
936 break;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
937 }
111
kono
parents: 67
diff changeset
938 /* If truncating after truncating, might as well do all at once.
kono
parents: 67
diff changeset
939 If truncating after extending, we may get rid of wasted work. */
kono
parents: 67
diff changeset
940 return convert (type, get_unwidened (TREE_OPERAND (expr, 0), type));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
941
111
kono
parents: 67
diff changeset
942 case COND_EXPR:
kono
parents: 67
diff changeset
943 /* It is sometimes worthwhile to push the narrowing down through
kono
parents: 67
diff changeset
944 the conditional and never loses. A COND_EXPR may have a throw
kono
parents: 67
diff changeset
945 as one operand, which then has void type. Just leave void
kono
parents: 67
diff changeset
946 operands as they are. */
kono
parents: 67
diff changeset
947 return
kono
parents: 67
diff changeset
948 fold_build3 (COND_EXPR, type, TREE_OPERAND (expr, 0),
kono
parents: 67
diff changeset
949 VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 1)))
kono
parents: 67
diff changeset
950 ? TREE_OPERAND (expr, 1)
kono
parents: 67
diff changeset
951 : convert (type, TREE_OPERAND (expr, 1)),
kono
parents: 67
diff changeset
952 VOID_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 2)))
kono
parents: 67
diff changeset
953 ? TREE_OPERAND (expr, 2)
kono
parents: 67
diff changeset
954 : convert (type, TREE_OPERAND (expr, 2)));
kono
parents: 67
diff changeset
955
kono
parents: 67
diff changeset
956 default:
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
957 break;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
958 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
959
111
kono
parents: 67
diff changeset
960 /* When parsing long initializers, we might end up with a lot of casts.
kono
parents: 67
diff changeset
961 Shortcut this. */
kono
parents: 67
diff changeset
962 if (TREE_CODE (expr) == INTEGER_CST)
kono
parents: 67
diff changeset
963 return fold_convert (type, expr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
964 return build1 (CONVERT_EXPR, type, expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
965
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
966 case REAL_TYPE:
111
kono
parents: 67
diff changeset
967 if (sanitize_flags_p (SANITIZE_FLOAT_CAST)
kono
parents: 67
diff changeset
968 && current_function_decl != NULL_TREE)
kono
parents: 67
diff changeset
969 {
kono
parents: 67
diff changeset
970 expr = save_expr (expr);
kono
parents: 67
diff changeset
971 tree check = ubsan_instrument_float_cast (loc, type, expr);
kono
parents: 67
diff changeset
972 expr = build1 (FIX_TRUNC_EXPR, type, expr);
kono
parents: 67
diff changeset
973 if (check == NULL_TREE)
kono
parents: 67
diff changeset
974 return expr;
kono
parents: 67
diff changeset
975 return maybe_fold_build2_loc (dofold, loc, COMPOUND_EXPR,
kono
parents: 67
diff changeset
976 TREE_TYPE (expr), check, expr);
kono
parents: 67
diff changeset
977 }
kono
parents: 67
diff changeset
978 else
kono
parents: 67
diff changeset
979 return build1 (FIX_TRUNC_EXPR, type, expr);
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 case FIXED_POINT_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
982 return build1 (FIXED_CONVERT_EXPR, type, expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
983
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
984 case COMPLEX_TYPE:
111
kono
parents: 67
diff changeset
985 expr = maybe_fold_build1_loc (dofold, loc, REALPART_EXPR,
kono
parents: 67
diff changeset
986 TREE_TYPE (TREE_TYPE (expr)), expr);
kono
parents: 67
diff changeset
987 return convert (type, expr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
988
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
989 case VECTOR_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
990 if (!tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (expr))))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
991 {
111
kono
parents: 67
diff changeset
992 error ("can%'t convert a vector of type %qT"
kono
parents: 67
diff changeset
993 " to type %qT which has different size",
kono
parents: 67
diff changeset
994 TREE_TYPE (expr), type);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
995 return error_mark_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
996 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
997 return build1 (VIEW_CONVERT_EXPR, type, expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
998
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
999 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1000 error ("aggregate value used where an integer was expected");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1001 return convert (type, integer_zero_node);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1002 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1003 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1004
111
kono
parents: 67
diff changeset
1005 /* Convert EXPR to some integer (or enum) type TYPE.
kono
parents: 67
diff changeset
1006
kono
parents: 67
diff changeset
1007 EXPR must be pointer, integer, discrete (enum, char, or bool), float,
kono
parents: 67
diff changeset
1008 fixed-point or vector; in other cases error is called.
kono
parents: 67
diff changeset
1009
kono
parents: 67
diff changeset
1010 The result of this is always supposed to be a newly created tree node
kono
parents: 67
diff changeset
1011 not in use in any existing structure. */
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1012
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1013 tree
111
kono
parents: 67
diff changeset
1014 convert_to_integer (tree type, tree expr)
kono
parents: 67
diff changeset
1015 {
kono
parents: 67
diff changeset
1016 return convert_to_integer_1 (type, expr, true);
kono
parents: 67
diff changeset
1017 }
kono
parents: 67
diff changeset
1018
kono
parents: 67
diff changeset
1019 /* A wrapper around convert_to_complex_1 that only folds the
kono
parents: 67
diff changeset
1020 expression if DOFOLD, or if it is CONSTANT_CLASS_P. */
kono
parents: 67
diff changeset
1021
kono
parents: 67
diff changeset
1022 tree
kono
parents: 67
diff changeset
1023 convert_to_integer_maybe_fold (tree type, tree expr, bool dofold)
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1024 {
111
kono
parents: 67
diff changeset
1025 return convert_to_integer_1 (type, expr, dofold || CONSTANT_CLASS_P (expr));
kono
parents: 67
diff changeset
1026 }
kono
parents: 67
diff changeset
1027
kono
parents: 67
diff changeset
1028 /* Convert EXPR to the complex type TYPE in the usual ways. If FOLD_P is
kono
parents: 67
diff changeset
1029 true, try to fold the expression. */
kono
parents: 67
diff changeset
1030
kono
parents: 67
diff changeset
1031 static tree
kono
parents: 67
diff changeset
1032 convert_to_complex_1 (tree type, tree expr, bool fold_p)
kono
parents: 67
diff changeset
1033 {
kono
parents: 67
diff changeset
1034 location_t loc = EXPR_LOCATION (expr);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1035 tree subtype = TREE_TYPE (type);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1036
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1037 switch (TREE_CODE (TREE_TYPE (expr)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1038 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1039 case REAL_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1040 case FIXED_POINT_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1041 case INTEGER_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1042 case ENUMERAL_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1043 case BOOLEAN_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1044 return build2 (COMPLEX_EXPR, type, convert (subtype, expr),
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1045 convert (subtype, integer_zero_node));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1046
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1047 case COMPLEX_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1048 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1049 tree elt_type = TREE_TYPE (TREE_TYPE (expr));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1050
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1051 if (TYPE_MAIN_VARIANT (elt_type) == TYPE_MAIN_VARIANT (subtype))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1052 return expr;
111
kono
parents: 67
diff changeset
1053 else if (TREE_CODE (expr) == COMPOUND_EXPR)
kono
parents: 67
diff changeset
1054 {
kono
parents: 67
diff changeset
1055 tree t = convert_to_complex_1 (type, TREE_OPERAND (expr, 1),
kono
parents: 67
diff changeset
1056 fold_p);
kono
parents: 67
diff changeset
1057 if (t == TREE_OPERAND (expr, 1))
kono
parents: 67
diff changeset
1058 return expr;
kono
parents: 67
diff changeset
1059 return build2_loc (EXPR_LOCATION (expr), COMPOUND_EXPR,
kono
parents: 67
diff changeset
1060 TREE_TYPE (t), TREE_OPERAND (expr, 0), t);
kono
parents: 67
diff changeset
1061 }
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1062 else if (TREE_CODE (expr) == COMPLEX_EXPR)
111
kono
parents: 67
diff changeset
1063 return maybe_fold_build2_loc (fold_p, loc, COMPLEX_EXPR, type,
kono
parents: 67
diff changeset
1064 convert (subtype,
kono
parents: 67
diff changeset
1065 TREE_OPERAND (expr, 0)),
kono
parents: 67
diff changeset
1066 convert (subtype,
kono
parents: 67
diff changeset
1067 TREE_OPERAND (expr, 1)));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1068 else
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1069 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1070 expr = save_expr (expr);
111
kono
parents: 67
diff changeset
1071 tree realp = maybe_fold_build1_loc (fold_p, loc, REALPART_EXPR,
kono
parents: 67
diff changeset
1072 TREE_TYPE (TREE_TYPE (expr)),
kono
parents: 67
diff changeset
1073 expr);
kono
parents: 67
diff changeset
1074 tree imagp = maybe_fold_build1_loc (fold_p, loc, IMAGPART_EXPR,
kono
parents: 67
diff changeset
1075 TREE_TYPE (TREE_TYPE (expr)),
kono
parents: 67
diff changeset
1076 expr);
kono
parents: 67
diff changeset
1077 return maybe_fold_build2_loc (fold_p, loc, COMPLEX_EXPR, type,
kono
parents: 67
diff changeset
1078 convert (subtype, realp),
kono
parents: 67
diff changeset
1079 convert (subtype, imagp));
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1080 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1081 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1082
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1083 case POINTER_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1084 case REFERENCE_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1085 error ("pointer value used where a complex was expected");
111
kono
parents: 67
diff changeset
1086 return convert_to_complex_1 (type, integer_zero_node, fold_p);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1087
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1088 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1089 error ("aggregate value used where a complex was expected");
111
kono
parents: 67
diff changeset
1090 return convert_to_complex_1 (type, integer_zero_node, fold_p);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1091 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1092 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1093
111
kono
parents: 67
diff changeset
1094 /* A wrapper around convert_to_complex_1 that always folds the
kono
parents: 67
diff changeset
1095 expression. */
kono
parents: 67
diff changeset
1096
kono
parents: 67
diff changeset
1097 tree
kono
parents: 67
diff changeset
1098 convert_to_complex (tree type, tree expr)
kono
parents: 67
diff changeset
1099 {
kono
parents: 67
diff changeset
1100 return convert_to_complex_1 (type, expr, true);
kono
parents: 67
diff changeset
1101 }
kono
parents: 67
diff changeset
1102
kono
parents: 67
diff changeset
1103 /* A wrapper around convert_to_complex_1 that only folds the
kono
parents: 67
diff changeset
1104 expression if DOFOLD, or if it is CONSTANT_CLASS_P. */
kono
parents: 67
diff changeset
1105
kono
parents: 67
diff changeset
1106 tree
kono
parents: 67
diff changeset
1107 convert_to_complex_maybe_fold (tree type, tree expr, bool dofold)
kono
parents: 67
diff changeset
1108 {
kono
parents: 67
diff changeset
1109 return convert_to_complex_1 (type, expr, dofold || CONSTANT_CLASS_P (expr));
kono
parents: 67
diff changeset
1110 }
kono
parents: 67
diff changeset
1111
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1112 /* Convert EXPR to the vector type TYPE in the usual ways. */
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1113
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1114 tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1115 convert_to_vector (tree type, tree expr)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1116 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1117 switch (TREE_CODE (TREE_TYPE (expr)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1118 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1119 case INTEGER_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1120 case VECTOR_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1121 if (!tree_int_cst_equal (TYPE_SIZE (type), TYPE_SIZE (TREE_TYPE (expr))))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1122 {
111
kono
parents: 67
diff changeset
1123 error ("can%'t convert a value of type %qT"
kono
parents: 67
diff changeset
1124 " to vector type %qT which has different size",
kono
parents: 67
diff changeset
1125 TREE_TYPE (expr), type);
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1126 return error_mark_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1127 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1128 return build1 (VIEW_CONVERT_EXPR, type, expr);
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 default:
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
1131 error ("can%'t convert value to a vector");
0
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1132 return error_mark_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1133 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1134 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1135
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1136 /* Convert EXPR to some fixed-point type TYPE.
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1137
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1138 EXPR must be fixed-point, float, integer, or enumeral;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1139 in other cases error is called. */
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 tree
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1142 convert_to_fixed (tree type, tree expr)
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1143 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1144 if (integer_zerop (expr))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1145 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1146 tree fixed_zero_node = build_fixed (type, FCONST0 (TYPE_MODE (type)));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1147 return fixed_zero_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1148 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1149 else if (integer_onep (expr) && ALL_SCALAR_ACCUM_MODE_P (TYPE_MODE (type)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1150 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1151 tree fixed_one_node = build_fixed (type, FCONST1 (TYPE_MODE (type)));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1152 return fixed_one_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1153 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1154
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1155 switch (TREE_CODE (TREE_TYPE (expr)))
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1156 {
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1157 case FIXED_POINT_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1158 case INTEGER_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1159 case ENUMERAL_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1160 case BOOLEAN_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1161 case REAL_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1162 return build1 (FIXED_CONVERT_EXPR, type, expr);
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1163
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1164 case COMPLEX_TYPE:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1165 return convert (type,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1166 fold_build1 (REALPART_EXPR,
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1167 TREE_TYPE (TREE_TYPE (expr)), expr));
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1168
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1169 default:
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1170 error ("aggregate value used where a fixed-point was expected");
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1171 return error_mark_node;
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1172 }
a06113de4d67 first commit
kent <kent@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1173 }