LCOV - code coverage report
Current view: top level - gcc - tree-call-cdce.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 90.4 % 543 491
Test Date: 2024-03-23 14:05:01 Functions: 95.7 % 23 22
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

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

Generated by: LCOV version 2.0-1

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.