comparison gcc/tree-call-cdce.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents a06113de4d67
children b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
2 Copyright (C) 2008 2 Copyright (C) 2008
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 Contributed by Xinliang David Li <davidxl@google.com> 4 Contributed by Xinliang David Li <davidxl@google.com>
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify it 8 GCC is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the 9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3, or (at your option) any 10 Free Software Foundation; either version 3, or (at your option) any
11 later version. 11 later version.
12 12
13 GCC is distributed in the hope that it will be useful, but WITHOUT 13 GCC is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details. 16 for more details.
17 17
18 You should have received a copy of the GNU General Public License 18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see 19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */ 20 <http://www.gnu.org/licenses/>. */
21 21
22 #include "config.h" 22 #include "config.h"
47 Some builtin functions can set errno on error conditions, but they 47 Some builtin functions can set errno on error conditions, but they
48 are otherwise pure. If the result of a call to such a function is 48 are otherwise pure. If the result of a call to such a function is
49 not used, the compiler can still not eliminate the call without 49 not used, the compiler can still not eliminate the call without
50 powerful interprocedural analysis to prove that the errno is not 50 powerful interprocedural analysis to prove that the errno is not
51 checked. However, if the conditions under which the error occurs 51 checked. However, if the conditions under which the error occurs
52 are known, the compiler can conditionally dead code eliminate the 52 are known, the compiler can conditionally dead code eliminate the
53 calls by shrink-wrapping the semi-dead calls into the error condition: 53 calls by shrink-wrapping the semi-dead calls into the error condition:
54 54
55 built_in_call (args) 55 built_in_call (args)
56 ==> 56 ==>
57 if (error_cond (args)) 57 if (error_cond (args))
63 if (x < 0) 63 if (x < 0)
64 log (x); 64 log (x);
65 With this change, call to log (x) is effectively eliminated, as 65 With this change, call to log (x) is effectively eliminated, as
66 in majority of the cases, log won't be called with x out of 66 in majority of the cases, log won't be called with x out of
67 range. The branch is totally predictable, so the branch cost 67 range. The branch is totally predictable, so the branch cost
68 is low. 68 is low.
69 69
70 Note that library functions are not supposed to clear errno to zero without 70 Note that library functions are not supposed to clear errno to zero without
71 error. See IEEE Std 1003.1, section 2.3 Error Numbers, and section 7.5:3 of 71 error. See IEEE Std 1003.1, section 2.3 Error Numbers, and section 7.5:3 of
72 ISO/IEC 9899 (C99). 72 ISO/IEC 9899 (C99).
73 73
79 condition is hit is very low (those builtin calls which are conditionally 79 condition is hit is very low (those builtin calls which are conditionally
80 dead are usually part of the C++ abstraction penalty exposed after 80 dead are usually part of the C++ abstraction penalty exposed after
81 inlining). */ 81 inlining). */
82 82
83 83
84 /* A structure for representing input domain of 84 /* A structure for representing input domain of
85 a function argument in integer. If the lower 85 a function argument in integer. If the lower
86 bound is -inf, has_lb is set to false. If the 86 bound is -inf, has_lb is set to false. If the
87 upper bound is +inf, has_ub is false. 87 upper bound is +inf, has_ub is false.
88 is_lb_inclusive and is_ub_inclusive are flags 88 is_lb_inclusive and is_ub_inclusive are flags
89 to indicate if lb and ub value are inclusive 89 to indicate if lb and ub value are inclusive
90 respectively. */ 90 respectively. */
91 91
92 typedef struct input_domain 92 typedef struct input_domain
93 { 93 {
94 int lb; 94 int lb;
98 bool is_lb_inclusive; 98 bool is_lb_inclusive;
99 bool is_ub_inclusive; 99 bool is_ub_inclusive;
100 } inp_domain; 100 } inp_domain;
101 101
102 /* A helper function to construct and return an input 102 /* A helper function to construct and return an input
103 domain object. LB is the lower bound, HAS_LB is 103 domain object. LB is the lower bound, HAS_LB is
104 a boolean flag indicating if the lower bound exists, 104 a boolean flag indicating if the lower bound exists,
105 and LB_INCLUSIVE is a boolean flag indicating if the 105 and LB_INCLUSIVE is a boolean flag indicating if the
106 lower bound is inclusive or not. UB, HAS_UB, and 106 lower bound is inclusive or not. UB, HAS_UB, and
107 UB_INCLUSIVE have the same meaning, but for upper 107 UB_INCLUSIVE have the same meaning, but for upper
108 bound of the domain. */ 108 bound of the domain. */
109 109
110 static inp_domain 110 static inp_domain
111 get_domain (int lb, bool has_lb, bool lb_inclusive, 111 get_domain (int lb, bool has_lb, bool lb_inclusive,
112 int ub, bool has_ub, bool ub_inclusive) 112 int ub, bool has_ub, bool ub_inclusive)
119 domain.has_ub = has_ub; 119 domain.has_ub = has_ub;
120 domain.is_ub_inclusive = ub_inclusive; 120 domain.is_ub_inclusive = ub_inclusive;
121 return domain; 121 return domain;
122 } 122 }
123 123
124 /* A helper function to check the target format for the 124 /* A helper function to check the target format for the
125 argument type. In this implementation, only IEEE formats 125 argument type. In this implementation, only IEEE formats
126 are supported. ARG is the call argument to be checked. 126 are supported. ARG is the call argument to be checked.
127 Returns true if the format is supported. To support other 127 Returns true if the format is supported. To support other
128 target formats, function get_no_error_domain needs to be 128 target formats, function get_no_error_domain needs to be
129 enhanced to have range bounds properly computed. Since 129 enhanced to have range bounds properly computed. Since
130 the check is cheap (very small number of candidates 130 the check is cheap (very small number of candidates
131 to be checked), the result is not cached for each float type. */ 131 to be checked), the result is not cached for each float type. */
132 132
133 static bool 133 static bool
134 check_target_format (tree arg) 134 check_target_format (tree arg)
135 { 135 {
136 tree type; 136 tree type;
137 enum machine_mode mode; 137 enum machine_mode mode;
138 const struct real_format *rfmt; 138 const struct real_format *rfmt;
139 139
140 type = TREE_TYPE (arg); 140 type = TREE_TYPE (arg);
141 mode = TYPE_MODE (type); 141 mode = TYPE_MODE (type);
142 rfmt = REAL_MODE_FORMAT (mode); 142 rfmt = REAL_MODE_FORMAT (mode);
143 if ((mode == SFmode 143 if ((mode == SFmode
144 && (rfmt == &ieee_single_format || rfmt == &mips_single_format 144 && (rfmt == &ieee_single_format || rfmt == &mips_single_format
145 || rfmt == &motorola_single_format)) 145 || rfmt == &motorola_single_format))
146 || (mode == DFmode 146 || (mode == DFmode
147 && (rfmt == &ieee_double_format || rfmt == &mips_double_format 147 && (rfmt == &ieee_double_format || rfmt == &mips_double_format
148 || rfmt == &motorola_double_format)) 148 || rfmt == &motorola_double_format))
149 /* For long double, we can not really check XFmode 149 /* For long double, we can not really check XFmode
150 which is only defined on intel platforms. 150 which is only defined on intel platforms.
151 Candidate pre-selection using builtin function 151 Candidate pre-selection using builtin function
152 code guarantees that we are checking formats 152 code guarantees that we are checking formats
153 for long double modes: double, quad, and extended. */ 153 for long double modes: double, quad, and extended. */
154 || (mode != SFmode && mode != DFmode 154 || (mode != SFmode && mode != DFmode
155 && (rfmt == &ieee_quad_format 155 && (rfmt == &ieee_quad_format
156 || rfmt == &mips_quad_format 156 || rfmt == &mips_quad_format
157 || rfmt == &ieee_extended_motorola_format 157 || rfmt == &ieee_extended_motorola_format
158 || rfmt == &ieee_extended_intel_96_format 158 || rfmt == &ieee_extended_intel_96_format
159 || rfmt == &ieee_extended_intel_128_format 159 || rfmt == &ieee_extended_intel_128_format
160 || rfmt == &ieee_extended_intel_96_round_53_format))) 160 || rfmt == &ieee_extended_intel_96_round_53_format)))
161 return true; 161 return true;
162 162
163 return false; 163 return false;
164 } 164 }
165 165
166 166
167 /* A helper function to help select calls to pow that are suitable for 167 /* A helper function to help select calls to pow that are suitable for
168 conditional DCE transformation. It looks for pow calls that can be 168 conditional DCE transformation. It looks for pow calls that can be
169 guided with simple conditions. Such calls either have constant base 169 guided with simple conditions. Such calls either have constant base
170 values or base values converted from integers. Returns true if 170 values or base values converted from integers. Returns true if
171 the pow call POW_CALL is a candidate. */ 171 the pow call POW_CALL is a candidate. */
172 172
173 /* The maximum integer bit size for base argument of a pow call 173 /* The maximum integer bit size for base argument of a pow call
174 that is suitable for shrink-wrapping transformation. */ 174 that is suitable for shrink-wrapping transformation. */
175 #define MAX_BASE_INT_BIT_SIZE 32 175 #define MAX_BASE_INT_BIT_SIZE 32
216 tree base_val0, base_var, type; 216 tree base_val0, base_var, type;
217 gimple base_def; 217 gimple base_def;
218 int bit_sz; 218 int bit_sz;
219 219
220 /* Only handles cases where base value is converted 220 /* Only handles cases where base value is converted
221 from integer values. */ 221 from integer values. */
222 base_def = SSA_NAME_DEF_STMT (base); 222 base_def = SSA_NAME_DEF_STMT (base);
223 if (gimple_code (base_def) != GIMPLE_ASSIGN) 223 if (gimple_code (base_def) != GIMPLE_ASSIGN)
224 return false; 224 return false;
225 225
226 if (gimple_assign_rhs_code (base_def) != FLOAT_EXPR) 226 if (gimple_assign_rhs_code (base_def) != FLOAT_EXPR)
275 if (gimple_call_lhs (call)) 275 if (gimple_call_lhs (call))
276 return false; 276 return false;
277 277
278 fn = gimple_call_fndecl (call); 278 fn = gimple_call_fndecl (call);
279 if (!fn 279 if (!fn
280 || !DECL_BUILT_IN (fn) 280 || !DECL_BUILT_IN (fn)
281 || (DECL_BUILT_IN_CLASS (fn) != BUILT_IN_NORMAL)) 281 || (DECL_BUILT_IN_CLASS (fn) != BUILT_IN_NORMAL))
282 return false; 282 return false;
283 283
284 fnc = DECL_FUNCTION_CODE (fn); 284 fnc = DECL_FUNCTION_CODE (fn);
285 switch (fnc) 285 switch (fnc)
322 be compared with the bound, LBUB is the bound value 322 be compared with the bound, LBUB is the bound value
323 in integer, TCODE is the tree_code of the comparison, 323 in integer, TCODE is the tree_code of the comparison,
324 TEMP_NAME1/TEMP_NAME2 are names of the temporaries, 324 TEMP_NAME1/TEMP_NAME2 are names of the temporaries,
325 CONDS is a vector holding the produced GIMPLE statements, 325 CONDS is a vector holding the produced GIMPLE statements,
326 and NCONDS points to the variable holding the number 326 and NCONDS points to the variable holding the number
327 of logical comparisons. CONDS is either empty or 327 of logical comparisons. CONDS is either empty or
328 a list ended with a null tree. */ 328 a list ended with a null tree. */
329 329
330 static void 330 static void
331 gen_one_condition (tree arg, int lbub, 331 gen_one_condition (tree arg, int lbub,
332 enum tree_code tcode, 332 enum tree_code tcode,
333 const char *temp_name1, 333 const char *temp_name1,
334 const char *temp_name2, 334 const char *temp_name2,
335 VEC (gimple, heap) *conds, 335 VEC (gimple, heap) *conds,
336 unsigned *nconds) 336 unsigned *nconds)
365 365
366 /* A helper function to generate GIMPLE statements for 366 /* A helper function to generate GIMPLE statements for
367 out of input domain check. ARG is the call argument 367 out of input domain check. ARG is the call argument
368 to be runtime checked, DOMAIN holds the valid domain 368 to be runtime checked, DOMAIN holds the valid domain
369 for the given function, CONDS points to the vector 369 for the given function, CONDS points to the vector
370 holding the result GIMPLE statements. *NCONDS is 370 holding the result GIMPLE statements. *NCONDS is
371 the number of logical comparisons. This function 371 the number of logical comparisons. This function
372 produces no more than two logical comparisons, one 372 produces no more than two logical comparisons, one
373 for lower bound check, one for upper bound check. */ 373 for lower bound check, one for upper bound check. */
374 374
375 static void 375 static void
376 gen_conditions_for_domain (tree arg, inp_domain domain, 376 gen_conditions_for_domain (tree arg, inp_domain domain,
377 VEC (gimple, heap) *conds, 377 VEC (gimple, heap) *conds,
378 unsigned *nconds) 378 unsigned *nconds)
379 { 379 {
380 if (domain.has_lb) 380 if (domain.has_lb)
381 gen_one_condition (arg, domain.lb, 381 gen_one_condition (arg, domain.lb,
382 (domain.is_lb_inclusive 382 (domain.is_lb_inclusive
399 } 399 }
400 400
401 401
402 /* A helper function to generate condition 402 /* A helper function to generate condition
403 code for the y argument in call pow (some_const, y). 403 code for the y argument in call pow (some_const, y).
404 See candidate selection in check_pow. Since the 404 See candidate selection in check_pow. Since the
405 candidates' base values have a limited range, 405 candidates' base values have a limited range,
406 the guarded code generated for y are simple: 406 the guarded code generated for y are simple:
407 if (y > max_y) 407 if (y > max_y)
408 pow (const, y); 408 pow (const, y);
409 Note max_y can be computed separately for each 409 Note max_y can be computed separately for each
418 static void 418 static void
419 gen_conditions_for_pow_cst_base (tree base, tree expn, 419 gen_conditions_for_pow_cst_base (tree base, tree expn,
420 VEC (gimple, heap) *conds, 420 VEC (gimple, heap) *conds,
421 unsigned *nconds) 421 unsigned *nconds)
422 { 422 {
423 inp_domain exp_domain; 423 inp_domain exp_domain;
424 /* Validate the range of the base constant to make 424 /* Validate the range of the base constant to make
425 sure it is consistent with check_pow. */ 425 sure it is consistent with check_pow. */
426 REAL_VALUE_TYPE mv; 426 REAL_VALUE_TYPE mv;
427 REAL_VALUE_TYPE bcv = TREE_REAL_CST (base); 427 REAL_VALUE_TYPE bcv = TREE_REAL_CST (base);
428 gcc_assert (!REAL_VALUES_EQUAL (bcv, dconst1) 428 gcc_assert (!REAL_VALUES_EQUAL (bcv, dconst1)
429 && !REAL_VALUES_LESS (bcv, dconst1)); 429 && !REAL_VALUES_LESS (bcv, dconst1));
442 have their base argument value converted from 442 have their base argument value converted from
443 integer (see check_pow) value (1, 2, 4 bytes), and 443 integer (see check_pow) value (1, 2, 4 bytes), and
444 the max exp value is computed based on the size 444 the max exp value is computed based on the size
445 of the integer type (i.e. max possible base value). 445 of the integer type (i.e. max possible base value).
446 The resulting input domain for exp argument is thus 446 The resulting input domain for exp argument is thus
447 conservative (smaller than the max value allowed by 447 conservative (smaller than the max value allowed by
448 the runtime value of the base). BASE is the integer 448 the runtime value of the base). BASE is the integer
449 base value, EXPN is the expression for the exponent 449 base value, EXPN is the expression for the exponent
450 argument, *CONDS is the vector to hold resulting 450 argument, *CONDS is the vector to hold resulting
451 statements, and *NCONDS is the number of logical 451 statements, and *NCONDS is the number of logical
452 conditions. */ 452 conditions. */
453 453
454 static void 454 static void
455 gen_conditions_for_pow_int_base (tree base, tree expn, 455 gen_conditions_for_pow_int_base (tree base, tree expn,
456 VEC (gimple, heap) *conds, 456 VEC (gimple, heap) *conds,
457 unsigned *nconds) 457 unsigned *nconds)
458 { 458 {
459 gimple base_def; 459 gimple base_def;
460 tree base_nm, base_val0; 460 tree base_val0;
461 tree base_var, int_type; 461 tree base_var, int_type;
462 tree temp, tempn; 462 tree temp, tempn;
463 tree cst0; 463 tree cst0;
464 gimple stmt1, stmt2; 464 gimple stmt1, stmt2;
465 int bit_sz, max_exp; 465 int bit_sz, max_exp;
466 inp_domain exp_domain; 466 inp_domain exp_domain;
467 467
468 base_def = SSA_NAME_DEF_STMT (base); 468 base_def = SSA_NAME_DEF_STMT (base);
469 base_nm = gimple_assign_lhs (base_def);
470 base_val0 = gimple_assign_rhs1 (base_def); 469 base_val0 = gimple_assign_rhs1 (base_def);
471 base_var = SSA_NAME_VAR (base_val0); 470 base_var = SSA_NAME_VAR (base_val0);
472 int_type = TREE_TYPE (base_var); 471 int_type = TREE_TYPE (base_var);
473 bit_sz = TYPE_PRECISION (int_type); 472 bit_sz = TYPE_PRECISION (int_type);
474 gcc_assert (bit_sz > 0 473 gcc_assert (bit_sz > 0
475 && bit_sz <= MAX_BASE_INT_BIT_SIZE); 474 && bit_sz <= MAX_BASE_INT_BIT_SIZE);
476 475
477 /* Determine the max exp argument value according to 476 /* Determine the max exp argument value according to
478 the size of the base integer. The max exp value 477 the size of the base integer. The max exp value
479 is conservatively estimated assuming IEEE754 double 478 is conservatively estimated assuming IEEE754 double
481 if (bit_sz == 8) 480 if (bit_sz == 8)
482 max_exp = 128; 481 max_exp = 128;
483 else if (bit_sz == 16) 482 else if (bit_sz == 16)
484 max_exp = 64; 483 max_exp = 64;
485 else 484 else
486 { 485 {
487 gcc_assert (bit_sz == MAX_BASE_INT_BIT_SIZE); 486 gcc_assert (bit_sz == MAX_BASE_INT_BIT_SIZE);
488 max_exp = 32; 487 max_exp = 32;
489 } 488 }
490 489
491 /* For pow ((double)x, y), generate the following conditions: 490 /* For pow ((double)x, y), generate the following conditions:
492 cond 1: 491 cond 1:
493 temp1 = x; 492 temp1 = x;
494 if (temp1 <= 0) 493 if (temp1 <= 0)
542 otherwise the call is bypassed. POW_CALL is the call statement, 541 otherwise the call is bypassed. POW_CALL is the call statement,
543 *CONDS is a vector holding the resulting condition statements, 542 *CONDS is a vector holding the resulting condition statements,
544 and *NCONDS is the number of logical conditions. */ 543 and *NCONDS is the number of logical conditions. */
545 544
546 static void 545 static void
547 gen_conditions_for_pow (gimple pow_call, VEC (gimple, heap) *conds, 546 gen_conditions_for_pow (gimple pow_call, VEC (gimple, heap) *conds,
548 unsigned *nconds) 547 unsigned *nconds)
549 { 548 {
550 tree base, expn; 549 tree base, expn;
551 enum tree_code bc, ec; 550 enum tree_code bc;
552 551
553 #ifdef ENABLE_CHECKING 552 #ifdef ENABLE_CHECKING
554 gcc_assert (check_pow (pow_call)); 553 gcc_assert (check_pow (pow_call));
555 #endif 554 #endif
556 555
558 557
559 base = gimple_call_arg (pow_call, 0); 558 base = gimple_call_arg (pow_call, 0);
560 expn = gimple_call_arg (pow_call, 1); 559 expn = gimple_call_arg (pow_call, 1);
561 560
562 bc = TREE_CODE (base); 561 bc = TREE_CODE (base);
563 ec = TREE_CODE (expn);
564 562
565 if (bc == REAL_CST) 563 if (bc == REAL_CST)
566 gen_conditions_for_pow_cst_base (base, expn, conds, nconds); 564 gen_conditions_for_pow_cst_base (base, expn, conds, nconds);
567 else if (bc == SSA_NAME) 565 else if (bc == SSA_NAME)
568 gen_conditions_for_pow_int_base (base, expn, conds, nconds); 566 gen_conditions_for_pow_int_base (base, expn, conds, nconds);
569 else 567 else
570 gcc_unreachable (); 568 gcc_unreachable ();
571 } 569 }
572 570
573 /* A helper routine to help computing the valid input domain 571 /* A helper routine to help computing the valid input domain
574 for a builtin function. See C99 7.12.7 for details. In this 572 for a builtin function. See C99 7.12.7 for details. In this
575 implementation, we only handle single region domain. The 573 implementation, we only handle single region domain. The
576 resulting region can be conservative (smaller) than the actual 574 resulting region can be conservative (smaller) than the actual
577 one and rounded to integers. Some of the bounds are documented 575 one and rounded to integers. Some of the bounds are documented
578 in the standard, while other limit constants are computed 576 in the standard, while other limit constants are computed
579 assuming IEEE floating point format (for SF and DF modes). 577 assuming IEEE floating point format (for SF and DF modes).
580 Since IEEE only sets minimum requirements for long double format, 578 Since IEEE only sets minimum requirements for long double format,
581 different long double formats exist under different implementations 579 different long double formats exist under different implementations
582 (e.g, 64 bit double precision (DF), 80 bit double-extended 580 (e.g, 64 bit double precision (DF), 80 bit double-extended
583 precision (XF), and 128 bit quad precision (QF) ). For simplicity, 581 precision (XF), and 128 bit quad precision (QF) ). For simplicity,
584 in this implementation, the computed bounds for long double assume 582 in this implementation, the computed bounds for long double assume
585 64 bit format (DF), and are therefore conservative. Another 583 64 bit format (DF), and are therefore conservative. Another
586 assumption is that single precision float type is always SF mode, 584 assumption is that single precision float type is always SF mode,
587 and double type is DF mode. This function is quite 585 and double type is DF mode. This function is quite
588 implementation specific, so it may not be suitable to be part of 586 implementation specific, so it may not be suitable to be part of
589 builtins.c. This needs to be revisited later to see if it can 587 builtins.c. This needs to be revisited later to see if it can
590 be leveraged in x87 assembly expansion. */ 588 be leveraged in x87 assembly expansion. */
591 589
592 static inp_domain 590 static inp_domain
666 /* sqrt: [0, +inf) */ 664 /* sqrt: [0, +inf) */
667 CASE_FLT_FN (BUILT_IN_SQRT): 665 CASE_FLT_FN (BUILT_IN_SQRT):
668 return get_domain (0, true, true, 666 return get_domain (0, true, true,
669 0, false, false); 667 0, false, false);
670 default: 668 default:
671 gcc_unreachable (); 669 gcc_unreachable ();
672 } 670 }
673 671
674 gcc_unreachable (); 672 gcc_unreachable ();
675 } 673 }
676 674
677 /* The function to generate shrink wrap conditions for a partially 675 /* The function to generate shrink wrap conditions for a partially
678 dead builtin call whose return value is not used anywhere, 676 dead builtin call whose return value is not used anywhere,
679 but has to be kept live due to potential error condition. 677 but has to be kept live due to potential error condition.
680 BI_CALL is the builtin call, CONDS is the vector of statements 678 BI_CALL is the builtin call, CONDS is the vector of statements
681 for condition code, NCODES is the pointer to the number of 679 for condition code, NCODES is the pointer to the number of
682 logical conditions. Statements belonging to different logical 680 logical conditions. Statements belonging to different logical
683 condition are separated by NULL tree in the vector. */ 681 condition are separated by NULL tree in the vector. */
684 682
685 static void 683 static void
686 gen_shrink_wrap_conditions (gimple bi_call, VEC (gimple, heap) *conds, 684 gen_shrink_wrap_conditions (gimple bi_call, VEC (gimple, heap) *conds,
687 unsigned int *nconds) 685 unsigned int *nconds)
688 { 686 {
689 gimple call; 687 gimple call;
690 tree fn; 688 tree fn;
691 enum built_in_function fnc; 689 enum built_in_function fnc;
716 714
717 715
718 /* Probability of the branch (to the call) is taken. */ 716 /* Probability of the branch (to the call) is taken. */
719 #define ERR_PROB 0.01 717 #define ERR_PROB 0.01
720 718
721 /* The function to shrink wrap a partially dead builtin call 719 /* The function to shrink wrap a partially dead builtin call
722 whose return value is not used anywhere, but has to be kept 720 whose return value is not used anywhere, but has to be kept
723 live due to potential error condition. Returns true if the 721 live due to potential error condition. Returns true if the
724 transformation actually happens. */ 722 transformation actually happens. */
725 723
726 static bool 724 static bool
727 shrink_wrap_one_built_in_call (gimple bi_call) 725 shrink_wrap_one_built_in_call (gimple bi_call)
728 { 726 {
729 gimple_stmt_iterator bi_call_bsi; 727 gimple_stmt_iterator bi_call_bsi;
730 basic_block bi_call_bb, join_tgt_bb, guard_bb, guard_bb0; 728 basic_block bi_call_bb, join_tgt_bb, guard_bb, guard_bb0;
731 edge join_tgt_in_edge_from_call, join_tgt_in_edge_fall_thru; 729 edge join_tgt_in_edge_from_call, join_tgt_in_edge_fall_thru;
741 conds = VEC_alloc (gimple, heap, 12); 739 conds = VEC_alloc (gimple, heap, 12);
742 gen_shrink_wrap_conditions (bi_call, conds, &nconds); 740 gen_shrink_wrap_conditions (bi_call, conds, &nconds);
743 741
744 /* This can happen if the condition generator decides 742 /* This can happen if the condition generator decides
745 it is not beneficial to do the transformation. Just 743 it is not beneficial to do the transformation. Just
746 return false and do not do any transformation for 744 return false and do not do any transformation for
747 the call. */ 745 the call. */
748 if (nconds == 0) 746 if (nconds == 0)
749 return false; 747 return false;
750 748
751 bi_call_bb = gimple_bb (bi_call); 749 bi_call_bb = gimple_bb (bi_call);
777 nconds--; 775 nconds--;
778 ci++; 776 ci++;
779 gcc_assert (cond_expr && gimple_code (cond_expr) == GIMPLE_COND); 777 gcc_assert (cond_expr && gimple_code (cond_expr) == GIMPLE_COND);
780 778
781 /* Now the label. */ 779 /* Now the label. */
782 bi_call_label_decl = create_artificial_label (); 780 bi_call_label_decl = create_artificial_label (gimple_location (bi_call));
783 bi_call_label = gimple_build_label (bi_call_label_decl); 781 bi_call_label = gimple_build_label (bi_call_label_decl);
784 gsi_insert_before (&bi_call_bsi, bi_call_label, GSI_SAME_STMT); 782 gsi_insert_before (&bi_call_bsi, bi_call_label, GSI_SAME_STMT);
785 783
786 bi_call_in_edge0 = split_block (bi_call_bb, cond_expr); 784 bi_call_in_edge0 = split_block (bi_call_bb, cond_expr);
787 bi_call_in_edge0->flags &= ~EDGE_FALLTHRU; 785 bi_call_in_edge0->flags &= ~EDGE_FALLTHRU;
788 bi_call_in_edge0->flags |= EDGE_TRUE_VALUE; 786 bi_call_in_edge0->flags |= EDGE_TRUE_VALUE;
789 guard_bb0 = bi_call_bb; 787 guard_bb0 = bi_call_bb;
790 bi_call_bb = bi_call_in_edge0->dest; 788 bi_call_bb = bi_call_in_edge0->dest;
791 join_tgt_in_edge_fall_thru = make_edge (guard_bb0, join_tgt_bb, 789 join_tgt_in_edge_fall_thru = make_edge (guard_bb0, join_tgt_bb,
792 EDGE_FALSE_VALUE); 790 EDGE_FALSE_VALUE);
793 791
794 bi_call_in_edge0->probability = REG_BR_PROB_BASE * ERR_PROB; 792 bi_call_in_edge0->probability = REG_BR_PROB_BASE * ERR_PROB;
795 join_tgt_in_edge_fall_thru->probability = 793 join_tgt_in_edge_fall_thru->probability =
796 REG_BR_PROB_BASE - bi_call_in_edge0->probability; 794 REG_BR_PROB_BASE - bi_call_in_edge0->probability;
849 { 847 {
850 bool changed = false; 848 bool changed = false;
851 unsigned i = 0; 849 unsigned i = 0;
852 850
853 unsigned n = VEC_length (gimple, calls); 851 unsigned n = VEC_length (gimple, calls);
854 if (n == 0) 852 if (n == 0)
855 return false; 853 return false;
856 854
857 for (; i < n ; i++) 855 for (; i < n ; i++)
858 { 856 {
859 gimple bi_call = VEC_index (gimple, calls, i); 857 gimple bi_call = VEC_index (gimple, calls, i);
904 902
905 if (something_changed) 903 if (something_changed)
906 { 904 {
907 free_dominance_info (CDI_DOMINATORS); 905 free_dominance_info (CDI_DOMINATORS);
908 free_dominance_info (CDI_POST_DOMINATORS); 906 free_dominance_info (CDI_POST_DOMINATORS);
909 return (TODO_update_ssa | TODO_cleanup_cfg | TODO_ggc_collect 907 /* As we introduced new control-flow we need to insert PHI-nodes
908 for the call-clobbers of the remaining call. */
909 mark_sym_for_renaming (gimple_vop (cfun));
910 return (TODO_update_ssa | TODO_cleanup_cfg | TODO_ggc_collect
910 | TODO_remove_unused_locals); 911 | TODO_remove_unused_locals);
911 } 912 }
912 else 913 else
913 return 0; 914 return 0;
914 } 915 }
917 gate_call_cdce (void) 918 gate_call_cdce (void)
918 { 919 {
919 /* The limit constants used in the implementation 920 /* The limit constants used in the implementation
920 assume IEEE floating point format. Other formats 921 assume IEEE floating point format. Other formats
921 can be supported in the future if needed. */ 922 can be supported in the future if needed. */
922 return flag_tree_builtin_call_dce != 0 && optimize_function_for_speed_p (cfun); 923 return flag_tree_builtin_call_dce != 0 && optimize_function_for_speed_p (cfun);
923 } 924 }
924 925
925 struct gimple_opt_pass pass_call_cdce = 926 struct gimple_opt_pass pass_call_cdce =
926 { 927 {
927 { 928 {