LCOV - code coverage report
Current view: top level - gcc - gimple-lower-bitint.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.6 % 4447 4120
Test Date: 2024-04-27 14:03:13 Functions: 100.0 % 56 56
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Lower _BitInt(N) operations to scalar operations.
       2                 :             :    Copyright (C) 2023-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by Jakub Jelinek <jakub@redhat.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 "rtl.h"
      26                 :             : #include "tree.h"
      27                 :             : #include "gimple.h"
      28                 :             : #include "cfghooks.h"
      29                 :             : #include "tree-pass.h"
      30                 :             : #include "ssa.h"
      31                 :             : #include "fold-const.h"
      32                 :             : #include "gimplify.h"
      33                 :             : #include "gimple-iterator.h"
      34                 :             : #include "tree-cfg.h"
      35                 :             : #include "tree-dfa.h"
      36                 :             : #include "cfgloop.h"
      37                 :             : #include "cfganal.h"
      38                 :             : #include "target.h"
      39                 :             : #include "tree-ssa-live.h"
      40                 :             : #include "tree-ssa-coalesce.h"
      41                 :             : #include "domwalk.h"
      42                 :             : #include "memmodel.h"
      43                 :             : #include "optabs.h"
      44                 :             : #include "varasm.h"
      45                 :             : #include "gimple-range.h"
      46                 :             : #include "value-range.h"
      47                 :             : #include "langhooks.h"
      48                 :             : #include "gimplify-me.h"
      49                 :             : #include "diagnostic-core.h"
      50                 :             : #include "tree-eh.h"
      51                 :             : #include "tree-pretty-print.h"
      52                 :             : #include "alloc-pool.h"
      53                 :             : #include "tree-into-ssa.h"
      54                 :             : #include "tree-cfgcleanup.h"
      55                 :             : #include "tree-switch-conversion.h"
      56                 :             : #include "ubsan.h"
      57                 :             : #include "stor-layout.h"
      58                 :             : #include "gimple-lower-bitint.h"
      59                 :             : 
      60                 :             : /* Split BITINT_TYPE precisions in 4 categories.  Small _BitInt, where
      61                 :             :    target hook says it is a single limb, middle _BitInt which per ABI
      62                 :             :    does not, but there is some INTEGER_TYPE in which arithmetics can be
      63                 :             :    performed (operations on such _BitInt are lowered to casts to that
      64                 :             :    arithmetic type and cast back; e.g. on x86_64 limb is DImode, but
      65                 :             :    target supports TImode, so _BitInt(65) to _BitInt(128) are middle
      66                 :             :    ones), large _BitInt which should by straight line code and
      67                 :             :    finally huge _BitInt which should be handled by loops over the limbs.  */
      68                 :             : 
      69                 :             : enum bitint_prec_kind {
      70                 :             :   bitint_prec_small,
      71                 :             :   bitint_prec_middle,
      72                 :             :   bitint_prec_large,
      73                 :             :   bitint_prec_huge
      74                 :             : };
      75                 :             : 
      76                 :             : /* Caches to speed up bitint_precision_kind.  */
      77                 :             : 
      78                 :             : static int small_max_prec, mid_min_prec, large_min_prec, huge_min_prec;
      79                 :             : static int limb_prec;
      80                 :             : 
      81                 :             : /* Categorize _BitInt(PREC) as small, middle, large or huge.  */
      82                 :             : 
      83                 :             : static bitint_prec_kind
      84                 :      461210 : bitint_precision_kind (int prec)
      85                 :             : {
      86                 :      461210 :   if (prec <= small_max_prec)
      87                 :             :     return bitint_prec_small;
      88                 :      446633 :   if (huge_min_prec && prec >= huge_min_prec)
      89                 :             :     return bitint_prec_huge;
      90                 :      259482 :   if (large_min_prec && prec >= large_min_prec)
      91                 :             :     return bitint_prec_large;
      92                 :       51205 :   if (mid_min_prec && prec >= mid_min_prec)
      93                 :             :     return bitint_prec_middle;
      94                 :             : 
      95                 :        9152 :   struct bitint_info info;
      96                 :        9152 :   bool ok = targetm.c.bitint_type_info (prec, &info);
      97                 :        9152 :   gcc_assert (ok);
      98                 :        9152 :   scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode);
      99                 :        9152 :   if (prec <= GET_MODE_PRECISION (limb_mode))
     100                 :             :     {
     101                 :        2133 :       small_max_prec = prec;
     102                 :        2133 :       return bitint_prec_small;
     103                 :             :     }
     104                 :        7019 :   if (!large_min_prec
     105                 :       13970 :       && GET_MODE_PRECISION (limb_mode) < MAX_FIXED_MODE_SIZE)
     106                 :       13902 :     large_min_prec = MAX_FIXED_MODE_SIZE + 1;
     107                 :        7019 :   if (!limb_prec)
     108                 :        6951 :     limb_prec = GET_MODE_PRECISION (limb_mode);
     109                 :        7019 :   if (!huge_min_prec)
     110                 :             :     {
     111                 :       13902 :       if (4 * limb_prec >= MAX_FIXED_MODE_SIZE)
     112                 :        6951 :         huge_min_prec = 4 * limb_prec;
     113                 :             :       else
     114                 :           0 :         huge_min_prec = MAX_FIXED_MODE_SIZE + 1;
     115                 :             :     }
     116                 :       14038 :   if (prec <= MAX_FIXED_MODE_SIZE)
     117                 :             :     {
     118                 :        1566 :       if (!mid_min_prec || prec < mid_min_prec)
     119                 :        1566 :         mid_min_prec = prec;
     120                 :        1566 :       return bitint_prec_middle;
     121                 :             :     }
     122                 :        5453 :   if (large_min_prec && prec <= large_min_prec)
     123                 :             :     return bitint_prec_large;
     124                 :             :   return bitint_prec_huge;
     125                 :             : }
     126                 :             : 
     127                 :             : /* Same for a TYPE.  */
     128                 :             : 
     129                 :             : static bitint_prec_kind
     130                 :      455928 : bitint_precision_kind (tree type)
     131                 :             : {
     132                 :      455928 :   return bitint_precision_kind (TYPE_PRECISION (type));
     133                 :             : }
     134                 :             : 
     135                 :             : /* Return minimum precision needed to describe INTEGER_CST
     136                 :             :    CST.  All bits above that precision up to precision of
     137                 :             :    TREE_TYPE (CST) are cleared if EXT is set to 0, or set
     138                 :             :    if EXT is set to -1.  */
     139                 :             : 
     140                 :             : static unsigned
     141                 :        5109 : bitint_min_cst_precision (tree cst, int &ext)
     142                 :             : {
     143                 :        5109 :   ext = tree_int_cst_sgn (cst) < 0 ? -1 : 0;
     144                 :        5109 :   wide_int w = wi::to_wide (cst);
     145                 :        5109 :   unsigned min_prec = wi::min_precision (w, TYPE_SIGN (TREE_TYPE (cst)));
     146                 :             :   /* For signed values, we don't need to count the sign bit,
     147                 :             :      we'll use constant 0 or -1 for the upper bits.  */
     148                 :        5109 :   if (!TYPE_UNSIGNED (TREE_TYPE (cst)))
     149                 :        3190 :     --min_prec;
     150                 :             :   else
     151                 :             :     {
     152                 :             :       /* For unsigned values, also try signed min_precision
     153                 :             :          in case the constant has lots of most significant bits set.  */
     154                 :        1919 :       unsigned min_prec2 = wi::min_precision (w, SIGNED) - 1;
     155                 :        1919 :       if (min_prec2 < min_prec)
     156                 :             :         {
     157                 :         929 :           ext = -1;
     158                 :         929 :           return min_prec2;
     159                 :             :         }
     160                 :             :     }
     161                 :             :   return min_prec;
     162                 :        5109 : }
     163                 :             : 
     164                 :             : namespace {
     165                 :             : 
     166                 :             : /* If OP is middle _BitInt, cast it to corresponding INTEGER_TYPE
     167                 :             :    cached in TYPE and return it.  */
     168                 :             : 
     169                 :             : tree
     170                 :        7662 : maybe_cast_middle_bitint (gimple_stmt_iterator *gsi, tree op, tree &type)
     171                 :             : {
     172                 :        7662 :   if (op == NULL_TREE
     173                 :        7634 :       || TREE_CODE (TREE_TYPE (op)) != BITINT_TYPE
     174                 :       14437 :       || bitint_precision_kind (TREE_TYPE (op)) != bitint_prec_middle)
     175                 :         888 :     return op;
     176                 :             : 
     177                 :        6774 :   int prec = TYPE_PRECISION (TREE_TYPE (op));
     178                 :        6774 :   int uns = TYPE_UNSIGNED (TREE_TYPE (op));
     179                 :        6774 :   if (type == NULL_TREE
     180                 :        2511 :       || TYPE_PRECISION (type) != prec
     181                 :        9285 :       || TYPE_UNSIGNED (type) != uns)
     182                 :        4263 :     type = build_nonstandard_integer_type (prec, uns);
     183                 :             : 
     184                 :        6774 :   if (TREE_CODE (op) != SSA_NAME)
     185                 :             :     {
     186                 :        2335 :       tree nop = fold_convert (type, op);
     187                 :        2335 :       if (is_gimple_val (nop))
     188                 :             :         return nop;
     189                 :             :     }
     190                 :             : 
     191                 :        4439 :   tree nop = make_ssa_name (type);
     192                 :        4439 :   gimple *g = gimple_build_assign (nop, NOP_EXPR, op);
     193                 :        4439 :   gsi_insert_before (gsi, g, GSI_SAME_STMT);
     194                 :        4439 :   return nop;
     195                 :             : }
     196                 :             : 
     197                 :             : /* Return true if STMT can be handled in a loop from least to most
     198                 :             :    significant limb together with its dependencies.  */
     199                 :             : 
     200                 :             : bool
     201                 :       45214 : mergeable_op (gimple *stmt)
     202                 :             : {
     203                 :       45214 :   if (!is_gimple_assign (stmt))
     204                 :             :     return false;
     205                 :       36898 :   switch (gimple_assign_rhs_code (stmt))
     206                 :             :     {
     207                 :             :     case PLUS_EXPR:
     208                 :             :     case MINUS_EXPR:
     209                 :             :     case NEGATE_EXPR:
     210                 :             :     case BIT_AND_EXPR:
     211                 :             :     case BIT_IOR_EXPR:
     212                 :             :     case BIT_XOR_EXPR:
     213                 :             :     case BIT_NOT_EXPR:
     214                 :             :     case SSA_NAME:
     215                 :             :     case INTEGER_CST:
     216                 :             :     case BIT_FIELD_REF:
     217                 :             :       return true;
     218                 :         369 :     case LSHIFT_EXPR:
     219                 :         369 :       {
     220                 :         369 :         tree cnt = gimple_assign_rhs2 (stmt);
     221                 :         369 :         if (tree_fits_uhwi_p (cnt)
     222                 :         179 :             && tree_to_uhwi (cnt) < (unsigned HOST_WIDE_INT) limb_prec)
     223                 :             :           return true;
     224                 :             :       }
     225                 :             :       break;
     226                 :        5774 :     CASE_CONVERT:
     227                 :        5774 :     case VIEW_CONVERT_EXPR:
     228                 :        5774 :       {
     229                 :        5774 :         tree lhs_type = TREE_TYPE (gimple_assign_lhs (stmt));
     230                 :        5774 :         tree rhs_type = TREE_TYPE (gimple_assign_rhs1 (stmt));
     231                 :        5774 :         if (TREE_CODE (gimple_assign_rhs1 (stmt)) == SSA_NAME
     232                 :        5734 :             && TREE_CODE (lhs_type) == BITINT_TYPE
     233                 :        3328 :             && TREE_CODE (rhs_type) == BITINT_TYPE
     234                 :        3007 :             && bitint_precision_kind (lhs_type) >= bitint_prec_large
     235                 :        2982 :             && bitint_precision_kind (rhs_type) >= bitint_prec_large
     236                 :        8635 :             && (CEIL (TYPE_PRECISION (lhs_type), limb_prec)
     237                 :        2861 :                 == CEIL (TYPE_PRECISION (rhs_type), limb_prec)))
     238                 :             :           {
     239                 :        2116 :             if (TYPE_PRECISION (rhs_type) >= TYPE_PRECISION (lhs_type))
     240                 :             :               return true;
     241                 :         145 :             if ((unsigned) TYPE_PRECISION (lhs_type) % (2 * limb_prec) != 0)
     242                 :             :               return true;
     243                 :           6 :             if (bitint_precision_kind (lhs_type) == bitint_prec_large)
     244                 :             :               return true;
     245                 :             :           }
     246                 :             :         break;
     247                 :             :       }
     248                 :             :     default:
     249                 :             :       break;
     250                 :             :     }
     251                 :             :   return false;
     252                 :             : }
     253                 :             : 
     254                 :             : /* Return non-zero if stmt is .{ADD,SUB,MUL}_OVERFLOW call with
     255                 :             :    _Complex large/huge _BitInt lhs which has at most two immediate uses,
     256                 :             :    at most one use in REALPART_EXPR stmt in the same bb and exactly one
     257                 :             :    IMAGPART_EXPR use in the same bb with a single use which casts it to
     258                 :             :    non-BITINT_TYPE integral type.  If there is a REALPART_EXPR use,
     259                 :             :    return 2.  Such cases (most common uses of those builtins) can be
     260                 :             :    optimized by marking their lhs and lhs of IMAGPART_EXPR and maybe lhs
     261                 :             :    of REALPART_EXPR as not needed to be backed up by a stack variable.
     262                 :             :    For .UBSAN_CHECK_{ADD,SUB,MUL} return 3.  */
     263                 :             : 
     264                 :             : int
     265                 :       19827 : optimizable_arith_overflow (gimple *stmt)
     266                 :             : {
     267                 :       19827 :   bool is_ubsan = false;
     268                 :       19827 :   if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt))
     269                 :             :     return false;
     270                 :        4929 :   switch (gimple_call_internal_fn (stmt))
     271                 :             :     {
     272                 :             :     case IFN_ADD_OVERFLOW:
     273                 :             :     case IFN_SUB_OVERFLOW:
     274                 :             :     case IFN_MUL_OVERFLOW:
     275                 :             :       break;
     276                 :          48 :     case IFN_UBSAN_CHECK_ADD:
     277                 :          48 :     case IFN_UBSAN_CHECK_SUB:
     278                 :          48 :     case IFN_UBSAN_CHECK_MUL:
     279                 :          48 :       is_ubsan = true;
     280                 :          48 :       break;
     281                 :             :     default:
     282                 :             :       return 0;
     283                 :             :     }
     284                 :        4929 :   tree lhs = gimple_call_lhs (stmt);
     285                 :        4929 :   if (!lhs)
     286                 :             :     return 0;
     287                 :        4929 :   if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
     288                 :             :     return 0;
     289                 :        4929 :   tree type = is_ubsan ? TREE_TYPE (lhs) : TREE_TYPE (TREE_TYPE (lhs));
     290                 :        4929 :   if (TREE_CODE (type) != BITINT_TYPE
     291                 :        4929 :       || bitint_precision_kind (type) < bitint_prec_large)
     292                 :           0 :     return 0;
     293                 :             : 
     294                 :        4929 :   if (is_ubsan)
     295                 :             :     {
     296                 :          48 :       use_operand_p use_p;
     297                 :          48 :       gimple *use_stmt;
     298                 :          48 :       if (!single_imm_use (lhs, &use_p, &use_stmt)
     299                 :          48 :           || gimple_bb (use_stmt) != gimple_bb (stmt)
     300                 :          48 :           || !gimple_store_p (use_stmt)
     301                 :          48 :           || !is_gimple_assign (use_stmt)
     302                 :          48 :           || gimple_has_volatile_ops (use_stmt)
     303                 :          96 :           || stmt_ends_bb_p (use_stmt))
     304                 :           0 :         return 0;
     305                 :             :       return 3;
     306                 :             :     }
     307                 :             : 
     308                 :        4881 :   imm_use_iterator ui;
     309                 :        4881 :   use_operand_p use_p;
     310                 :        4881 :   int seen = 0;
     311                 :        4881 :   gimple *realpart = NULL, *cast = NULL;
     312                 :       14377 :   FOR_EACH_IMM_USE_FAST (use_p, ui, lhs)
     313                 :             :     {
     314                 :        9500 :       gimple *g = USE_STMT (use_p);
     315                 :        9500 :       if (is_gimple_debug (g))
     316                 :           0 :         continue;
     317                 :        9500 :       if (!is_gimple_assign (g) || gimple_bb (g) != gimple_bb (stmt))
     318                 :             :         return 0;
     319                 :        9500 :       if (gimple_assign_rhs_code (g) == REALPART_EXPR)
     320                 :             :         {
     321                 :        4619 :           if ((seen & 1) != 0)
     322                 :             :             return 0;
     323                 :        4619 :           seen |= 1;
     324                 :        4619 :           realpart = g;
     325                 :             :         }
     326                 :        4881 :       else if (gimple_assign_rhs_code (g) == IMAGPART_EXPR)
     327                 :             :         {
     328                 :        4881 :           if ((seen & 2) != 0)
     329                 :           4 :             return 0;
     330                 :        4881 :           seen |= 2;
     331                 :             : 
     332                 :        4881 :           use_operand_p use2_p;
     333                 :        4881 :           gimple *use_stmt;
     334                 :        4881 :           tree lhs2 = gimple_assign_lhs (g);
     335                 :        4881 :           if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs2))
     336                 :             :             return 0;
     337                 :        4881 :           if (!single_imm_use (lhs2, &use2_p, &use_stmt)
     338                 :        4881 :               || gimple_bb (use_stmt) != gimple_bb (stmt)
     339                 :        9762 :               || !gimple_assign_cast_p (use_stmt))
     340                 :             :             return 0;
     341                 :             : 
     342                 :        4881 :           lhs2 = gimple_assign_lhs (use_stmt);
     343                 :        9762 :           if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs2))
     344                 :        9762 :               || TREE_CODE (TREE_TYPE (lhs2)) == BITINT_TYPE)
     345                 :             :             return 0;
     346                 :        4877 :           cast = use_stmt;
     347                 :             :         }
     348                 :             :       else
     349                 :             :         return 0;
     350                 :             :     }
     351                 :        4877 :   if ((seen & 2) == 0)
     352                 :             :     return 0;
     353                 :        4877 :   if (seen == 3)
     354                 :             :     {
     355                 :             :       /* Punt if the cast stmt appears before realpart stmt, because
     356                 :             :          if both appear, the lowering wants to emit all the code
     357                 :             :          at the location of realpart stmt.  */
     358                 :        4619 :       gimple_stmt_iterator gsi = gsi_for_stmt (realpart);
     359                 :        4619 :       unsigned int cnt = 0;
     360                 :        4621 :       do
     361                 :             :         {
     362                 :        4621 :           gsi_prev_nondebug (&gsi);
     363                 :        4621 :           if (gsi_end_p (gsi) || gsi_stmt (gsi) == cast)
     364                 :           2 :             return 0;
     365                 :        4619 :           if (gsi_stmt (gsi) == stmt)
     366                 :             :             return 2;
     367                 :             :           /* If realpart is too far from stmt, punt as well.
     368                 :             :              Usually it will appear right after it.  */
     369                 :           2 :           if (++cnt == 32)
     370                 :             :             return 0;
     371                 :             :         }
     372                 :             :       while (1);
     373                 :             :     }
     374                 :             :   return 1;
     375                 :             : }
     376                 :             : 
     377                 :             : /* If STMT is some kind of comparison (GIMPLE_COND, comparison assignment)
     378                 :             :    comparing large/huge _BitInt types, return the comparison code and if
     379                 :             :    non-NULL fill in the comparison operands to *POP1 and *POP2.  */
     380                 :             : 
     381                 :             : tree_code
     382                 :       34258 : comparison_op (gimple *stmt, tree *pop1, tree *pop2)
     383                 :             : {
     384                 :       34258 :   tree op1 = NULL_TREE, op2 = NULL_TREE;
     385                 :       34258 :   tree_code code = ERROR_MARK;
     386                 :       34258 :   if (gimple_code (stmt) == GIMPLE_COND)
     387                 :             :     {
     388                 :        6240 :       code = gimple_cond_code (stmt);
     389                 :        6240 :       op1 = gimple_cond_lhs (stmt);
     390                 :        6240 :       op2 = gimple_cond_rhs (stmt);
     391                 :             :     }
     392                 :       28018 :   else if (is_gimple_assign (stmt))
     393                 :             :     {
     394                 :       28003 :       code = gimple_assign_rhs_code (stmt);
     395                 :       28003 :       op1 = gimple_assign_rhs1 (stmt);
     396                 :       28003 :       if (TREE_CODE_CLASS (code) == tcc_comparison
     397                 :       28003 :           || TREE_CODE_CLASS (code) == tcc_binary)
     398                 :        2029 :         op2 = gimple_assign_rhs2 (stmt);
     399                 :             :     }
     400                 :       34258 :   if (TREE_CODE_CLASS (code) != tcc_comparison)
     401                 :             :     return ERROR_MARK;
     402                 :        7014 :   tree type = TREE_TYPE (op1);
     403                 :        7014 :   if (TREE_CODE (type) != BITINT_TYPE
     404                 :        7014 :       || bitint_precision_kind (type) < bitint_prec_large)
     405                 :           0 :     return ERROR_MARK;
     406                 :        7014 :   if (pop1)
     407                 :             :     {
     408                 :        6952 :       *pop1 = op1;
     409                 :        6952 :       *pop2 = op2;
     410                 :             :     }
     411                 :             :   return code;
     412                 :             : }
     413                 :             : 
     414                 :             : /* Class used during large/huge _BitInt lowering containing all the
     415                 :             :    state for the methods.  */
     416                 :             : 
     417                 :             : struct bitint_large_huge
     418                 :             : {
     419                 :        6951 :   bitint_large_huge ()
     420                 :        6951 :     : m_names (NULL), m_loads (NULL), m_preserved (NULL),
     421                 :        6951 :       m_single_use_names (NULL), m_map (NULL), m_vars (NULL),
     422                 :        6951 :       m_limb_type (NULL_TREE), m_data (vNULL),
     423                 :        6951 :       m_returns_twice_calls (vNULL) {}
     424                 :             : 
     425                 :             :   ~bitint_large_huge ();
     426                 :             : 
     427                 :             :   void insert_before (gimple *);
     428                 :             :   tree limb_access_type (tree, tree);
     429                 :             :   tree limb_access (tree, tree, tree, bool);
     430                 :             :   tree build_bit_field_ref (tree, tree, unsigned HOST_WIDE_INT,
     431                 :             :                             unsigned HOST_WIDE_INT);
     432                 :             :   void if_then (gimple *, profile_probability, edge &, edge &);
     433                 :             :   void if_then_else (gimple *, profile_probability, edge &, edge &);
     434                 :             :   void if_then_if_then_else (gimple *g, gimple *,
     435                 :             :                              profile_probability, profile_probability,
     436                 :             :                              edge &, edge &, edge &);
     437                 :             :   tree handle_operand (tree, tree);
     438                 :             :   tree prepare_data_in_out (tree, tree, tree *, tree = NULL_TREE);
     439                 :             :   tree add_cast (tree, tree);
     440                 :             :   tree handle_plus_minus (tree_code, tree, tree, tree);
     441                 :             :   tree handle_lshift (tree, tree, tree);
     442                 :             :   tree handle_cast (tree, tree, tree);
     443                 :             :   tree handle_bit_field_ref (tree, tree);
     444                 :             :   tree handle_load (gimple *, tree);
     445                 :             :   tree handle_stmt (gimple *, tree);
     446                 :             :   tree handle_operand_addr (tree, gimple *, int *, int *);
     447                 :             :   tree create_loop (tree, tree *);
     448                 :             :   tree lower_mergeable_stmt (gimple *, tree_code &, tree, tree);
     449                 :             :   tree lower_comparison_stmt (gimple *, tree_code &, tree, tree);
     450                 :             :   void lower_shift_stmt (tree, gimple *);
     451                 :             :   void lower_muldiv_stmt (tree, gimple *);
     452                 :             :   void lower_float_conv_stmt (tree, gimple *);
     453                 :             :   tree arith_overflow_extract_bits (unsigned int, unsigned int, tree,
     454                 :             :                                     unsigned int, bool);
     455                 :             :   void finish_arith_overflow (tree, tree, tree, tree, tree, tree, gimple *,
     456                 :             :                               tree_code);
     457                 :             :   void lower_addsub_overflow (tree, gimple *);
     458                 :             :   void lower_mul_overflow (tree, gimple *);
     459                 :             :   void lower_cplxpart_stmt (tree, gimple *);
     460                 :             :   void lower_complexexpr_stmt (gimple *);
     461                 :             :   void lower_bit_query (gimple *);
     462                 :             :   void lower_call (tree, gimple *);
     463                 :             :   void lower_asm (gimple *);
     464                 :             :   void lower_stmt (gimple *);
     465                 :             : 
     466                 :             :   /* Bitmap of large/huge _BitInt SSA_NAMEs except those can be
     467                 :             :      merged with their uses.  */
     468                 :             :   bitmap m_names;
     469                 :             :   /* Subset of those for lhs of load statements.  These will be
     470                 :             :      cleared in m_names if the loads will be mergeable with all
     471                 :             :      their uses.  */
     472                 :             :   bitmap m_loads;
     473                 :             :   /* Bitmap of large/huge _BitInt SSA_NAMEs that should survive
     474                 :             :      to later passes (arguments or return values of calls).  */
     475                 :             :   bitmap m_preserved;
     476                 :             :   /* Subset of m_names which have a single use.  As the lowering
     477                 :             :      can replace various original statements with their lowered
     478                 :             :      form even before it is done iterating over all basic blocks,
     479                 :             :      testing has_single_use for the purpose of emitting clobbers
     480                 :             :      doesn't work properly.  */
     481                 :             :   bitmap m_single_use_names;
     482                 :             :   /* Used for coalescing/partitioning of large/huge _BitInt SSA_NAMEs
     483                 :             :      set in m_names.  */
     484                 :             :   var_map m_map;
     485                 :             :   /* Mapping of the partitions to corresponding decls.  */
     486                 :             :   tree *m_vars;
     487                 :             :   /* Unsigned integer type with limb precision.  */
     488                 :             :   tree m_limb_type;
     489                 :             :   /* Its TYPE_SIZE_UNIT.  */
     490                 :             :   unsigned HOST_WIDE_INT m_limb_size;
     491                 :             :   /* Location of a gimple stmt which is being currently lowered.  */
     492                 :             :   location_t m_loc;
     493                 :             :   /* Current stmt iterator where code is being lowered currently.  */
     494                 :             :   gimple_stmt_iterator m_gsi;
     495                 :             :   /* Statement after which any clobbers should be added if non-NULL.  */
     496                 :             :   gimple *m_after_stmt;
     497                 :             :   /* Set when creating loops to the loop header bb and its preheader.  */
     498                 :             :   basic_block m_bb, m_preheader_bb;
     499                 :             :   /* Stmt iterator after which initialization statements should be emitted.  */
     500                 :             :   gimple_stmt_iterator m_init_gsi;
     501                 :             :   /* Decl into which a mergeable statement stores result.  */
     502                 :             :   tree m_lhs;
     503                 :             :   /* handle_operand/handle_stmt can be invoked in various ways.
     504                 :             : 
     505                 :             :      lower_mergeable_stmt for large _BitInt calls those with constant
     506                 :             :      idx only, expanding to straight line code, for huge _BitInt
     507                 :             :      emits a loop from least significant limb upwards, where each loop
     508                 :             :      iteration handles 2 limbs, plus there can be up to one full limb
     509                 :             :      and one partial limb processed after the loop, where handle_operand
     510                 :             :      and/or handle_stmt are called with constant idx.  m_upwards_2limb
     511                 :             :      is set for this case, false otherwise.  m_upwards is true if it
     512                 :             :      is either large or huge _BitInt handled by lower_mergeable_stmt,
     513                 :             :      i.e. indexes always increase.
     514                 :             : 
     515                 :             :      Another way is used by lower_comparison_stmt, which walks limbs
     516                 :             :      from most significant to least significant, partial limb if any
     517                 :             :      processed first with constant idx and then loop processing a single
     518                 :             :      limb per iteration with non-constant idx.
     519                 :             : 
     520                 :             :      Another way is used in lower_shift_stmt, where for LSHIFT_EXPR
     521                 :             :      destination limbs are processed from most significant to least
     522                 :             :      significant or for RSHIFT_EXPR the other way around, in loops or
     523                 :             :      straight line code, but idx usually is non-constant (so from
     524                 :             :      handle_operand/handle_stmt POV random access).  The LSHIFT_EXPR
     525                 :             :      handling there can access even partial limbs using non-constant
     526                 :             :      idx (then m_var_msb should be true, for all the other cases
     527                 :             :      including lower_mergeable_stmt/lower_comparison_stmt that is
     528                 :             :      not the case and so m_var_msb should be false.
     529                 :             : 
     530                 :             :      m_first should be set the first time handle_operand/handle_stmt
     531                 :             :      is called and clear when it is called for some other limb with
     532                 :             :      the same argument.  If the lowering of an operand (e.g. INTEGER_CST)
     533                 :             :      or statement (e.g. +/-/<< with < limb_prec constant) needs some
     534                 :             :      state between the different calls, when m_first is true it should
     535                 :             :      push some trees to m_data vector and also make sure m_data_cnt is
     536                 :             :      incremented by how many trees were pushed, and when m_first is
     537                 :             :      false, it can use the m_data[m_data_cnt] etc. data or update them,
     538                 :             :      just needs to bump m_data_cnt by the same amount as when it was
     539                 :             :      called with m_first set.  The toplevel calls to
     540                 :             :      handle_operand/handle_stmt should set m_data_cnt to 0 and truncate
     541                 :             :      m_data vector when setting m_first to true.
     542                 :             : 
     543                 :             :      m_cast_conditional and m_bitfld_load are used when handling a
     544                 :             :      bit-field load inside of a widening cast.  handle_cast sometimes
     545                 :             :      needs to do runtime comparisons and handle_operand only conditionally
     546                 :             :      or even in two separate conditional blocks for one idx (once with
     547                 :             :      constant index after comparing the runtime one for equality with the
     548                 :             :      constant).  In these cases, m_cast_conditional is set to true and
     549                 :             :      the bit-field load then communicates its m_data_cnt to handle_cast
     550                 :             :      using m_bitfld_load.  */
     551                 :             :   bool m_first;
     552                 :             :   bool m_var_msb;
     553                 :             :   unsigned m_upwards_2limb;
     554                 :             :   bool m_upwards;
     555                 :             :   bool m_cast_conditional;
     556                 :             :   unsigned m_bitfld_load;
     557                 :             :   vec<tree> m_data;
     558                 :             :   unsigned int m_data_cnt;
     559                 :             :   vec<gimple *> m_returns_twice_calls;
     560                 :             : };
     561                 :             : 
     562                 :        6951 : bitint_large_huge::~bitint_large_huge ()
     563                 :             : {
     564                 :        6951 :   BITMAP_FREE (m_names);
     565                 :        6951 :   BITMAP_FREE (m_loads);
     566                 :        6951 :   BITMAP_FREE (m_preserved);
     567                 :        6951 :   BITMAP_FREE (m_single_use_names);
     568                 :        6951 :   if (m_map)
     569                 :        5344 :     delete_var_map (m_map);
     570                 :        6951 :   XDELETEVEC (m_vars);
     571                 :        6951 :   m_data.release ();
     572                 :        6951 :   m_returns_twice_calls.release ();
     573                 :        6951 : }
     574                 :             : 
     575                 :             : /* Insert gimple statement G before current location
     576                 :             :    and set its gimple_location.  */
     577                 :             : 
     578                 :             : void
     579                 :      340316 : bitint_large_huge::insert_before (gimple *g)
     580                 :             : {
     581                 :      340316 :   gimple_set_location (g, m_loc);
     582                 :      340316 :   gsi_insert_before (&m_gsi, g, GSI_SAME_STMT);
     583                 :      340316 : }
     584                 :             : 
     585                 :             : /* Return type for accessing limb IDX of BITINT_TYPE TYPE.
     586                 :             :    This is normally m_limb_type, except for a partial most
     587                 :             :    significant limb if any.  */
     588                 :             : 
     589                 :             : tree
     590                 :      125465 : bitint_large_huge::limb_access_type (tree type, tree idx)
     591                 :             : {
     592                 :      125465 :   if (type == NULL_TREE)
     593                 :        5352 :     return m_limb_type;
     594                 :      120113 :   unsigned HOST_WIDE_INT i = tree_to_uhwi (idx);
     595                 :      120113 :   unsigned int prec = TYPE_PRECISION (type);
     596                 :      120113 :   gcc_assert (i * limb_prec < prec);
     597                 :      120113 :   if ((i + 1) * limb_prec <= prec)
     598                 :       78958 :     return m_limb_type;
     599                 :             :   else
     600                 :       82310 :     return build_nonstandard_integer_type (prec % limb_prec,
     601                 :       41155 :                                            TYPE_UNSIGNED (type));
     602                 :             : }
     603                 :             : 
     604                 :             : /* Return a tree how to access limb IDX of VAR corresponding to BITINT_TYPE
     605                 :             :    TYPE.  If WRITE_P is true, it will be a store, otherwise a read.  */
     606                 :             : 
     607                 :             : tree
     608                 :      148059 : bitint_large_huge::limb_access (tree type, tree var, tree idx, bool write_p)
     609                 :             : {
     610                 :      148059 :   tree atype = (tree_fits_uhwi_p (idx)
     611                 :      148059 :                 ? limb_access_type (type, idx) : m_limb_type);
     612                 :      148059 :   tree ltype = m_limb_type;
     613                 :      148059 :   addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (var));
     614                 :      148059 :   if (as != TYPE_ADDR_SPACE (ltype))
     615                 :          17 :     ltype = build_qualified_type (ltype, TYPE_QUALS (ltype)
     616                 :          17 :                                          | ENCODE_QUAL_ADDR_SPACE (as));
     617                 :      148059 :   tree ret;
     618                 :      148059 :   if (DECL_P (var) && tree_fits_uhwi_p (idx))
     619                 :             :     {
     620                 :       92694 :       tree ptype = build_pointer_type (strip_array_types (TREE_TYPE (var)));
     621                 :       92694 :       unsigned HOST_WIDE_INT off = tree_to_uhwi (idx) * m_limb_size;
     622                 :       92694 :       ret = build2 (MEM_REF, ltype,
     623                 :             :                     build_fold_addr_expr (var),
     624                 :             :                     build_int_cst (ptype, off));
     625                 :       92694 :       TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (var);
     626                 :       92694 :       TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (var);
     627                 :       92694 :     }
     628                 :       55365 :   else if (TREE_CODE (var) == MEM_REF && tree_fits_uhwi_p (idx))
     629                 :             :     {
     630                 :        4288 :       ret
     631                 :       12864 :         = build2 (MEM_REF, ltype, unshare_expr (TREE_OPERAND (var, 0)),
     632                 :        8576 :                   size_binop (PLUS_EXPR, TREE_OPERAND (var, 1),
     633                 :             :                               build_int_cst (TREE_TYPE (TREE_OPERAND (var, 1)),
     634                 :             :                                              tree_to_uhwi (idx)
     635                 :             :                                              * m_limb_size)));
     636                 :        4288 :       TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (var);
     637                 :        4288 :       TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (var);
     638                 :        4288 :       TREE_THIS_NOTRAP (ret) = TREE_THIS_NOTRAP (var);
     639                 :             :     }
     640                 :             :   else
     641                 :             :     {
     642                 :       51077 :       var = unshare_expr (var);
     643                 :       51077 :       if (TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE
     644                 :       77010 :           || !useless_type_conversion_p (m_limb_type,
     645                 :       25933 :                                          TREE_TYPE (TREE_TYPE (var))))
     646                 :             :         {
     647                 :       25700 :           unsigned HOST_WIDE_INT nelts
     648                 :       25700 :             = CEIL (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (var))), limb_prec);
     649                 :       25700 :           tree atype = build_array_type_nelts (ltype, nelts);
     650                 :       25700 :           var = build1 (VIEW_CONVERT_EXPR, atype, var);
     651                 :             :         }
     652                 :       51077 :       ret = build4 (ARRAY_REF, ltype, var, idx, NULL_TREE, NULL_TREE);
     653                 :             :     }
     654                 :      148059 :   if (!write_p && !useless_type_conversion_p (atype, m_limb_type))
     655                 :             :     {
     656                 :       17958 :       gimple *g = gimple_build_assign (make_ssa_name (m_limb_type), ret);
     657                 :       17958 :       insert_before (g);
     658                 :       17958 :       ret = gimple_assign_lhs (g);
     659                 :       17958 :       ret = build1 (NOP_EXPR, atype, ret);
     660                 :             :     }
     661                 :      148059 :   return ret;
     662                 :             : }
     663                 :             : 
     664                 :             : /* Build a BIT_FIELD_REF to access BITSIZE bits with FTYPE type at
     665                 :             :    offset BITPOS inside of OBJ.  */
     666                 :             : 
     667                 :             : tree
     668                 :         159 : bitint_large_huge::build_bit_field_ref (tree ftype, tree obj,
     669                 :             :                                         unsigned HOST_WIDE_INT bitsize,
     670                 :             :                                         unsigned HOST_WIDE_INT bitpos)
     671                 :             : {
     672                 :         318 :   if (INTEGRAL_TYPE_P (TREE_TYPE (obj))
     673                 :         160 :       && !type_has_mode_precision_p (TREE_TYPE (obj)))
     674                 :             :     {
     675                 :           1 :       unsigned HOST_WIDE_INT nelts
     676                 :           1 :         = CEIL (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (obj))), limb_prec);
     677                 :           1 :       tree ltype = m_limb_type;
     678                 :           1 :       addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (obj));
     679                 :           1 :       if (as != TYPE_ADDR_SPACE (ltype))
     680                 :           0 :         ltype = build_qualified_type (ltype, TYPE_QUALS (ltype)
     681                 :           0 :                                       | ENCODE_QUAL_ADDR_SPACE (as));
     682                 :           1 :       tree atype = build_array_type_nelts (ltype, nelts);
     683                 :           1 :       obj = build1 (VIEW_CONVERT_EXPR, atype, obj);
     684                 :             :     }
     685                 :         159 :   return build3 (BIT_FIELD_REF, ftype, obj, bitsize_int (bitsize),
     686                 :         159 :                  bitsize_int (bitpos));
     687                 :             : }
     688                 :             : 
     689                 :             : /* Emit a half diamond,
     690                 :             :    if (COND)
     691                 :             :      |\
     692                 :             :      | \
     693                 :             :      |  \
     694                 :             :      | new_bb1
     695                 :             :      |  /
     696                 :             :      | /
     697                 :             :      |/
     698                 :             :    or if (COND) new_bb1;
     699                 :             :    PROB is the probability that the condition is true.
     700                 :             :    Updates m_gsi to start of new_bb1.
     701                 :             :    Sets EDGE_TRUE to edge from new_bb1 to successor and
     702                 :             :    EDGE_FALSE to the EDGE_FALSE_VALUE edge from if (COND) bb.  */
     703                 :             : 
     704                 :             : void
     705                 :        3779 : bitint_large_huge::if_then (gimple *cond, profile_probability prob,
     706                 :             :                             edge &edge_true, edge &edge_false)
     707                 :             : {
     708                 :        3779 :   insert_before (cond);
     709                 :        3779 :   edge e1 = split_block (gsi_bb (m_gsi), cond);
     710                 :        3779 :   edge e2 = split_block (e1->dest, (gimple *) NULL);
     711                 :        3779 :   edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE);
     712                 :        3779 :   e1->flags = EDGE_TRUE_VALUE;
     713                 :        3779 :   e1->probability = prob;
     714                 :        3779 :   e3->probability = prob.invert ();
     715                 :        3779 :   set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src);
     716                 :        3779 :   edge_true = e2;
     717                 :        3779 :   edge_false = e3;
     718                 :        3779 :   m_gsi = gsi_after_labels (e1->dest);
     719                 :        3779 : }
     720                 :             : 
     721                 :             : /* Emit a full diamond,
     722                 :             :        if (COND)
     723                 :             :          /\
     724                 :             :         /  \
     725                 :             :        /    \
     726                 :             :    new_bb1 new_bb2
     727                 :             :        \    /
     728                 :             :         \  /
     729                 :             :          \/
     730                 :             :    or if (COND) new_bb2; else new_bb1;
     731                 :             :    PROB is the probability that the condition is true.
     732                 :             :    Updates m_gsi to start of new_bb2.
     733                 :             :    Sets EDGE_TRUE to edge from new_bb1 to successor and
     734                 :             :    EDGE_FALSE to the EDGE_FALSE_VALUE edge from if (COND) bb.  */
     735                 :             : 
     736                 :             : void
     737                 :          69 : bitint_large_huge::if_then_else (gimple *cond, profile_probability prob,
     738                 :             :                                  edge &edge_true, edge &edge_false)
     739                 :             : {
     740                 :          69 :   insert_before (cond);
     741                 :          69 :   edge e1 = split_block (gsi_bb (m_gsi), cond);
     742                 :          69 :   edge e2 = split_block (e1->dest, (gimple *) NULL);
     743                 :          69 :   basic_block bb = create_empty_bb (e1->dest);
     744                 :          69 :   add_bb_to_loop (bb, e1->dest->loop_father);
     745                 :          69 :   edge e3 = make_edge (e1->src, bb, EDGE_TRUE_VALUE);
     746                 :          69 :   e1->flags = EDGE_FALSE_VALUE;
     747                 :          69 :   e3->probability = prob;
     748                 :          69 :   e1->probability = prob.invert ();
     749                 :          69 :   bb->count = e1->src->count.apply_probability (prob);
     750                 :          69 :   set_immediate_dominator (CDI_DOMINATORS, bb, e1->src);
     751                 :          69 :   set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src);
     752                 :          69 :   edge_true = make_single_succ_edge (bb, e2->dest, EDGE_FALLTHRU);
     753                 :          69 :   edge_false = e2;
     754                 :          69 :   m_gsi = gsi_after_labels (bb);
     755                 :          69 : }
     756                 :             : 
     757                 :             : /* Emit a half diamond with full diamond in it
     758                 :             :    if (COND1)
     759                 :             :      |\
     760                 :             :      | \
     761                 :             :      |  \
     762                 :             :      | if (COND2)
     763                 :             :      |    /  \
     764                 :             :      |   /    \
     765                 :             :      |new_bb1 new_bb2
     766                 :             :      |   |    /
     767                 :             :      \   |   /
     768                 :             :       \  |  /
     769                 :             :        \ | /
     770                 :             :         \|/
     771                 :             :    or if (COND1) { if (COND2) new_bb2; else new_bb1; }
     772                 :             :    PROB1 is the probability that the condition 1 is true.
     773                 :             :    PROB2 is the probability that the condition 2 is true.
     774                 :             :    Updates m_gsi to start of new_bb1.
     775                 :             :    Sets EDGE_TRUE_TRUE to edge from new_bb2 to successor,
     776                 :             :    EDGE_TRUE_FALSE to edge from new_bb1 to successor and
     777                 :             :    EDGE_FALSE to the EDGE_FALSE_VALUE edge from if (COND1) bb.
     778                 :             :    If COND2 is NULL, this is equivalent to
     779                 :             :    if_then (COND1, PROB1, EDGE_TRUE_FALSE, EDGE_FALSE);
     780                 :             :    EDGE_TRUE_TRUE = NULL;  */
     781                 :             : 
     782                 :             : void
     783                 :        1827 : bitint_large_huge::if_then_if_then_else (gimple *cond1, gimple *cond2,
     784                 :             :                                          profile_probability prob1,
     785                 :             :                                          profile_probability prob2,
     786                 :             :                                          edge &edge_true_true,
     787                 :             :                                          edge &edge_true_false,
     788                 :             :                                          edge &edge_false)
     789                 :             : {
     790                 :        1827 :   edge e2, e3, e4 = NULL;
     791                 :        1827 :   if_then (cond1, prob1, e2, e3);
     792                 :        1827 :   if (cond2 == NULL)
     793                 :             :     {
     794                 :        1159 :       edge_true_true = NULL;
     795                 :        1159 :       edge_true_false = e2;
     796                 :        1159 :       edge_false = e3;
     797                 :        1159 :       return;
     798                 :             :     }
     799                 :         668 :   insert_before (cond2);
     800                 :         668 :   e2 = split_block (gsi_bb (m_gsi), cond2);
     801                 :         668 :   basic_block bb = create_empty_bb (e2->dest);
     802                 :         668 :   add_bb_to_loop (bb, e2->dest->loop_father);
     803                 :         668 :   e4 = make_edge (e2->src, bb, EDGE_TRUE_VALUE);
     804                 :         668 :   set_immediate_dominator (CDI_DOMINATORS, bb, e2->src);
     805                 :         668 :   e4->probability = prob2;
     806                 :         668 :   e2->flags = EDGE_FALSE_VALUE;
     807                 :         668 :   e2->probability = prob2.invert ();
     808                 :         668 :   bb->count = e2->src->count.apply_probability (prob2);
     809                 :         668 :   e4 = make_single_succ_edge (bb, e3->dest, EDGE_FALLTHRU);
     810                 :         668 :   e2 = find_edge (e2->dest, e3->dest);
     811                 :         668 :   edge_true_true = e4;
     812                 :         668 :   edge_true_false = e2;
     813                 :         668 :   edge_false = e3;
     814                 :         668 :   m_gsi = gsi_after_labels (e2->src);
     815                 :             : }
     816                 :             : 
     817                 :             : /* Emit code to access limb IDX from OP.  */
     818                 :             : 
     819                 :             : tree
     820                 :      105486 : bitint_large_huge::handle_operand (tree op, tree idx)
     821                 :             : {
     822                 :      105486 :   switch (TREE_CODE (op))
     823                 :             :     {
     824                 :       72412 :     case SSA_NAME:
     825                 :       72412 :       if (m_names == NULL
     826                 :       72412 :           || !bitmap_bit_p (m_names, SSA_NAME_VERSION (op)))
     827                 :             :         {
     828                 :       13365 :           if (SSA_NAME_IS_DEFAULT_DEF (op))
     829                 :             :             {
     830                 :           5 :               if (m_first)
     831                 :             :                 {
     832                 :           2 :                   tree v = create_tmp_reg (m_limb_type);
     833                 :           2 :                   if (SSA_NAME_VAR (op) && VAR_P (SSA_NAME_VAR (op)))
     834                 :             :                     {
     835                 :           2 :                       DECL_NAME (v) = DECL_NAME (SSA_NAME_VAR (op));
     836                 :           2 :                       DECL_SOURCE_LOCATION (v)
     837                 :           2 :                         = DECL_SOURCE_LOCATION (SSA_NAME_VAR (op));
     838                 :             :                     }
     839                 :           2 :                   v = get_or_create_ssa_default_def (cfun, v);
     840                 :           2 :                   m_data.safe_push (v);
     841                 :             :                 }
     842                 :           5 :               tree ret = m_data[m_data_cnt];
     843                 :           5 :               m_data_cnt++;
     844                 :           5 :               if (tree_fits_uhwi_p (idx))
     845                 :             :                 {
     846                 :           3 :                   tree type = limb_access_type (TREE_TYPE (op), idx);
     847                 :           3 :                   ret = add_cast (type, ret);
     848                 :             :                 }
     849                 :           5 :               return ret;
     850                 :             :             }
     851                 :       13360 :           location_t loc_save = m_loc;
     852                 :       13360 :           m_loc = gimple_location (SSA_NAME_DEF_STMT (op));
     853                 :       13360 :           tree ret = handle_stmt (SSA_NAME_DEF_STMT (op), idx);
     854                 :       13360 :           m_loc = loc_save;
     855                 :       13360 :           return ret;
     856                 :             :         }
     857                 :       59047 :       int p;
     858                 :       59047 :       gimple *g;
     859                 :       59047 :       tree t;
     860                 :       59047 :       p = var_to_partition (m_map, op);
     861                 :       59047 :       gcc_assert (m_vars[p] != NULL_TREE);
     862                 :       59047 :       t = limb_access (TREE_TYPE (op), m_vars[p], idx, false);
     863                 :       59047 :       g = gimple_build_assign (make_ssa_name (TREE_TYPE (t)), t);
     864                 :       59047 :       insert_before (g);
     865                 :       59047 :       t = gimple_assign_lhs (g);
     866                 :       59047 :       if (m_first
     867                 :       21401 :           && m_single_use_names
     868                 :       20699 :           && m_vars[p] != m_lhs
     869                 :       20606 :           && m_after_stmt
     870                 :       67295 :           && bitmap_bit_p (m_single_use_names, SSA_NAME_VERSION (op)))
     871                 :             :         {
     872                 :        8053 :           tree clobber = build_clobber (TREE_TYPE (m_vars[p]),
     873                 :             :                                         CLOBBER_STORAGE_END);
     874                 :        8053 :           g = gimple_build_assign (m_vars[p], clobber);
     875                 :        8053 :           gimple_stmt_iterator gsi = gsi_for_stmt (m_after_stmt);
     876                 :        8053 :           gsi_insert_after (&gsi, g, GSI_SAME_STMT);
     877                 :             :         }
     878                 :             :       return t;
     879                 :       33074 :     case INTEGER_CST:
     880                 :       33074 :       if (tree_fits_uhwi_p (idx))
     881                 :             :         {
     882                 :       22974 :           tree c, type = limb_access_type (TREE_TYPE (op), idx);
     883                 :       22974 :           unsigned HOST_WIDE_INT i = tree_to_uhwi (idx);
     884                 :       22974 :           if (m_first)
     885                 :             :             {
     886                 :        6061 :               m_data.safe_push (NULL_TREE);
     887                 :        6061 :               m_data.safe_push (NULL_TREE);
     888                 :             :             }
     889                 :       22974 :           if (limb_prec != HOST_BITS_PER_WIDE_INT)
     890                 :             :             {
     891                 :           0 :               wide_int w = wi::rshift (wi::to_wide (op), i * limb_prec,
     892                 :           0 :                                        TYPE_SIGN (TREE_TYPE (op)));
     893                 :           0 :               c = wide_int_to_tree (type,
     894                 :           0 :                                     wide_int::from (w, TYPE_PRECISION (type),
     895                 :             :                                                     UNSIGNED));
     896                 :           0 :             }
     897                 :       22974 :           else if (i >= TREE_INT_CST_EXT_NUNITS (op))
     898                 :        7326 :             c = build_int_cst (type,
     899                 :       13013 :                                tree_int_cst_sgn (op) < 0 ? -1 : 0);
     900                 :             :           else
     901                 :       15648 :             c = build_int_cst (type, TREE_INT_CST_ELT (op, i));
     902                 :       22974 :           m_data_cnt += 2;
     903                 :       22974 :           return c;
     904                 :             :         }
     905                 :       10100 :       if (m_first
     906                 :       10100 :           || (m_data[m_data_cnt] == NULL_TREE
     907                 :         150 :               && m_data[m_data_cnt + 1] == NULL_TREE))
     908                 :             :         {
     909                 :        5092 :           unsigned int prec = TYPE_PRECISION (TREE_TYPE (op));
     910                 :        5092 :           unsigned int rem = prec % ((m_upwards_2limb ? 2 : 1) * limb_prec);
     911                 :        5092 :           int ext;
     912                 :        5092 :           unsigned min_prec = bitint_min_cst_precision (op, ext);
     913                 :        5092 :           if (m_first)
     914                 :             :             {
     915                 :        4942 :               m_data.safe_push (NULL_TREE);
     916                 :        4942 :               m_data.safe_push (NULL_TREE);
     917                 :             :             }
     918                 :        5092 :           if (integer_zerop (op))
     919                 :             :             {
     920                 :         826 :               tree c = build_zero_cst (m_limb_type);
     921                 :         826 :               m_data[m_data_cnt] = c;
     922                 :         826 :               m_data[m_data_cnt + 1] = c;
     923                 :             :             }
     924                 :        4266 :           else if (integer_all_onesp (op))
     925                 :             :             {
     926                 :         661 :               tree c = build_all_ones_cst (m_limb_type);
     927                 :         661 :               m_data[m_data_cnt] = c;
     928                 :         661 :               m_data[m_data_cnt + 1] = c;
     929                 :             :             }
     930                 :        3605 :           else if (m_upwards_2limb && min_prec <= (unsigned) limb_prec)
     931                 :             :             {
     932                 :             :               /* Single limb constant.  Use a phi with that limb from
     933                 :             :                  the preheader edge and 0 or -1 constant from the other edge
     934                 :             :                  and for the second limb in the loop.  */
     935                 :         852 :               tree out;
     936                 :         852 :               gcc_assert (m_first);
     937                 :         852 :               m_data.pop ();
     938                 :         852 :               m_data.pop ();
     939                 :         852 :               prepare_data_in_out (fold_convert (m_limb_type, op), idx, &out,
     940                 :             :                                    build_int_cst (m_limb_type, ext));
     941                 :         852 :             }
     942                 :        2753 :           else if (min_prec > prec - rem - 2 * limb_prec)
     943                 :             :             {
     944                 :             :               /* Constant which has enough significant bits that it isn't
     945                 :             :                  worth trying to save .rodata space by extending from smaller
     946                 :             :                  number.  */
     947                 :        2293 :               tree type;
     948                 :        2293 :               if (m_var_msb)
     949                 :          24 :                 type = TREE_TYPE (op);
     950                 :             :               else
     951                 :             :                 /* If we have a guarantee the most significant partial limb
     952                 :             :                    (if any) will be only accessed through handle_operand
     953                 :             :                    with INTEGER_CST idx, we don't need to include the partial
     954                 :             :                    limb in .rodata.  */
     955                 :        2269 :                 type = build_bitint_type (prec - rem, 1);
     956                 :        2293 :               tree c = tree_output_constant_def (fold_convert (type, op));
     957                 :        2293 :               m_data[m_data_cnt] = c;
     958                 :        2293 :               m_data[m_data_cnt + 1] = NULL_TREE;
     959                 :             :             }
     960                 :         460 :           else if (m_upwards_2limb)
     961                 :             :             {
     962                 :             :               /* Constant with smaller number of bits.  Trade conditional
     963                 :             :                  code for .rodata space by extending from smaller number.  */
     964                 :         393 :               min_prec = CEIL (min_prec, 2 * limb_prec) * (2 * limb_prec);
     965                 :         393 :               tree type = build_bitint_type (min_prec, 1);
     966                 :         393 :               tree c = tree_output_constant_def (fold_convert (type, op));
     967                 :         393 :               tree idx2 = make_ssa_name (sizetype);
     968                 :         393 :               g = gimple_build_assign (idx2, PLUS_EXPR, idx, size_one_node);
     969                 :         393 :               insert_before (g);
     970                 :         393 :               g = gimple_build_cond (LT_EXPR, idx,
     971                 :         393 :                                      size_int (min_prec / limb_prec),
     972                 :             :                                      NULL_TREE, NULL_TREE);
     973                 :         393 :               edge edge_true, edge_false;
     974                 :         786 :               if_then (g, (min_prec >= (prec - rem) / 2
     975                 :         264 :                            ? profile_probability::likely ()
     976                 :         129 :                            : profile_probability::unlikely ()),
     977                 :             :                        edge_true, edge_false);
     978                 :         393 :               tree c1 = limb_access (TREE_TYPE (op), c, idx, false);
     979                 :         393 :               g = gimple_build_assign (make_ssa_name (TREE_TYPE (c1)), c1);
     980                 :         393 :               insert_before (g);
     981                 :         393 :               c1 = gimple_assign_lhs (g);
     982                 :         393 :               tree c2 = limb_access (TREE_TYPE (op), c, idx2, false);
     983                 :         393 :               g = gimple_build_assign (make_ssa_name (TREE_TYPE (c2)), c2);
     984                 :         393 :               insert_before (g);
     985                 :         393 :               c2 = gimple_assign_lhs (g);
     986                 :         393 :               tree c3 = build_int_cst (m_limb_type, ext);
     987                 :         393 :               m_gsi = gsi_after_labels (edge_true->dest);
     988                 :         393 :               m_data[m_data_cnt] = make_ssa_name (m_limb_type);
     989                 :         393 :               m_data[m_data_cnt + 1] = make_ssa_name (m_limb_type);
     990                 :         393 :               gphi *phi = create_phi_node (m_data[m_data_cnt],
     991                 :             :                                            edge_true->dest);
     992                 :         393 :               add_phi_arg (phi, c1, edge_true, UNKNOWN_LOCATION);
     993                 :         393 :               add_phi_arg (phi, c3, edge_false, UNKNOWN_LOCATION);
     994                 :         393 :               phi = create_phi_node (m_data[m_data_cnt + 1], edge_true->dest);
     995                 :         393 :               add_phi_arg (phi, c2, edge_true, UNKNOWN_LOCATION);
     996                 :         393 :               add_phi_arg (phi, c3, edge_false, UNKNOWN_LOCATION);
     997                 :             :             }
     998                 :             :           else
     999                 :             :             {
    1000                 :             :               /* Constant with smaller number of bits.  Trade conditional
    1001                 :             :                  code for .rodata space by extending from smaller number.
    1002                 :             :                  Version for loops with random access to the limbs or
    1003                 :             :                  downwards loops.  */
    1004                 :          67 :               min_prec = CEIL (min_prec, limb_prec) * limb_prec;
    1005                 :          67 :               tree c;
    1006                 :          67 :               if (min_prec <= (unsigned) limb_prec)
    1007                 :          22 :                 c = fold_convert (m_limb_type, op);
    1008                 :             :               else
    1009                 :             :                 {
    1010                 :          45 :                   tree type = build_bitint_type (min_prec, 1);
    1011                 :          45 :                   c = tree_output_constant_def (fold_convert (type, op));
    1012                 :             :                 }
    1013                 :          67 :               m_data[m_data_cnt] = c;
    1014                 :          67 :               m_data[m_data_cnt + 1] = integer_type_node;
    1015                 :             :             }
    1016                 :        5092 :           t = m_data[m_data_cnt];
    1017                 :        5092 :           if (m_data[m_data_cnt + 1] == NULL_TREE)
    1018                 :             :             {
    1019                 :        2293 :               t = limb_access (TREE_TYPE (op), t, idx, false);
    1020                 :        2293 :               g = gimple_build_assign (make_ssa_name (TREE_TYPE (t)), t);
    1021                 :        2293 :               insert_before (g);
    1022                 :        2293 :               t = gimple_assign_lhs (g);
    1023                 :             :             }
    1024                 :             :         }
    1025                 :        5008 :       else if (m_data[m_data_cnt + 1] == NULL_TREE)
    1026                 :             :         {
    1027                 :        2236 :           t = limb_access (TREE_TYPE (op), m_data[m_data_cnt], idx, false);
    1028                 :        2236 :           g = gimple_build_assign (make_ssa_name (TREE_TYPE (t)), t);
    1029                 :        2236 :           insert_before (g);
    1030                 :        2236 :           t = gimple_assign_lhs (g);
    1031                 :             :         }
    1032                 :             :       else
    1033                 :             :         t = m_data[m_data_cnt + 1];
    1034                 :       10100 :       if (m_data[m_data_cnt + 1] == integer_type_node)
    1035                 :             :         {
    1036                 :         107 :           unsigned int prec = TYPE_PRECISION (TREE_TYPE (op));
    1037                 :         107 :           unsigned rem = prec % ((m_upwards_2limb ? 2 : 1) * limb_prec);
    1038                 :         107 :           int ext = wi::neg_p (wi::to_wide (op)) ? -1 : 0;
    1039                 :         107 :           tree c = m_data[m_data_cnt];
    1040                 :         107 :           unsigned min_prec = TYPE_PRECISION (TREE_TYPE (c));
    1041                 :         107 :           g = gimple_build_cond (LT_EXPR, idx,
    1042                 :         107 :                                  size_int (min_prec / limb_prec),
    1043                 :             :                                  NULL_TREE, NULL_TREE);
    1044                 :         107 :           edge edge_true, edge_false;
    1045                 :         214 :           if_then (g, (min_prec >= (prec - rem) / 2
    1046                 :          20 :                        ? profile_probability::likely ()
    1047                 :          87 :                        : profile_probability::unlikely ()),
    1048                 :             :                    edge_true, edge_false);
    1049                 :         107 :           if (min_prec > (unsigned) limb_prec)
    1050                 :             :             {
    1051                 :          61 :               c = limb_access (TREE_TYPE (op), c, idx, false);
    1052                 :          61 :               g = gimple_build_assign (make_ssa_name (TREE_TYPE (c)), c);
    1053                 :          61 :               insert_before (g);
    1054                 :          61 :               c = gimple_assign_lhs (g);
    1055                 :             :             }
    1056                 :         107 :           tree c2 = build_int_cst (m_limb_type, ext);
    1057                 :         107 :           m_gsi = gsi_after_labels (edge_true->dest);
    1058                 :         107 :           t = make_ssa_name (m_limb_type);
    1059                 :         107 :           gphi *phi = create_phi_node (t, edge_true->dest);
    1060                 :         107 :           add_phi_arg (phi, c, edge_true, UNKNOWN_LOCATION);
    1061                 :         107 :           add_phi_arg (phi, c2, edge_false, UNKNOWN_LOCATION);
    1062                 :             :         }
    1063                 :       10100 :       m_data_cnt += 2;
    1064                 :       10100 :       return t;
    1065                 :           0 :     default:
    1066                 :           0 :       gcc_unreachable ();
    1067                 :             :     }
    1068                 :             : }
    1069                 :             : 
    1070                 :             : /* Helper method, add a PHI node with VAL from preheader edge if
    1071                 :             :    inside of a loop and m_first.  Keep state in a pair of m_data
    1072                 :             :    elements.  If VAL_OUT is non-NULL, use that as PHI argument from
    1073                 :             :    the latch edge, otherwise create a new SSA_NAME for it and let
    1074                 :             :    caller initialize it.  */
    1075                 :             : 
    1076                 :             : tree
    1077                 :       14713 : bitint_large_huge::prepare_data_in_out (tree val, tree idx, tree *data_out,
    1078                 :             :                                         tree val_out)
    1079                 :             : {
    1080                 :       14713 :   if (!m_first)
    1081                 :             :     {
    1082                 :        8841 :       *data_out = tree_fits_uhwi_p (idx) ? NULL_TREE : m_data[m_data_cnt + 1];
    1083                 :        8841 :       return m_data[m_data_cnt];
    1084                 :             :     }
    1085                 :             : 
    1086                 :        5872 :   *data_out = NULL_TREE;
    1087                 :        5872 :   if (tree_fits_uhwi_p (idx))
    1088                 :             :     {
    1089                 :        1937 :       m_data.safe_push (val);
    1090                 :        1937 :       m_data.safe_push (NULL_TREE);
    1091                 :        1937 :       return val;
    1092                 :             :     }
    1093                 :             : 
    1094                 :        3935 :   tree in = make_ssa_name (TREE_TYPE (val));
    1095                 :        3935 :   gphi *phi = create_phi_node (in, m_bb);
    1096                 :        3935 :   edge e1 = find_edge (m_preheader_bb, m_bb);
    1097                 :        3935 :   edge e2 = EDGE_PRED (m_bb, 0);
    1098                 :        3935 :   if (e1 == e2)
    1099                 :        3935 :     e2 = EDGE_PRED (m_bb, 1);
    1100                 :        3935 :   add_phi_arg (phi, val, e1, UNKNOWN_LOCATION);
    1101                 :        3935 :   tree out = val_out ? val_out : make_ssa_name (TREE_TYPE (val));
    1102                 :        3935 :   add_phi_arg (phi, out, e2, UNKNOWN_LOCATION);
    1103                 :        3935 :   m_data.safe_push (in);
    1104                 :        3935 :   m_data.safe_push (out);
    1105                 :        3935 :   return in;
    1106                 :             : }
    1107                 :             : 
    1108                 :             : /* Return VAL cast to TYPE.  If VAL is INTEGER_CST, just
    1109                 :             :    convert it without emitting any code, otherwise emit
    1110                 :             :    the conversion statement before the current location.  */
    1111                 :             : 
    1112                 :             : tree
    1113                 :       36021 : bitint_large_huge::add_cast (tree type, tree val)
    1114                 :             : {
    1115                 :       36021 :   if (TREE_CODE (val) == INTEGER_CST)
    1116                 :        4502 :     return fold_convert (type, val);
    1117                 :             : 
    1118                 :       31519 :   tree lhs = make_ssa_name (type);
    1119                 :       31519 :   gimple *g = gimple_build_assign (lhs, NOP_EXPR, val);
    1120                 :       31519 :   insert_before (g);
    1121                 :       31519 :   return lhs;
    1122                 :             : }
    1123                 :             : 
    1124                 :             : /* Helper of handle_stmt method, handle PLUS_EXPR or MINUS_EXPR.  */
    1125                 :             : 
    1126                 :             : tree
    1127                 :       12526 : bitint_large_huge::handle_plus_minus (tree_code code, tree rhs1, tree rhs2,
    1128                 :             :                                       tree idx)
    1129                 :             : {
    1130                 :       12526 :   tree lhs, data_out, ctype;
    1131                 :       12526 :   tree rhs1_type = TREE_TYPE (rhs1);
    1132                 :       12526 :   gimple *g;
    1133                 :       12526 :   tree data_in = prepare_data_in_out (build_zero_cst (m_limb_type), idx,
    1134                 :             :                                       &data_out);
    1135                 :             : 
    1136                 :       17998 :   if (optab_handler (code == PLUS_EXPR ? uaddc5_optab : usubc5_optab,
    1137                 :       12526 :                      TYPE_MODE (m_limb_type)) != CODE_FOR_nothing)
    1138                 :             :     {
    1139                 :       12526 :       ctype = build_complex_type (m_limb_type);
    1140                 :       12526 :       if (!types_compatible_p (rhs1_type, m_limb_type))
    1141                 :             :         {
    1142                 :         926 :           if (!TYPE_UNSIGNED (rhs1_type))
    1143                 :             :             {
    1144                 :         273 :               tree type = unsigned_type_for (rhs1_type);
    1145                 :         273 :               rhs1 = add_cast (type, rhs1);
    1146                 :         273 :               rhs2 = add_cast (type, rhs2);
    1147                 :             :             }
    1148                 :         926 :           rhs1 = add_cast (m_limb_type, rhs1);
    1149                 :         926 :           rhs2 = add_cast (m_limb_type, rhs2);
    1150                 :             :         }
    1151                 :       12526 :       lhs = make_ssa_name (ctype);
    1152                 :       17998 :       g = gimple_build_call_internal (code == PLUS_EXPR
    1153                 :             :                                       ? IFN_UADDC : IFN_USUBC,
    1154                 :             :                                       3, rhs1, rhs2, data_in);
    1155                 :       12526 :       gimple_call_set_lhs (g, lhs);
    1156                 :       12526 :       insert_before (g);
    1157                 :       12526 :       if (data_out == NULL_TREE)
    1158                 :       10535 :         data_out = make_ssa_name (m_limb_type);
    1159                 :       12526 :       g = gimple_build_assign (data_out, IMAGPART_EXPR,
    1160                 :             :                                build1 (IMAGPART_EXPR, m_limb_type, lhs));
    1161                 :       12526 :       insert_before (g);
    1162                 :             :     }
    1163                 :           0 :   else if (types_compatible_p (rhs1_type, m_limb_type))
    1164                 :             :     {
    1165                 :           0 :       ctype = build_complex_type (m_limb_type);
    1166                 :           0 :       lhs = make_ssa_name (ctype);
    1167                 :           0 :       g = gimple_build_call_internal (code == PLUS_EXPR
    1168                 :             :                                       ? IFN_ADD_OVERFLOW : IFN_SUB_OVERFLOW,
    1169                 :             :                                       2, rhs1, rhs2);
    1170                 :           0 :       gimple_call_set_lhs (g, lhs);
    1171                 :           0 :       insert_before (g);
    1172                 :           0 :       if (data_out == NULL_TREE)
    1173                 :           0 :         data_out = make_ssa_name (m_limb_type);
    1174                 :           0 :       if (!integer_zerop (data_in))
    1175                 :             :         {
    1176                 :           0 :           rhs1 = make_ssa_name (m_limb_type);
    1177                 :           0 :           g = gimple_build_assign (rhs1, REALPART_EXPR,
    1178                 :             :                                    build1 (REALPART_EXPR, m_limb_type, lhs));
    1179                 :           0 :           insert_before (g);
    1180                 :           0 :           rhs2 = make_ssa_name (m_limb_type);
    1181                 :           0 :           g = gimple_build_assign (rhs2, IMAGPART_EXPR,
    1182                 :             :                                    build1 (IMAGPART_EXPR, m_limb_type, lhs));
    1183                 :           0 :           insert_before (g);
    1184                 :           0 :           lhs = make_ssa_name (ctype);
    1185                 :           0 :           g = gimple_build_call_internal (code == PLUS_EXPR
    1186                 :             :                                           ? IFN_ADD_OVERFLOW
    1187                 :             :                                           : IFN_SUB_OVERFLOW,
    1188                 :             :                                           2, rhs1, data_in);
    1189                 :           0 :           gimple_call_set_lhs (g, lhs);
    1190                 :           0 :           insert_before (g);
    1191                 :           0 :           data_in = make_ssa_name (m_limb_type);
    1192                 :           0 :           g = gimple_build_assign (data_in, IMAGPART_EXPR,
    1193                 :             :                                    build1 (IMAGPART_EXPR, m_limb_type, lhs));
    1194                 :           0 :           insert_before (g);
    1195                 :           0 :           g = gimple_build_assign (data_out, PLUS_EXPR, rhs2, data_in);
    1196                 :           0 :           insert_before (g);
    1197                 :             :         }
    1198                 :             :       else
    1199                 :             :         {
    1200                 :           0 :           g = gimple_build_assign (data_out, IMAGPART_EXPR,
    1201                 :             :                                    build1 (IMAGPART_EXPR, m_limb_type, lhs));
    1202                 :           0 :           insert_before (g);
    1203                 :             :         }
    1204                 :             :     }
    1205                 :             :   else
    1206                 :             :     {
    1207                 :           0 :       tree in = add_cast (rhs1_type, data_in);
    1208                 :           0 :       lhs = make_ssa_name (rhs1_type);
    1209                 :           0 :       g = gimple_build_assign (lhs, code, rhs1, rhs2);
    1210                 :           0 :       insert_before (g);
    1211                 :           0 :       rhs1 = make_ssa_name (rhs1_type);
    1212                 :           0 :       g = gimple_build_assign (rhs1, code, lhs, in);
    1213                 :           0 :       insert_before (g);
    1214                 :           0 :       m_data[m_data_cnt] = NULL_TREE;
    1215                 :           0 :       m_data_cnt += 2;
    1216                 :           0 :       return rhs1;
    1217                 :             :     }
    1218                 :       12526 :   rhs1 = make_ssa_name (m_limb_type);
    1219                 :       12526 :   g = gimple_build_assign (rhs1, REALPART_EXPR,
    1220                 :             :                            build1 (REALPART_EXPR, m_limb_type, lhs));
    1221                 :       12526 :   insert_before (g);
    1222                 :       12526 :   if (!types_compatible_p (rhs1_type, m_limb_type))
    1223                 :         926 :     rhs1 = add_cast (rhs1_type, rhs1);
    1224                 :       12526 :   m_data[m_data_cnt] = data_out;
    1225                 :       12526 :   m_data_cnt += 2;
    1226                 :       12526 :   return rhs1;
    1227                 :             : }
    1228                 :             : 
    1229                 :             : /* Helper function for handle_stmt method, handle LSHIFT_EXPR by
    1230                 :             :    count in [0, limb_prec - 1] range.  */
    1231                 :             : 
    1232                 :             : tree
    1233                 :         133 : bitint_large_huge::handle_lshift (tree rhs1, tree rhs2, tree idx)
    1234                 :             : {
    1235                 :         133 :   unsigned HOST_WIDE_INT cnt = tree_to_uhwi (rhs2);
    1236                 :         133 :   gcc_checking_assert (cnt < (unsigned) limb_prec);
    1237                 :         133 :   if (cnt == 0)
    1238                 :             :     return rhs1;
    1239                 :             : 
    1240                 :         133 :   tree lhs, data_out, rhs1_type = TREE_TYPE (rhs1);
    1241                 :         133 :   gimple *g;
    1242                 :         133 :   tree data_in = prepare_data_in_out (build_zero_cst (m_limb_type), idx,
    1243                 :             :                                       &data_out);
    1244                 :             : 
    1245                 :         133 :   if (!integer_zerop (data_in))
    1246                 :             :     {
    1247                 :         119 :       lhs = make_ssa_name (m_limb_type);
    1248                 :         119 :       g = gimple_build_assign (lhs, RSHIFT_EXPR, data_in,
    1249                 :             :                                build_int_cst (unsigned_type_node,
    1250                 :         119 :                                               limb_prec - cnt));
    1251                 :         119 :       insert_before (g);
    1252                 :         119 :       if (!types_compatible_p (rhs1_type, m_limb_type))
    1253                 :          29 :         lhs = add_cast (rhs1_type, lhs);
    1254                 :             :       data_in = lhs;
    1255                 :             :     }
    1256                 :         133 :   if (types_compatible_p (rhs1_type, m_limb_type))
    1257                 :             :     {
    1258                 :         104 :       if (data_out == NULL_TREE)
    1259                 :          73 :         data_out = make_ssa_name (m_limb_type);
    1260                 :         104 :       g = gimple_build_assign (data_out, rhs1);
    1261                 :         104 :       insert_before (g);
    1262                 :             :     }
    1263                 :         133 :   if (cnt < (unsigned) TYPE_PRECISION (rhs1_type))
    1264                 :             :     {
    1265                 :         123 :       lhs = make_ssa_name (rhs1_type);
    1266                 :         123 :       g = gimple_build_assign (lhs, LSHIFT_EXPR, rhs1, rhs2);
    1267                 :         123 :       insert_before (g);
    1268                 :         123 :       if (!integer_zerop (data_in))
    1269                 :             :         {
    1270                 :         109 :           rhs1 = lhs;
    1271                 :         109 :           lhs = make_ssa_name (rhs1_type);
    1272                 :         109 :           g = gimple_build_assign (lhs, BIT_IOR_EXPR, rhs1, data_in);
    1273                 :         109 :           insert_before (g);
    1274                 :             :         }
    1275                 :             :     }
    1276                 :             :   else
    1277                 :             :     lhs = data_in;
    1278                 :         133 :   m_data[m_data_cnt] = data_out;
    1279                 :         133 :   m_data_cnt += 2;
    1280                 :         133 :   return lhs;
    1281                 :             : }
    1282                 :             : 
    1283                 :             : /* Helper function for handle_stmt method, handle an integral
    1284                 :             :    to integral conversion.  */
    1285                 :             : 
    1286                 :             : tree
    1287                 :        7065 : bitint_large_huge::handle_cast (tree lhs_type, tree rhs1, tree idx)
    1288                 :             : {
    1289                 :        7065 :   tree rhs_type = TREE_TYPE (rhs1);
    1290                 :        7065 :   gimple *g;
    1291                 :        7065 :   if ((TREE_CODE (rhs1) == SSA_NAME || TREE_CODE (rhs1) == INTEGER_CST)
    1292                 :        7065 :       && TREE_CODE (lhs_type) == BITINT_TYPE
    1293                 :        7065 :       && TREE_CODE (rhs_type) == BITINT_TYPE
    1294                 :        6137 :       && bitint_precision_kind (lhs_type) >= bitint_prec_large
    1295                 :       13202 :       && bitint_precision_kind (rhs_type) >= bitint_prec_large)
    1296                 :             :     {
    1297                 :        5602 :       if (TYPE_PRECISION (rhs_type) >= TYPE_PRECISION (lhs_type)
    1298                 :             :           /* If lhs has bigger precision than rhs, we can use
    1299                 :             :              the simple case only if there is a guarantee that
    1300                 :             :              the most significant limb is handled in straight
    1301                 :             :              line code.  If m_var_msb (on left shifts) or
    1302                 :             :              if m_upwards_2limb * limb_prec is equal to
    1303                 :             :              lhs precision or if not m_upwards_2limb and lhs_type
    1304                 :             :              has precision which is multiple of limb_prec that is
    1305                 :             :              not the case.  */
    1306                 :        5602 :           || (!m_var_msb
    1307                 :        1267 :               && (CEIL (TYPE_PRECISION (lhs_type), limb_prec)
    1308                 :        1267 :                   == CEIL (TYPE_PRECISION (rhs_type), limb_prec))
    1309                 :         312 :               && ((!m_upwards_2limb
    1310                 :         170 :                    && (TYPE_PRECISION (lhs_type) % limb_prec != 0))
    1311                 :         221 :                   || (m_upwards_2limb
    1312                 :         284 :                       && (m_upwards_2limb * limb_prec
    1313                 :         142 :                           < TYPE_PRECISION (lhs_type))))))
    1314                 :             :         {
    1315                 :        4558 :           rhs1 = handle_operand (rhs1, idx);
    1316                 :        4558 :           if (tree_fits_uhwi_p (idx))
    1317                 :             :             {
    1318                 :        2335 :               tree type = limb_access_type (lhs_type, idx);
    1319                 :        2335 :               if (!types_compatible_p (type, TREE_TYPE (rhs1)))
    1320                 :        1215 :                 rhs1 = add_cast (type, rhs1);
    1321                 :             :             }
    1322                 :        4558 :           return rhs1;
    1323                 :             :         }
    1324                 :        1044 :       tree t;
    1325                 :             :       /* Indexes lower than this don't need any special processing.  */
    1326                 :        1044 :       unsigned low = ((unsigned) TYPE_PRECISION (rhs_type)
    1327                 :        1044 :                       - !TYPE_UNSIGNED (rhs_type)) / limb_prec;
    1328                 :             :       /* Indexes >= than this always contain an extension.  */
    1329                 :        1044 :       unsigned high = CEIL ((unsigned) TYPE_PRECISION (rhs_type), limb_prec);
    1330                 :        1044 :       bool save_first = m_first;
    1331                 :        1044 :       if (m_first)
    1332                 :             :         {
    1333                 :         343 :           m_data.safe_push (NULL_TREE);
    1334                 :         343 :           m_data.safe_push (NULL_TREE);
    1335                 :         343 :           m_data.safe_push (NULL_TREE);
    1336                 :         343 :           if (TYPE_UNSIGNED (rhs_type))
    1337                 :             :             /* No need to keep state between iterations.  */
    1338                 :             :             ;
    1339                 :         160 :           else if (m_upwards && !m_upwards_2limb)
    1340                 :             :             /* We need to keep state between iterations, but
    1341                 :             :                not within any loop, everything is straight line
    1342                 :             :                code with only increasing indexes.  */
    1343                 :             :             ;
    1344                 :         126 :           else if (!m_upwards_2limb)
    1345                 :             :             {
    1346                 :           3 :               unsigned save_data_cnt = m_data_cnt;
    1347                 :           3 :               gimple_stmt_iterator save_gsi = m_gsi;
    1348                 :           3 :               m_gsi = m_init_gsi;
    1349                 :           3 :               if (gsi_end_p (m_gsi))
    1350                 :           0 :                 m_gsi = gsi_after_labels (gsi_bb (m_gsi));
    1351                 :             :               else
    1352                 :           3 :                 gsi_next (&m_gsi);
    1353                 :           3 :               m_data_cnt = save_data_cnt + 3;
    1354                 :           3 :               t = handle_operand (rhs1, size_int (low));
    1355                 :           3 :               m_first = false;
    1356                 :           3 :               m_data[save_data_cnt + 2]
    1357                 :           3 :                 = build_int_cst (NULL_TREE, m_data_cnt);
    1358                 :           3 :               m_data_cnt = save_data_cnt;
    1359                 :           3 :               t = add_cast (signed_type_for (m_limb_type), t);
    1360                 :           3 :               tree lpm1 = build_int_cst (unsigned_type_node, limb_prec - 1);
    1361                 :           3 :               tree n = make_ssa_name (TREE_TYPE (t));
    1362                 :           3 :               g = gimple_build_assign (n, RSHIFT_EXPR, t, lpm1);
    1363                 :           3 :               insert_before (g);
    1364                 :           3 :               m_data[save_data_cnt + 1] = add_cast (m_limb_type, n);
    1365                 :           3 :               m_init_gsi = m_gsi;
    1366                 :           3 :               if (gsi_end_p (m_init_gsi))
    1367                 :           0 :                 m_init_gsi = gsi_last_bb (gsi_bb (m_init_gsi));
    1368                 :             :               else
    1369                 :           3 :                 gsi_prev (&m_init_gsi);
    1370                 :           3 :               m_gsi = save_gsi;
    1371                 :             :             }
    1372                 :         123 :           else if (m_upwards_2limb * limb_prec < TYPE_PRECISION (rhs_type))
    1373                 :             :             /* We need to keep state between iterations, but
    1374                 :             :                fortunately not within the loop, only afterwards.  */
    1375                 :             :             ;
    1376                 :             :           else
    1377                 :             :             {
    1378                 :         120 :               tree out;
    1379                 :         120 :               m_data.truncate (m_data_cnt);
    1380                 :         120 :               prepare_data_in_out (build_zero_cst (m_limb_type), idx, &out);
    1381                 :         120 :               m_data.safe_push (NULL_TREE);
    1382                 :             :             }
    1383                 :             :         }
    1384                 :             : 
    1385                 :        1044 :       unsigned save_data_cnt = m_data_cnt;
    1386                 :        1044 :       m_data_cnt += 3;
    1387                 :        1044 :       if (!tree_fits_uhwi_p (idx))
    1388                 :             :         {
    1389                 :         566 :           if (m_upwards_2limb
    1390                 :         548 :               && low >= m_upwards_2limb - m_first)
    1391                 :             :             {
    1392                 :         140 :               rhs1 = handle_operand (rhs1, idx);
    1393                 :         140 :               if (m_first)
    1394                 :         115 :                 m_data[save_data_cnt + 2]
    1395                 :         230 :                   = build_int_cst (NULL_TREE, m_data_cnt);
    1396                 :         140 :               m_first = save_first;
    1397                 :         140 :               return rhs1;
    1398                 :             :             }
    1399                 :        1069 :           bool single_comparison
    1400                 :         426 :             = low == high || (m_upwards_2limb && (low & 1) == m_first);
    1401                 :         217 :           tree idxc = idx;
    1402                 :         217 :           if (!single_comparison
    1403                 :         217 :               && m_upwards_2limb
    1404                 :         199 :               && !m_first
    1405                 :          98 :               && low + 1 == m_upwards_2limb)
    1406                 :             :             /* In this case we know that idx <= low always,
    1407                 :             :                so effectively we just needs a single comparison,
    1408                 :             :                idx < low or idx == low, but we'd need to emit different
    1409                 :             :                code for the 2 branches than single_comparison normally
    1410                 :             :                emits.  So, instead of special-casing that, emit a
    1411                 :             :                low <= low comparison which cfg cleanup will clean up
    1412                 :             :                at the end of the pass.  */
    1413                 :          76 :             idxc = size_int (low);
    1414                 :         643 :           g = gimple_build_cond (single_comparison ? LT_EXPR : LE_EXPR,
    1415                 :             :                                  idxc, size_int (low), NULL_TREE, NULL_TREE);
    1416                 :         426 :           edge edge_true_true, edge_true_false, edge_false;
    1417                 :         643 :           if_then_if_then_else (g, (single_comparison ? NULL
    1418                 :         217 :                                     : gimple_build_cond (EQ_EXPR, idx,
    1419                 :             :                                                          size_int (low),
    1420                 :             :                                                          NULL_TREE,
    1421                 :             :                                                          NULL_TREE)),
    1422                 :             :                                 profile_probability::likely (),
    1423                 :             :                                 profile_probability::unlikely (),
    1424                 :             :                                 edge_true_true, edge_true_false, edge_false);
    1425                 :         426 :           bool save_cast_conditional = m_cast_conditional;
    1426                 :         426 :           m_cast_conditional = true;
    1427                 :         426 :           m_bitfld_load = 0;
    1428                 :         426 :           tree t1 = handle_operand (rhs1, idx), t2 = NULL_TREE;
    1429                 :         426 :           if (m_first)
    1430                 :         163 :             m_data[save_data_cnt + 2]
    1431                 :         326 :               = build_int_cst (NULL_TREE, m_data_cnt);
    1432                 :         426 :           tree ext = NULL_TREE;
    1433                 :         426 :           tree bitfld = NULL_TREE;
    1434                 :         426 :           if (!single_comparison)
    1435                 :             :             {
    1436                 :         217 :               m_gsi = gsi_after_labels (edge_true_true->src);
    1437                 :         217 :               m_first = false;
    1438                 :         217 :               m_data_cnt = save_data_cnt + 3;
    1439                 :         217 :               if (m_bitfld_load)
    1440                 :             :                 {
    1441                 :           4 :                   bitfld = m_data[m_bitfld_load];
    1442                 :           4 :                   m_data[m_bitfld_load] = m_data[m_bitfld_load + 2];
    1443                 :           4 :                   m_bitfld_load = 0;
    1444                 :             :                 }
    1445                 :         217 :               t2 = handle_operand (rhs1, size_int (low));
    1446                 :         217 :               if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (t2)))
    1447                 :         177 :                 t2 = add_cast (m_limb_type, t2);
    1448                 :         217 :               if (!TYPE_UNSIGNED (rhs_type) && m_upwards_2limb)
    1449                 :             :                 {
    1450                 :         120 :                   ext = add_cast (signed_type_for (m_limb_type), t2);
    1451                 :         240 :                   tree lpm1 = build_int_cst (unsigned_type_node,
    1452                 :         120 :                                              limb_prec - 1);
    1453                 :         120 :                   tree n = make_ssa_name (TREE_TYPE (ext));
    1454                 :         120 :                   g = gimple_build_assign (n, RSHIFT_EXPR, ext, lpm1);
    1455                 :         120 :                   insert_before (g);
    1456                 :         120 :                   ext = add_cast (m_limb_type, n);
    1457                 :             :                 }
    1458                 :             :             }
    1459                 :         426 :           tree t3;
    1460                 :         426 :           if (TYPE_UNSIGNED (rhs_type))
    1461                 :         222 :             t3 = build_zero_cst (m_limb_type);
    1462                 :         204 :           else if (m_upwards_2limb && (save_first || ext != NULL_TREE))
    1463                 :         141 :             t3 = m_data[save_data_cnt];
    1464                 :             :           else
    1465                 :          63 :             t3 = m_data[save_data_cnt + 1];
    1466                 :         426 :           m_gsi = gsi_after_labels (edge_true_false->dest);
    1467                 :         426 :           t = make_ssa_name (m_limb_type);
    1468                 :         426 :           gphi *phi = create_phi_node (t, edge_true_false->dest);
    1469                 :         426 :           add_phi_arg (phi, t1, edge_true_false, UNKNOWN_LOCATION);
    1470                 :         426 :           add_phi_arg (phi, t3, edge_false, UNKNOWN_LOCATION);
    1471                 :         426 :           if (edge_true_true)
    1472                 :         217 :             add_phi_arg (phi, t2, edge_true_true, UNKNOWN_LOCATION);
    1473                 :         426 :           if (ext)
    1474                 :             :             {
    1475                 :         120 :               tree t4 = make_ssa_name (m_limb_type);
    1476                 :         120 :               phi = create_phi_node (t4, edge_true_false->dest);
    1477                 :         120 :               add_phi_arg (phi, build_zero_cst (m_limb_type), edge_true_false,
    1478                 :             :                            UNKNOWN_LOCATION);
    1479                 :         120 :               add_phi_arg (phi, m_data[save_data_cnt], edge_false,
    1480                 :             :                            UNKNOWN_LOCATION);
    1481                 :         120 :               add_phi_arg (phi, ext, edge_true_true, UNKNOWN_LOCATION);
    1482                 :         120 :               if (!save_cast_conditional)
    1483                 :             :                 {
    1484                 :         110 :                   g = gimple_build_assign (m_data[save_data_cnt + 1], t4);
    1485                 :         110 :                   insert_before (g);
    1486                 :             :                 }
    1487                 :             :               else
    1488                 :          10 :                 for (basic_block bb = gsi_bb (m_gsi);;)
    1489                 :             :                   {
    1490                 :          10 :                     edge e1 = single_succ_edge (bb);
    1491                 :          10 :                     edge e2 = find_edge (e1->dest, m_bb), e3;
    1492                 :          10 :                     tree t5 = (e2 ? m_data[save_data_cnt + 1]
    1493                 :           0 :                                : make_ssa_name (m_limb_type));
    1494                 :          10 :                     phi = create_phi_node (t5, e1->dest);
    1495                 :          10 :                     edge_iterator ei;
    1496                 :          30 :                     FOR_EACH_EDGE (e3, ei, e1->dest->preds)
    1497                 :          30 :                       add_phi_arg (phi, (e3 == e1 ? t4
    1498                 :          10 :                                          : build_zero_cst (m_limb_type)),
    1499                 :             :                                    e3, UNKNOWN_LOCATION);
    1500                 :          10 :                     if (e2)
    1501                 :             :                       break;
    1502                 :           0 :                     t4 = t5;
    1503                 :           0 :                     bb = e1->dest;
    1504                 :           0 :                   }
    1505                 :             :             }
    1506                 :         426 :           if (m_bitfld_load)
    1507                 :             :             {
    1508                 :           8 :               tree t4;
    1509                 :           8 :               if (!save_first && !save_cast_conditional)
    1510                 :           2 :                 t4 = m_data[m_bitfld_load + 1];
    1511                 :             :               else
    1512                 :           6 :                 t4 = make_ssa_name (m_limb_type);
    1513                 :           8 :               phi = create_phi_node (t4, edge_true_false->dest);
    1514                 :          12 :               add_phi_arg (phi,
    1515                 :           4 :                            edge_true_true ? bitfld : m_data[m_bitfld_load],
    1516                 :             :                            edge_true_false, UNKNOWN_LOCATION);
    1517                 :           8 :               add_phi_arg (phi, m_data[m_bitfld_load + 2],
    1518                 :             :                            edge_false, UNKNOWN_LOCATION);
    1519                 :           8 :               if (edge_true_true)
    1520                 :           4 :                 add_phi_arg (phi, m_data[m_bitfld_load], edge_true_true,
    1521                 :             :                              UNKNOWN_LOCATION);
    1522                 :           8 :               if (save_cast_conditional)
    1523                 :           4 :                 for (basic_block bb = gsi_bb (m_gsi);;)
    1524                 :             :                   {
    1525                 :           4 :                     edge e1 = single_succ_edge (bb);
    1526                 :           4 :                     edge e2 = find_edge (e1->dest, m_bb), e3;
    1527                 :           4 :                     tree t5 = ((e2 && !save_first) ? m_data[m_bitfld_load + 1]
    1528                 :           2 :                                : make_ssa_name (m_limb_type));
    1529                 :           4 :                     phi = create_phi_node (t5, e1->dest);
    1530                 :           4 :                     edge_iterator ei;
    1531                 :          14 :                     FOR_EACH_EDGE (e3, ei, e1->dest->preds)
    1532                 :          16 :                       add_phi_arg (phi, (e3 == e1 ? t4
    1533                 :           6 :                                          : build_zero_cst (m_limb_type)),
    1534                 :             :                                    e3, UNKNOWN_LOCATION);
    1535                 :           4 :                     t4 = t5;
    1536                 :           4 :                     if (e2)
    1537                 :             :                       break;
    1538                 :           0 :                     bb = e1->dest;
    1539                 :           0 :                   }
    1540                 :           8 :               m_data[m_bitfld_load] = t4;
    1541                 :           8 :               m_data[m_bitfld_load + 2] = t4;
    1542                 :           8 :               m_bitfld_load = 0;
    1543                 :             :             }
    1544                 :         426 :           m_cast_conditional = save_cast_conditional;
    1545                 :         426 :           m_first = save_first;
    1546                 :         426 :           return t;
    1547                 :             :         }
    1548                 :             :       else
    1549                 :             :         {
    1550                 :         478 :           if (tree_to_uhwi (idx) < low)
    1551                 :             :             {
    1552                 :         132 :               t = handle_operand (rhs1, idx);
    1553                 :         132 :               if (m_first)
    1554                 :          61 :                 m_data[save_data_cnt + 2]
    1555                 :         122 :                   = build_int_cst (NULL_TREE, m_data_cnt);
    1556                 :             :             }
    1557                 :         346 :           else if (tree_to_uhwi (idx) < high)
    1558                 :             :             {
    1559                 :          57 :               t = handle_operand (rhs1, size_int (low));
    1560                 :          57 :               if (m_first)
    1561                 :           1 :                 m_data[save_data_cnt + 2]
    1562                 :           2 :                   = build_int_cst (NULL_TREE, m_data_cnt);
    1563                 :          57 :               if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (t)))
    1564                 :          49 :                 t = add_cast (m_limb_type, t);
    1565                 :          57 :               tree ext = NULL_TREE;
    1566                 :          57 :               if (!TYPE_UNSIGNED (rhs_type) && m_upwards)
    1567                 :             :                 {
    1568                 :          37 :                   ext = add_cast (signed_type_for (m_limb_type), t);
    1569                 :          74 :                   tree lpm1 = build_int_cst (unsigned_type_node,
    1570                 :          37 :                                              limb_prec - 1);
    1571                 :          37 :                   tree n = make_ssa_name (TREE_TYPE (ext));
    1572                 :          37 :                   g = gimple_build_assign (n, RSHIFT_EXPR, ext, lpm1);
    1573                 :          37 :                   insert_before (g);
    1574                 :          37 :                   ext = add_cast (m_limb_type, n);
    1575                 :          37 :                   m_data[save_data_cnt + 1] = ext;
    1576                 :             :                 }
    1577                 :             :             }
    1578                 :             :           else
    1579                 :             :             {
    1580                 :         289 :               if (TYPE_UNSIGNED (rhs_type) && m_first)
    1581                 :             :                 {
    1582                 :           0 :                   handle_operand (rhs1, size_zero_node);
    1583                 :           0 :                   m_data[save_data_cnt + 2]
    1584                 :           0 :                     = build_int_cst (NULL_TREE, m_data_cnt);
    1585                 :             :                 }
    1586                 :             :               else
    1587                 :         289 :                 m_data_cnt = tree_to_uhwi (m_data[save_data_cnt + 2]);
    1588                 :         289 :               if (TYPE_UNSIGNED (rhs_type))
    1589                 :         159 :                 t = build_zero_cst (m_limb_type);
    1590                 :         130 :               else if (m_bb && m_data[save_data_cnt])
    1591                 :             :                 t = m_data[save_data_cnt];
    1592                 :             :               else
    1593                 :         124 :                 t = m_data[save_data_cnt + 1];
    1594                 :             :             }
    1595                 :         478 :           tree type = limb_access_type (lhs_type, idx);
    1596                 :         478 :           if (!useless_type_conversion_p (type, m_limb_type))
    1597                 :         247 :             t = add_cast (type, t);
    1598                 :         478 :           m_first = save_first;
    1599                 :         478 :           return t;
    1600                 :             :         }
    1601                 :             :     }
    1602                 :        1463 :   else if (TREE_CODE (lhs_type) == BITINT_TYPE
    1603                 :        1463 :            && bitint_precision_kind (lhs_type) >= bitint_prec_large
    1604                 :        2926 :            && INTEGRAL_TYPE_P (rhs_type))
    1605                 :             :     {
    1606                 :             :       /* Add support for 3 or more limbs filled in from normal integral
    1607                 :             :          type if this assert fails.  If no target chooses limb mode smaller
    1608                 :             :          than half of largest supported normal integral type, this will not
    1609                 :             :          be needed.  */
    1610                 :        1463 :       gcc_assert (TYPE_PRECISION (rhs_type) <= 2 * limb_prec);
    1611                 :        1463 :       tree r1 = NULL_TREE, r2 = NULL_TREE, rext = NULL_TREE;
    1612                 :        1463 :       if (m_first)
    1613                 :             :         {
    1614                 :         537 :           gimple_stmt_iterator save_gsi = m_gsi;
    1615                 :         537 :           m_gsi = m_init_gsi;
    1616                 :         537 :           if (gsi_end_p (m_gsi))
    1617                 :          54 :             m_gsi = gsi_after_labels (gsi_bb (m_gsi));
    1618                 :             :           else
    1619                 :         483 :             gsi_next (&m_gsi);
    1620                 :         537 :           if (TREE_CODE (rhs_type) == BITINT_TYPE
    1621                 :         537 :               && bitint_precision_kind (rhs_type) == bitint_prec_middle)
    1622                 :             :             {
    1623                 :          60 :               tree type = NULL_TREE;
    1624                 :          60 :               rhs1 = maybe_cast_middle_bitint (&m_gsi, rhs1, type);
    1625                 :          60 :               rhs_type = TREE_TYPE (rhs1);
    1626                 :             :             }
    1627                 :         537 :           r1 = rhs1;
    1628                 :         537 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1)))
    1629                 :         469 :             r1 = add_cast (m_limb_type, rhs1);
    1630                 :         537 :           if (TYPE_PRECISION (rhs_type) > limb_prec)
    1631                 :             :             {
    1632                 :         106 :               g = gimple_build_assign (make_ssa_name (rhs_type),
    1633                 :             :                                        RSHIFT_EXPR, rhs1,
    1634                 :             :                                        build_int_cst (unsigned_type_node,
    1635                 :             :                                                       limb_prec));
    1636                 :         106 :               insert_before (g);
    1637                 :         106 :               r2 = add_cast (m_limb_type, gimple_assign_lhs (g));
    1638                 :             :             }
    1639                 :         537 :           if (TYPE_UNSIGNED (rhs_type))
    1640                 :         265 :             rext = build_zero_cst (m_limb_type);
    1641                 :             :           else
    1642                 :             :             {
    1643                 :         272 :               rext = add_cast (signed_type_for (m_limb_type), r2 ? r2 : r1);
    1644                 :         272 :               g = gimple_build_assign (make_ssa_name (TREE_TYPE (rext)),
    1645                 :             :                                        RSHIFT_EXPR, rext,
    1646                 :             :                                        build_int_cst (unsigned_type_node,
    1647                 :         272 :                                                       limb_prec - 1));
    1648                 :         272 :               insert_before (g);
    1649                 :         272 :               rext = add_cast (m_limb_type, gimple_assign_lhs (g));
    1650                 :             :             }
    1651                 :         537 :           m_init_gsi = m_gsi;
    1652                 :         537 :           if (gsi_end_p (m_init_gsi))
    1653                 :         514 :             m_init_gsi = gsi_last_bb (gsi_bb (m_init_gsi));
    1654                 :             :           else
    1655                 :         280 :             gsi_prev (&m_init_gsi);
    1656                 :         537 :           m_gsi = save_gsi;
    1657                 :             :         }
    1658                 :        1463 :       tree t;
    1659                 :        1463 :       if (m_upwards_2limb)
    1660                 :             :         {
    1661                 :         666 :           if (m_first)
    1662                 :             :             {
    1663                 :         256 :               tree out1, out2;
    1664                 :         256 :               prepare_data_in_out (r1, idx, &out1, rext);
    1665                 :         256 :               if (TYPE_PRECISION (rhs_type) > limb_prec)
    1666                 :             :                 {
    1667                 :          70 :                   prepare_data_in_out (r2, idx, &out2, rext);
    1668                 :          70 :                   m_data.pop ();
    1669                 :          70 :                   t = m_data.pop ();
    1670                 :          70 :                   m_data[m_data_cnt + 1] = t;
    1671                 :             :                 }
    1672                 :             :               else
    1673                 :         186 :                 m_data[m_data_cnt + 1] = rext;
    1674                 :         256 :               m_data.safe_push (rext);
    1675                 :         256 :               t = m_data[m_data_cnt];
    1676                 :             :             }
    1677                 :         410 :           else if (!tree_fits_uhwi_p (idx))
    1678                 :         256 :             t = m_data[m_data_cnt + 1];
    1679                 :             :           else
    1680                 :             :             {
    1681                 :         154 :               tree type = limb_access_type (lhs_type, idx);
    1682                 :         154 :               t = m_data[m_data_cnt + 2];
    1683                 :         154 :               if (!useless_type_conversion_p (type, m_limb_type))
    1684                 :         126 :                 t = add_cast (type, t);
    1685                 :             :             }
    1686                 :         666 :           m_data_cnt += 3;
    1687                 :         666 :           return t;
    1688                 :             :         }
    1689                 :         797 :       else if (m_first)
    1690                 :             :         {
    1691                 :         281 :           m_data.safe_push (r1);
    1692                 :         281 :           m_data.safe_push (r2);
    1693                 :         281 :           m_data.safe_push (rext);
    1694                 :             :         }
    1695                 :         797 :       if (tree_fits_uhwi_p (idx))
    1696                 :             :         {
    1697                 :         753 :           tree type = limb_access_type (lhs_type, idx);
    1698                 :         753 :           if (integer_zerop (idx))
    1699                 :         253 :             t = m_data[m_data_cnt];
    1700                 :         500 :           else if (TYPE_PRECISION (rhs_type) > limb_prec
    1701                 :         500 :                    && integer_onep (idx))
    1702                 :          30 :             t = m_data[m_data_cnt + 1];
    1703                 :             :           else
    1704                 :         470 :             t = m_data[m_data_cnt + 2];
    1705                 :         753 :           if (!useless_type_conversion_p (type, m_limb_type))
    1706                 :         234 :             t = add_cast (type, t);
    1707                 :         753 :           m_data_cnt += 3;
    1708                 :         753 :           return t;
    1709                 :             :         }
    1710                 :          44 :       g = gimple_build_cond (NE_EXPR, idx, size_zero_node,
    1711                 :             :                              NULL_TREE, NULL_TREE);
    1712                 :          44 :       edge e2, e3, e4 = NULL;
    1713                 :          44 :       if_then (g, profile_probability::likely (), e2, e3);
    1714                 :          44 :       if (m_data[m_data_cnt + 1])
    1715                 :             :         {
    1716                 :          14 :           g = gimple_build_cond (EQ_EXPR, idx, size_one_node,
    1717                 :             :                                  NULL_TREE, NULL_TREE);
    1718                 :          14 :           insert_before (g);
    1719                 :          14 :           edge e5 = split_block (gsi_bb (m_gsi), g);
    1720                 :          14 :           e4 = make_edge (e5->src, e2->dest, EDGE_TRUE_VALUE);
    1721                 :          14 :           e2 = find_edge (e5->dest, e2->dest);
    1722                 :          14 :           e4->probability = profile_probability::unlikely ();
    1723                 :          14 :           e5->flags = EDGE_FALSE_VALUE;
    1724                 :          14 :           e5->probability = e4->probability.invert ();
    1725                 :             :         }
    1726                 :          44 :       m_gsi = gsi_after_labels (e2->dest);
    1727                 :          44 :       t = make_ssa_name (m_limb_type);
    1728                 :          44 :       gphi *phi = create_phi_node (t, e2->dest);
    1729                 :          44 :       add_phi_arg (phi, m_data[m_data_cnt + 2], e2, UNKNOWN_LOCATION);
    1730                 :          44 :       add_phi_arg (phi, m_data[m_data_cnt], e3, UNKNOWN_LOCATION);
    1731                 :          44 :       if (e4)
    1732                 :          14 :         add_phi_arg (phi, m_data[m_data_cnt + 1], e4, UNKNOWN_LOCATION);
    1733                 :          44 :       m_data_cnt += 3;
    1734                 :          44 :       return t;
    1735                 :             :     }
    1736                 :             :   return NULL_TREE;
    1737                 :             : }
    1738                 :             : 
    1739                 :             : /* Helper function for handle_stmt method, handle a BIT_FIELD_REF.  */
    1740                 :             : 
    1741                 :             : tree
    1742                 :          29 : bitint_large_huge::handle_bit_field_ref (tree op, tree idx)
    1743                 :             : {
    1744                 :          29 :   if (tree_fits_uhwi_p (idx))
    1745                 :             :     {
    1746                 :          17 :       if (m_first)
    1747                 :           5 :         m_data.safe_push (NULL);
    1748                 :          17 :       ++m_data_cnt;
    1749                 :          17 :       unsigned HOST_WIDE_INT sz = tree_to_uhwi (TYPE_SIZE (m_limb_type));
    1750                 :          34 :       tree bfr = build3 (BIT_FIELD_REF, m_limb_type,
    1751                 :          17 :                          TREE_OPERAND (op, 0),
    1752                 :          17 :                          TYPE_SIZE (m_limb_type),
    1753                 :          17 :                          size_binop (PLUS_EXPR, TREE_OPERAND (op, 2),
    1754                 :             :                                      bitsize_int (tree_to_uhwi (idx) * sz)));
    1755                 :          17 :       tree r = make_ssa_name (m_limb_type);
    1756                 :          17 :       gimple *g = gimple_build_assign (r, bfr);
    1757                 :          17 :       insert_before (g);
    1758                 :          17 :       tree type = limb_access_type (TREE_TYPE (op), idx);
    1759                 :          17 :       if (!useless_type_conversion_p (type, m_limb_type))
    1760                 :           0 :         r = add_cast (type, r);
    1761                 :          17 :       return r;
    1762                 :             :     }
    1763                 :          12 :   tree var;
    1764                 :          12 :   if (m_first)
    1765                 :             :     {
    1766                 :           6 :       unsigned HOST_WIDE_INT sz = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (op)));
    1767                 :           6 :       machine_mode mode;
    1768                 :           6 :       tree type, bfr;
    1769                 :           6 :       if (bitwise_mode_for_size (sz).exists (&mode)
    1770                 :           4 :           && known_eq (GET_MODE_BITSIZE (mode), sz))
    1771                 :           2 :         type = bitwise_type_for_mode (mode);
    1772                 :             :       else
    1773                 :             :         {
    1774                 :           4 :           mode = VOIDmode;
    1775                 :           4 :           type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (op, 0)));
    1776                 :             :         }
    1777                 :           6 :       if (TYPE_ALIGN (type) < TYPE_ALIGN (TREE_TYPE (op)))
    1778                 :           0 :         type = build_aligned_type (type, TYPE_ALIGN (TREE_TYPE (op)));
    1779                 :           6 :       var = create_tmp_var (type);
    1780                 :           6 :       TREE_ADDRESSABLE (var) = 1;
    1781                 :           6 :       gimple *g;
    1782                 :           6 :       if (mode != VOIDmode)
    1783                 :             :         {
    1784                 :           2 :           bfr = build3 (BIT_FIELD_REF, type, TREE_OPERAND (op, 0),
    1785                 :           2 :                         TYPE_SIZE (type), TREE_OPERAND (op, 2));
    1786                 :           2 :           g = gimple_build_assign (make_ssa_name (type),
    1787                 :             :                                    BIT_FIELD_REF, bfr);
    1788                 :           2 :           gimple_set_location (g, m_loc);
    1789                 :           2 :           gsi_insert_after (&m_init_gsi, g, GSI_NEW_STMT);
    1790                 :           2 :           bfr = gimple_assign_lhs (g);
    1791                 :             :         }
    1792                 :             :       else
    1793                 :           4 :         bfr = TREE_OPERAND (op, 0);
    1794                 :           6 :       g = gimple_build_assign (var, bfr);
    1795                 :           6 :       gimple_set_location (g, m_loc);
    1796                 :           6 :       gsi_insert_after (&m_init_gsi, g, GSI_NEW_STMT);
    1797                 :           6 :       if (mode == VOIDmode)
    1798                 :             :         {
    1799                 :           4 :           unsigned HOST_WIDE_INT nelts
    1800                 :           4 :             = CEIL (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (op))), limb_prec);
    1801                 :           4 :           tree atype = build_array_type_nelts (m_limb_type, nelts);
    1802                 :           4 :           var = build2 (MEM_REF, atype, build_fold_addr_expr (var),
    1803                 :             :                         build_int_cst (build_pointer_type (type),
    1804                 :           4 :                                        tree_to_uhwi (TREE_OPERAND (op, 2))
    1805                 :           4 :                                        / BITS_PER_UNIT));
    1806                 :             :         }
    1807                 :           6 :       m_data.safe_push (var);
    1808                 :             :     }
    1809                 :             :   else
    1810                 :           6 :     var = unshare_expr (m_data[m_data_cnt]);
    1811                 :          12 :   ++m_data_cnt;
    1812                 :          12 :   var = limb_access (TREE_TYPE (op), var, idx, false);
    1813                 :          12 :   tree r = make_ssa_name (m_limb_type);
    1814                 :          12 :   gimple *g = gimple_build_assign (r, var);
    1815                 :          12 :   insert_before (g);
    1816                 :          12 :   return r;
    1817                 :             : }
    1818                 :             : 
    1819                 :             : /* Add a new EH edge from SRC to EH_EDGE->dest, where EH_EDGE
    1820                 :             :    is an older EH edge, and except for virtual PHIs duplicate the
    1821                 :             :    PHI argument from the EH_EDGE to the new EH edge.  */
    1822                 :             : 
    1823                 :             : static void
    1824                 :          18 : add_eh_edge (basic_block src, edge eh_edge)
    1825                 :             : {
    1826                 :          18 :   edge e = make_edge (src, eh_edge->dest, EDGE_EH);
    1827                 :          18 :   e->probability = profile_probability::very_unlikely ();
    1828                 :          18 :   for (gphi_iterator gsi = gsi_start_phis (eh_edge->dest);
    1829                 :          24 :        !gsi_end_p (gsi); gsi_next (&gsi))
    1830                 :             :     {
    1831                 :           6 :       gphi *phi = gsi.phi ();
    1832                 :           6 :       tree lhs = gimple_phi_result (phi);
    1833                 :          12 :       if (virtual_operand_p (lhs))
    1834                 :           3 :         continue;
    1835                 :           3 :       const phi_arg_d *arg = gimple_phi_arg (phi, eh_edge->dest_idx);
    1836                 :           3 :       add_phi_arg (phi, arg->def, e, arg->locus);
    1837                 :             :     }
    1838                 :          18 : }
    1839                 :             : 
    1840                 :             : /* Helper function for handle_stmt method, handle a load from memory.  */
    1841                 :             : 
    1842                 :             : tree
    1843                 :       20305 : bitint_large_huge::handle_load (gimple *stmt, tree idx)
    1844                 :             : {
    1845                 :       20305 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    1846                 :       20305 :   tree rhs_type = TREE_TYPE (rhs1);
    1847                 :       20305 :   bool eh = stmt_ends_bb_p (stmt);
    1848                 :       20305 :   edge eh_edge = NULL;
    1849                 :       20305 :   gimple *g;
    1850                 :             : 
    1851                 :       20305 :   if (eh)
    1852                 :             :     {
    1853                 :          10 :       edge_iterator ei;
    1854                 :          10 :       basic_block bb = gimple_bb (stmt);
    1855                 :             : 
    1856                 :          10 :       FOR_EACH_EDGE (eh_edge, ei, bb->succs)
    1857                 :          10 :         if (eh_edge->flags & EDGE_EH)
    1858                 :             :             break;
    1859                 :             :     }
    1860                 :             : 
    1861                 :       20305 :   if (TREE_CODE (rhs1) == COMPONENT_REF
    1862                 :       20305 :       && DECL_BIT_FIELD_TYPE (TREE_OPERAND (rhs1, 1)))
    1863                 :             :     {
    1864                 :         395 :       tree fld = TREE_OPERAND (rhs1, 1);
    1865                 :             :       /* For little-endian, we can allow as inputs bit-fields
    1866                 :             :          which start at a limb boundary.  */
    1867                 :         395 :       gcc_assert (tree_fits_uhwi_p (DECL_FIELD_BIT_OFFSET (fld)));
    1868                 :         395 :       if (DECL_OFFSET_ALIGN (fld) >= TYPE_ALIGN (TREE_TYPE (rhs1))
    1869                 :         395 :           && (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld)) % limb_prec) == 0)
    1870                 :         113 :         goto normal_load;
    1871                 :             :       /* Even if DECL_FIELD_BIT_OFFSET (fld) is a multiple of UNITS_PER_BIT,
    1872                 :             :          handle it normally for now.  */
    1873                 :         282 :       if ((tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld)) % BITS_PER_UNIT) == 0)
    1874                 :           0 :         goto normal_load;
    1875                 :         282 :       tree repr = DECL_BIT_FIELD_REPRESENTATIVE (fld);
    1876                 :         282 :       poly_int64 bitoffset;
    1877                 :         282 :       poly_uint64 field_offset, repr_offset;
    1878                 :         282 :       bool var_field_off = false;
    1879                 :         282 :       if (poly_int_tree_p (DECL_FIELD_OFFSET (fld), &field_offset)
    1880                 :         564 :           && poly_int_tree_p (DECL_FIELD_OFFSET (repr), &repr_offset))
    1881                 :         282 :         bitoffset = (field_offset - repr_offset) * BITS_PER_UNIT;
    1882                 :             :       else
    1883                 :             :         {
    1884                 :             :           bitoffset = 0;
    1885                 :             :           var_field_off = true;
    1886                 :             :         }
    1887                 :         282 :       bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld))
    1888                 :         282 :                     - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
    1889                 :         564 :       tree nrhs1 = build3 (COMPONENT_REF, TREE_TYPE (repr),
    1890                 :         282 :                            TREE_OPERAND (rhs1, 0), repr,
    1891                 :           0 :                            var_field_off ? TREE_OPERAND (rhs1, 2) : NULL_TREE);
    1892                 :         282 :       HOST_WIDE_INT bo = bitoffset.to_constant ();
    1893                 :         282 :       unsigned bo_idx = (unsigned HOST_WIDE_INT) bo / limb_prec;
    1894                 :         282 :       unsigned bo_bit = (unsigned HOST_WIDE_INT) bo % limb_prec;
    1895                 :         282 :       if (m_first)
    1896                 :             :         {
    1897                 :          89 :           if (m_upwards)
    1898                 :             :             {
    1899                 :          86 :               gimple_stmt_iterator save_gsi = m_gsi;
    1900                 :          86 :               m_gsi = m_init_gsi;
    1901                 :          86 :               if (gsi_end_p (m_gsi))
    1902                 :          21 :                 m_gsi = gsi_after_labels (gsi_bb (m_gsi));
    1903                 :             :               else
    1904                 :          65 :                 gsi_next (&m_gsi);
    1905                 :          86 :               tree t = limb_access (NULL_TREE, nrhs1, size_int (bo_idx), true);
    1906                 :          86 :               tree iv = make_ssa_name (m_limb_type);
    1907                 :          86 :               g = gimple_build_assign (iv, t);
    1908                 :          86 :               insert_before (g);
    1909                 :          86 :               if (eh)
    1910                 :             :                 {
    1911                 :           2 :                   maybe_duplicate_eh_stmt (g, stmt);
    1912                 :           2 :                   if (eh_edge)
    1913                 :             :                     {
    1914                 :           2 :                       edge e = split_block (gsi_bb (m_gsi), g);
    1915                 :           2 :                       add_eh_edge (e->src, eh_edge);
    1916                 :           2 :                       m_gsi = gsi_after_labels (e->dest);
    1917                 :           2 :                       if (gsi_bb (save_gsi) == e->src)
    1918                 :             :                         {
    1919                 :           1 :                           if (gsi_end_p (save_gsi))
    1920                 :           0 :                             save_gsi = gsi_end_bb (e->dest);
    1921                 :             :                           else
    1922                 :           1 :                             save_gsi = gsi_for_stmt (gsi_stmt (save_gsi));
    1923                 :             :                         }
    1924                 :           2 :                       if (m_preheader_bb == e->src)
    1925                 :           1 :                         m_preheader_bb = e->dest;
    1926                 :             :                     }
    1927                 :             :                 }
    1928                 :          86 :               m_init_gsi = m_gsi;
    1929                 :          86 :               if (gsi_end_p (m_init_gsi))
    1930                 :         144 :                 m_init_gsi = gsi_last_bb (gsi_bb (m_init_gsi));
    1931                 :             :               else
    1932                 :          14 :                 gsi_prev (&m_init_gsi);
    1933                 :          86 :               m_gsi = save_gsi;
    1934                 :          86 :               tree out;
    1935                 :          86 :               prepare_data_in_out (iv, idx, &out);
    1936                 :          86 :               out = m_data[m_data_cnt];
    1937                 :          86 :               m_data.safe_push (out);
    1938                 :             :             }
    1939                 :             :           else
    1940                 :             :             {
    1941                 :           3 :               m_data.safe_push (NULL_TREE);
    1942                 :           3 :               m_data.safe_push (NULL_TREE);
    1943                 :           3 :               m_data.safe_push (NULL_TREE);
    1944                 :             :             }
    1945                 :             :         }
    1946                 :             : 
    1947                 :         282 :       tree nidx0 = NULL_TREE, nidx1;
    1948                 :         282 :       tree iv = m_data[m_data_cnt];
    1949                 :         282 :       if (m_cast_conditional && iv)
    1950                 :             :         {
    1951                 :          12 :           gcc_assert (!m_bitfld_load);
    1952                 :          12 :           m_bitfld_load = m_data_cnt;
    1953                 :             :         }
    1954                 :         282 :       if (tree_fits_uhwi_p (idx))
    1955                 :             :         {
    1956                 :         140 :           unsigned prec = TYPE_PRECISION (rhs_type);
    1957                 :         140 :           unsigned HOST_WIDE_INT i = tree_to_uhwi (idx);
    1958                 :         140 :           gcc_assert (i * limb_prec < prec);
    1959                 :         140 :           nidx1 = size_int (i + bo_idx + 1);
    1960                 :         140 :           if ((i + 1) * limb_prec > prec)
    1961                 :             :             {
    1962                 :          64 :               prec %= limb_prec;
    1963                 :          64 :               if (prec + bo_bit <= (unsigned) limb_prec)
    1964                 :         140 :                 nidx1 = NULL_TREE;
    1965                 :             :             }
    1966                 :         140 :           if (!iv)
    1967                 :           4 :             nidx0 = size_int (i + bo_idx);
    1968                 :             :         }
    1969                 :             :       else
    1970                 :             :         {
    1971                 :         142 :           if (!iv)
    1972                 :             :             {
    1973                 :           4 :               if (bo_idx == 0)
    1974                 :             :                 nidx0 = idx;
    1975                 :             :               else
    1976                 :             :                 {
    1977                 :           0 :                   nidx0 = make_ssa_name (sizetype);
    1978                 :           0 :                   g = gimple_build_assign (nidx0, PLUS_EXPR, idx,
    1979                 :             :                                            size_int (bo_idx));
    1980                 :           0 :                   insert_before (g);
    1981                 :             :                 }
    1982                 :             :             }
    1983                 :         142 :           nidx1 = make_ssa_name (sizetype);
    1984                 :         142 :           g = gimple_build_assign (nidx1, PLUS_EXPR, idx,
    1985                 :         142 :                                    size_int (bo_idx + 1));
    1986                 :         142 :           insert_before (g);
    1987                 :             :         }
    1988                 :             : 
    1989                 :         428 :       tree iv2 = NULL_TREE;
    1990                 :         146 :       if (nidx0)
    1991                 :             :         {
    1992                 :           8 :           tree t = limb_access (NULL_TREE, nrhs1, nidx0, true);
    1993                 :           8 :           iv = make_ssa_name (m_limb_type);
    1994                 :           8 :           g = gimple_build_assign (iv, t);
    1995                 :           8 :           insert_before (g);
    1996                 :           8 :           gcc_assert (!eh);
    1997                 :             :         }
    1998                 :         282 :       if (nidx1)
    1999                 :             :         {
    2000                 :         233 :           bool conditional = m_var_msb && !tree_fits_uhwi_p (idx);
    2001                 :         233 :           unsigned prec = TYPE_PRECISION (rhs_type);
    2002                 :         233 :           if (conditional)
    2003                 :             :             {
    2004                 :           3 :               if ((prec % limb_prec) == 0
    2005                 :           3 :                   || ((prec % limb_prec) + bo_bit > (unsigned) limb_prec))
    2006                 :         230 :                 conditional = false;
    2007                 :             :             }
    2008                 :         233 :           edge edge_true = NULL, edge_false = NULL;
    2009                 :         233 :           if (conditional)
    2010                 :             :             {
    2011                 :           3 :               g = gimple_build_cond (NE_EXPR, idx,
    2012                 :           3 :                                      size_int (prec / limb_prec),
    2013                 :             :                                      NULL_TREE, NULL_TREE);
    2014                 :           3 :               if_then (g, profile_probability::likely (),
    2015                 :             :                        edge_true, edge_false);
    2016                 :             :             }
    2017                 :         233 :           tree t = limb_access (NULL_TREE, nrhs1, nidx1, true);
    2018                 :         233 :           if (m_upwards_2limb
    2019                 :         193 :               && !m_first
    2020                 :         124 :               && !m_bitfld_load
    2021                 :         118 :               && !tree_fits_uhwi_p (idx))
    2022                 :          65 :             iv2 = m_data[m_data_cnt + 1];
    2023                 :             :           else
    2024                 :         168 :             iv2 = make_ssa_name (m_limb_type);
    2025                 :         233 :           g = gimple_build_assign (iv2, t);
    2026                 :         233 :           insert_before (g);
    2027                 :         233 :           if (eh)
    2028                 :             :             {
    2029                 :           5 :               maybe_duplicate_eh_stmt (g, stmt);
    2030                 :           5 :               if (eh_edge)
    2031                 :             :                 {
    2032                 :           5 :                   edge e = split_block (gsi_bb (m_gsi), g);
    2033                 :           5 :                   m_gsi = gsi_after_labels (e->dest);
    2034                 :           5 :                   add_eh_edge (e->src, eh_edge);
    2035                 :             :                 }
    2036                 :             :             }
    2037                 :         233 :           if (conditional)
    2038                 :             :             {
    2039                 :           3 :               tree iv3 = make_ssa_name (m_limb_type);
    2040                 :           3 :               if (eh)
    2041                 :           0 :                 edge_true = find_edge (gsi_bb (m_gsi), edge_false->dest);
    2042                 :           3 :               gphi *phi = create_phi_node (iv3, edge_true->dest);
    2043                 :           3 :               add_phi_arg (phi, iv2, edge_true, UNKNOWN_LOCATION);
    2044                 :           3 :               add_phi_arg (phi, build_zero_cst (m_limb_type),
    2045                 :             :                            edge_false, UNKNOWN_LOCATION);
    2046                 :           3 :               m_gsi = gsi_after_labels (edge_true->dest);
    2047                 :           3 :               iv2 = iv3;
    2048                 :             :             }
    2049                 :             :         }
    2050                 :         282 :       g = gimple_build_assign (make_ssa_name (m_limb_type), RSHIFT_EXPR,
    2051                 :             :                                iv, build_int_cst (unsigned_type_node, bo_bit));
    2052                 :         282 :       insert_before (g);
    2053                 :         282 :       iv = gimple_assign_lhs (g);
    2054                 :         282 :       if (iv2)
    2055                 :             :         {
    2056                 :         233 :           g = gimple_build_assign (make_ssa_name (m_limb_type), LSHIFT_EXPR,
    2057                 :             :                                    iv2, build_int_cst (unsigned_type_node,
    2058                 :         233 :                                                        limb_prec - bo_bit));
    2059                 :         233 :           insert_before (g);
    2060                 :         233 :           g = gimple_build_assign (make_ssa_name (m_limb_type), BIT_IOR_EXPR,
    2061                 :             :                                    gimple_assign_lhs (g), iv);
    2062                 :         233 :           insert_before (g);
    2063                 :         233 :           iv = gimple_assign_lhs (g);
    2064                 :         233 :           if (m_data[m_data_cnt])
    2065                 :         227 :             m_data[m_data_cnt] = iv2;
    2066                 :             :         }
    2067                 :         282 :       if (tree_fits_uhwi_p (idx))
    2068                 :             :         {
    2069                 :         140 :           tree atype = limb_access_type (rhs_type, idx);
    2070                 :         140 :           if (!useless_type_conversion_p (atype, TREE_TYPE (iv)))
    2071                 :          64 :             iv = add_cast (atype, iv);
    2072                 :             :         }
    2073                 :         282 :       m_data_cnt += 3;
    2074                 :         282 :       return iv;
    2075                 :             :     }
    2076                 :             : 
    2077                 :       20023 : normal_load:
    2078                 :             :   /* Use write_p = true for loads with EH edges to make
    2079                 :             :      sure limb_access doesn't add a cast as separate
    2080                 :             :      statement after it.  */
    2081                 :       20023 :   rhs1 = limb_access (rhs_type, rhs1, idx, eh);
    2082                 :       20023 :   tree ret = make_ssa_name (TREE_TYPE (rhs1));
    2083                 :       20023 :   g = gimple_build_assign (ret, rhs1);
    2084                 :       20023 :   insert_before (g);
    2085                 :       20023 :   if (eh)
    2086                 :             :     {
    2087                 :           3 :       maybe_duplicate_eh_stmt (g, stmt);
    2088                 :           3 :       if (eh_edge)
    2089                 :             :         {
    2090                 :           3 :           edge e = split_block (gsi_bb (m_gsi), g);
    2091                 :           3 :           m_gsi = gsi_after_labels (e->dest);
    2092                 :           3 :           add_eh_edge (e->src, eh_edge);
    2093                 :             :         }
    2094                 :           3 :       if (tree_fits_uhwi_p (idx))
    2095                 :             :         {
    2096                 :           1 :           tree atype = limb_access_type (rhs_type, idx);
    2097                 :           1 :           if (!useless_type_conversion_p (atype, TREE_TYPE (rhs1)))
    2098                 :           1 :             ret = add_cast (atype, ret);
    2099                 :             :         }
    2100                 :             :     }
    2101                 :             :   return ret;
    2102                 :             : }
    2103                 :             : 
    2104                 :             : /* Return a limb IDX from a mergeable statement STMT.  */
    2105                 :             : 
    2106                 :             : tree
    2107                 :       36954 : bitint_large_huge::handle_stmt (gimple *stmt, tree idx)
    2108                 :             : {
    2109                 :       36954 :   tree lhs, rhs1, rhs2 = NULL_TREE;
    2110                 :       36954 :   gimple *g;
    2111                 :       36954 :   switch (gimple_code (stmt))
    2112                 :             :     {
    2113                 :       36954 :     case GIMPLE_ASSIGN:
    2114                 :       36954 :       if (gimple_assign_load_p (stmt))
    2115                 :       20305 :         return handle_load (stmt, idx);
    2116                 :       16649 :       switch (gimple_assign_rhs_code (stmt))
    2117                 :             :         {
    2118                 :         901 :         case BIT_AND_EXPR:
    2119                 :         901 :         case BIT_IOR_EXPR:
    2120                 :         901 :         case BIT_XOR_EXPR:
    2121                 :         901 :           rhs2 = handle_operand (gimple_assign_rhs2 (stmt), idx);
    2122                 :             :           /* FALLTHRU */
    2123                 :        1297 :         case BIT_NOT_EXPR:
    2124                 :        1297 :           rhs1 = handle_operand (gimple_assign_rhs1 (stmt), idx);
    2125                 :        1297 :           lhs = make_ssa_name (TREE_TYPE (rhs1));
    2126                 :        1297 :           g = gimple_build_assign (lhs, gimple_assign_rhs_code (stmt),
    2127                 :             :                                    rhs1, rhs2);
    2128                 :        1297 :           insert_before (g);
    2129                 :        1297 :           return lhs;
    2130                 :        3546 :         case PLUS_EXPR:
    2131                 :        3546 :         case MINUS_EXPR:
    2132                 :        3546 :           rhs1 = handle_operand (gimple_assign_rhs1 (stmt), idx);
    2133                 :        3546 :           rhs2 = handle_operand (gimple_assign_rhs2 (stmt), idx);
    2134                 :        3546 :           return handle_plus_minus (gimple_assign_rhs_code (stmt),
    2135                 :        3546 :                                     rhs1, rhs2, idx);
    2136                 :         115 :         case NEGATE_EXPR:
    2137                 :         115 :           rhs2 = handle_operand (gimple_assign_rhs1 (stmt), idx);
    2138                 :         115 :           rhs1 = build_zero_cst (TREE_TYPE (rhs2));
    2139                 :         115 :           return handle_plus_minus (MINUS_EXPR, rhs1, rhs2, idx);
    2140                 :         133 :         case LSHIFT_EXPR:
    2141                 :         133 :           return handle_lshift (handle_operand (gimple_assign_rhs1 (stmt),
    2142                 :             :                                                 idx),
    2143                 :         133 :                                 gimple_assign_rhs2 (stmt), idx);
    2144                 :        5018 :         case SSA_NAME:
    2145                 :        5018 :         case INTEGER_CST:
    2146                 :        5018 :           return handle_operand (gimple_assign_rhs1 (stmt), idx);
    2147                 :        6503 :         CASE_CONVERT:
    2148                 :        6503 :           return handle_cast (TREE_TYPE (gimple_assign_lhs (stmt)),
    2149                 :        6503 :                               gimple_assign_rhs1 (stmt), idx);
    2150                 :           8 :         case VIEW_CONVERT_EXPR:
    2151                 :           8 :           return handle_cast (TREE_TYPE (gimple_assign_lhs (stmt)),
    2152                 :           8 :                               TREE_OPERAND (gimple_assign_rhs1 (stmt), 0),
    2153                 :           8 :                               idx);
    2154                 :          29 :         case BIT_FIELD_REF:
    2155                 :          29 :           return handle_bit_field_ref (gimple_assign_rhs1 (stmt), idx);
    2156                 :             :         default:
    2157                 :             :           break;
    2158                 :             :         }
    2159                 :             :       break;
    2160                 :             :     default:
    2161                 :             :       break;
    2162                 :             :     }
    2163                 :           0 :   gcc_unreachable ();
    2164                 :             : }
    2165                 :             : 
    2166                 :             : /* Return minimum precision of OP at STMT.
    2167                 :             :    Positive value is minimum precision above which all bits
    2168                 :             :    are zero, negative means all bits above negation of the
    2169                 :             :    value are copies of the sign bit.  */
    2170                 :             : 
    2171                 :             : static int
    2172                 :        7957 : range_to_prec (tree op, gimple *stmt)
    2173                 :             : {
    2174                 :        7957 :   int_range_max r;
    2175                 :        7957 :   wide_int w;
    2176                 :        7957 :   tree type = TREE_TYPE (op);
    2177                 :        7957 :   unsigned int prec = TYPE_PRECISION (type);
    2178                 :             : 
    2179                 :        7957 :   if (!optimize
    2180                 :        6914 :       || !get_range_query (cfun)->range_of_expr (r, op, stmt)
    2181                 :       11414 :       || r.undefined_p ())
    2182                 :             :     {
    2183                 :        4501 :       if (TYPE_UNSIGNED (type))
    2184                 :        1819 :         return prec;
    2185                 :             :       else
    2186                 :        2682 :         return MIN ((int) -prec, -2);
    2187                 :             :     }
    2188                 :             : 
    2189                 :        3456 :   if (!TYPE_UNSIGNED (TREE_TYPE (op)))
    2190                 :             :     {
    2191                 :        2165 :       w = r.lower_bound ();
    2192                 :        2165 :       if (wi::neg_p (w))
    2193                 :             :         {
    2194                 :        1772 :           int min_prec1 = wi::min_precision (w, SIGNED);
    2195                 :        1772 :           w = r.upper_bound ();
    2196                 :        1772 :           int min_prec2 = wi::min_precision (w, SIGNED);
    2197                 :        1772 :           int min_prec = MAX (min_prec1, min_prec2);
    2198                 :        1772 :           return MIN (-min_prec, -2);
    2199                 :             :         }
    2200                 :             :     }
    2201                 :             : 
    2202                 :        1684 :   w = r.upper_bound ();
    2203                 :        1684 :   int min_prec = wi::min_precision (w, UNSIGNED);
    2204                 :        1684 :   return MAX (min_prec, 1);
    2205                 :        7957 : }
    2206                 :             : 
    2207                 :             : /* Return address of the first limb of OP and write into *PREC
    2208                 :             :    its precision.  If positive, the operand is zero extended
    2209                 :             :    from that precision, if it is negative, the operand is sign-extended
    2210                 :             :    from -*PREC.  If PREC_STORED is NULL, it is the toplevel call,
    2211                 :             :    otherwise *PREC_STORED is prec from the innermost call without
    2212                 :             :    range optimizations.  */
    2213                 :             : 
    2214                 :             : tree
    2215                 :        3506 : bitint_large_huge::handle_operand_addr (tree op, gimple *stmt,
    2216                 :             :                                         int *prec_stored, int *prec)
    2217                 :             : {
    2218                 :        3506 :   wide_int w;
    2219                 :        3506 :   location_t loc_save = m_loc;
    2220                 :        3506 :   if ((TREE_CODE (TREE_TYPE (op)) != BITINT_TYPE
    2221                 :        3499 :        || bitint_precision_kind (TREE_TYPE (op)) < bitint_prec_large)
    2222                 :        3601 :       && TREE_CODE (op) != INTEGER_CST)
    2223                 :             :     {
    2224                 :         104 :     do_int:
    2225                 :         104 :       *prec = range_to_prec (op, stmt);
    2226                 :         104 :       bitint_prec_kind kind = bitint_prec_small;
    2227                 :         104 :       gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (op)));
    2228                 :         104 :       if (TREE_CODE (TREE_TYPE (op)) == BITINT_TYPE)
    2229                 :          97 :         kind = bitint_precision_kind (TREE_TYPE (op));
    2230                 :          97 :       if (kind == bitint_prec_middle)
    2231                 :             :         {
    2232                 :          12 :           tree type = NULL_TREE;
    2233                 :          12 :           op = maybe_cast_middle_bitint (&m_gsi, op, type);
    2234                 :             :         }
    2235                 :         104 :       tree op_type = TREE_TYPE (op);
    2236                 :         104 :       unsigned HOST_WIDE_INT nelts
    2237                 :         104 :         = CEIL (TYPE_PRECISION (op_type), limb_prec);
    2238                 :             :       /* Add support for 3 or more limbs filled in from normal
    2239                 :             :          integral type if this assert fails.  If no target chooses
    2240                 :             :          limb mode smaller than half of largest supported normal
    2241                 :             :          integral type, this will not be needed.  */
    2242                 :         104 :       gcc_assert (nelts <= 2);
    2243                 :         104 :       if (prec_stored)
    2244                 :           0 :         *prec_stored = (TYPE_UNSIGNED (op_type)
    2245                 :           0 :                         ? TYPE_PRECISION (op_type)
    2246                 :           0 :                         : -TYPE_PRECISION (op_type));
    2247                 :         104 :       if (*prec <= limb_prec && *prec >= -limb_prec)
    2248                 :             :         {
    2249                 :          91 :           nelts = 1;
    2250                 :          91 :           if (prec_stored)
    2251                 :             :             {
    2252                 :           0 :               if (TYPE_UNSIGNED (op_type))
    2253                 :             :                 {
    2254                 :           0 :                   if (*prec_stored > limb_prec)
    2255                 :           0 :                     *prec_stored = limb_prec;
    2256                 :             :                 }
    2257                 :           0 :               else if (*prec_stored < -limb_prec)
    2258                 :           0 :                 *prec_stored = -limb_prec;
    2259                 :             :             }
    2260                 :             :         }
    2261                 :         104 :       tree atype = build_array_type_nelts (m_limb_type, nelts);
    2262                 :         104 :       tree var = create_tmp_var (atype);
    2263                 :         104 :       tree t1 = op;
    2264                 :         104 :       if (!useless_type_conversion_p (m_limb_type, op_type))
    2265                 :         104 :         t1 = add_cast (m_limb_type, t1);
    2266                 :         104 :       tree v = build4 (ARRAY_REF, m_limb_type, var, size_zero_node,
    2267                 :             :                        NULL_TREE, NULL_TREE);
    2268                 :         104 :       gimple *g = gimple_build_assign (v, t1);
    2269                 :         104 :       insert_before (g);
    2270                 :         104 :       if (nelts > 1)
    2271                 :             :         {
    2272                 :          13 :           tree lp = build_int_cst (unsigned_type_node, limb_prec);
    2273                 :          13 :           g = gimple_build_assign (make_ssa_name (op_type),
    2274                 :             :                                    RSHIFT_EXPR, op, lp);
    2275                 :          13 :           insert_before (g);
    2276                 :          13 :           tree t2 = gimple_assign_lhs (g);
    2277                 :          13 :           t2 = add_cast (m_limb_type, t2);
    2278                 :          13 :           v = build4 (ARRAY_REF, m_limb_type, var, size_one_node,
    2279                 :             :                       NULL_TREE, NULL_TREE);
    2280                 :          13 :           g = gimple_build_assign (v, t2);
    2281                 :          13 :           insert_before (g);
    2282                 :             :         }
    2283                 :         104 :       tree ret = build_fold_addr_expr (var);
    2284                 :         104 :       if (!stmt_ends_bb_p (gsi_stmt (m_gsi)))
    2285                 :             :         {
    2286                 :         104 :           tree clobber = build_clobber (atype, CLOBBER_STORAGE_END);
    2287                 :         104 :           g = gimple_build_assign (var, clobber);
    2288                 :         104 :           gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
    2289                 :             :         }
    2290                 :         104 :       m_loc = loc_save;
    2291                 :         104 :       return ret;
    2292                 :             :     }
    2293                 :        3433 :   switch (TREE_CODE (op))
    2294                 :             :     {
    2295                 :        2617 :     case SSA_NAME:
    2296                 :        2617 :       if (m_names == NULL
    2297                 :        2617 :           || !bitmap_bit_p (m_names, SSA_NAME_VERSION (op)))
    2298                 :             :         {
    2299                 :          77 :           gimple *g = SSA_NAME_DEF_STMT (op);
    2300                 :          77 :           tree ret;
    2301                 :          77 :           m_loc = gimple_location (g);
    2302                 :          77 :           if (gimple_assign_load_p (g))
    2303                 :             :             {
    2304                 :          31 :               *prec = range_to_prec (op, NULL);
    2305                 :          31 :               if (prec_stored)
    2306                 :          12 :                 *prec_stored = (TYPE_UNSIGNED (TREE_TYPE (op))
    2307                 :           6 :                                 ? TYPE_PRECISION (TREE_TYPE (op))
    2308                 :           6 :                                 : -TYPE_PRECISION (TREE_TYPE (op)));
    2309                 :          31 :               ret = build_fold_addr_expr (gimple_assign_rhs1 (g));
    2310                 :          31 :               ret = force_gimple_operand_gsi (&m_gsi, ret, true,
    2311                 :             :                                               NULL_TREE, true, GSI_SAME_STMT);
    2312                 :             :             }
    2313                 :          46 :           else if (gimple_code (g) == GIMPLE_NOP)
    2314                 :             :             {
    2315                 :           1 :               *prec = TYPE_UNSIGNED (TREE_TYPE (op)) ? limb_prec : -limb_prec;
    2316                 :           1 :               if (prec_stored)
    2317                 :           0 :                 *prec_stored = *prec;
    2318                 :           1 :               tree var = create_tmp_var (m_limb_type);
    2319                 :           1 :               TREE_ADDRESSABLE (var) = 1;
    2320                 :           1 :               ret = build_fold_addr_expr (var);
    2321                 :           1 :               if (!stmt_ends_bb_p (gsi_stmt (m_gsi)))
    2322                 :             :                 {
    2323                 :           1 :                   tree clobber = build_clobber (m_limb_type,
    2324                 :             :                                                 CLOBBER_STORAGE_END);
    2325                 :           1 :                   g = gimple_build_assign (var, clobber);
    2326                 :           1 :                   gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
    2327                 :             :                 }
    2328                 :             :             }
    2329                 :             :           else
    2330                 :             :             {
    2331                 :          45 :               gcc_assert (gimple_assign_cast_p (g));
    2332                 :          45 :               tree rhs1 = gimple_assign_rhs1 (g);
    2333                 :          45 :               bitint_prec_kind kind = bitint_prec_small;
    2334                 :          45 :               if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR)
    2335                 :           1 :                 rhs1 = TREE_OPERAND (rhs1, 0);
    2336                 :          45 :               gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (rhs1)));
    2337                 :          45 :               if (TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE)
    2338                 :          40 :                 kind = bitint_precision_kind (TREE_TYPE (rhs1));
    2339                 :          40 :               if (kind >= bitint_prec_large)
    2340                 :             :                 {
    2341                 :          14 :                   tree lhs_type = TREE_TYPE (op);
    2342                 :          14 :                   tree rhs_type = TREE_TYPE (rhs1);
    2343                 :          14 :                   int prec_stored_val = 0;
    2344                 :          14 :                   ret = handle_operand_addr (rhs1, g, &prec_stored_val, prec);
    2345                 :          14 :                   if (TYPE_PRECISION (lhs_type) > TYPE_PRECISION (rhs_type))
    2346                 :             :                     {
    2347                 :           4 :                       if (TYPE_UNSIGNED (lhs_type)
    2348                 :           4 :                           && !TYPE_UNSIGNED (rhs_type))
    2349                 :           1 :                         gcc_assert (*prec >= 0 || prec_stored == NULL);
    2350                 :             :                     }
    2351                 :             :                   else
    2352                 :             :                     {
    2353                 :          10 :                       if (*prec > 0 && *prec < TYPE_PRECISION (lhs_type))
    2354                 :             :                         ;
    2355                 :          10 :                       else if (TYPE_UNSIGNED (lhs_type))
    2356                 :             :                         {
    2357                 :           8 :                           gcc_assert (*prec > 0
    2358                 :             :                                       || prec_stored_val > 0
    2359                 :             :                                       || (-prec_stored_val
    2360                 :             :                                           >= TYPE_PRECISION (lhs_type)));
    2361                 :           8 :                           *prec = TYPE_PRECISION (lhs_type);
    2362                 :             :                         }
    2363                 :           2 :                       else if (*prec < 0 && -*prec < TYPE_PRECISION (lhs_type))
    2364                 :             :                         ;
    2365                 :             :                       else
    2366                 :           2 :                         *prec = -TYPE_PRECISION (lhs_type);
    2367                 :             :                     }
    2368                 :             :                 }
    2369                 :             :               else
    2370                 :             :                 {
    2371                 :          31 :                   op = rhs1;
    2372                 :          31 :                   stmt = g;
    2373                 :          31 :                   goto do_int;
    2374                 :             :                 }
    2375                 :             :             }
    2376                 :          46 :           m_loc = loc_save;
    2377                 :          46 :           return ret;
    2378                 :             :         }
    2379                 :             :       else
    2380                 :             :         {
    2381                 :        2540 :           int p = var_to_partition (m_map, op);
    2382                 :        2540 :           gcc_assert (m_vars[p] != NULL_TREE);
    2383                 :        2540 :           *prec = range_to_prec (op, stmt);
    2384                 :        2540 :           if (prec_stored)
    2385                 :          16 :             *prec_stored = (TYPE_UNSIGNED (TREE_TYPE (op))
    2386                 :           8 :                             ? TYPE_PRECISION (TREE_TYPE (op))
    2387                 :           3 :                             : -TYPE_PRECISION (TREE_TYPE (op)));
    2388                 :        2540 :           return build_fold_addr_expr (m_vars[p]);
    2389                 :             :         }
    2390                 :         816 :     case INTEGER_CST:
    2391                 :         816 :       unsigned int min_prec, mp;
    2392                 :         816 :       tree type;
    2393                 :         816 :       w = wi::to_wide (op);
    2394                 :         816 :       if (tree_int_cst_sgn (op) >= 0)
    2395                 :             :         {
    2396                 :         601 :           min_prec = wi::min_precision (w, UNSIGNED);
    2397                 :         601 :           *prec = MAX (min_prec, 1);
    2398                 :             :         }
    2399                 :             :       else
    2400                 :             :         {
    2401                 :         215 :           min_prec = wi::min_precision (w, SIGNED);
    2402                 :         215 :           *prec = MIN ((int) -min_prec, -2);
    2403                 :             :         }
    2404                 :         816 :       mp = CEIL (min_prec, limb_prec) * limb_prec;
    2405                 :         816 :       if (mp == 0)
    2406                 :             :         mp = 1;
    2407                 :         816 :       if (mp >= (unsigned) TYPE_PRECISION (TREE_TYPE (op))
    2408                 :         816 :           && (TREE_CODE (TREE_TYPE (op)) == BITINT_TYPE
    2409                 :           5 :               || TYPE_PRECISION (TREE_TYPE (op)) <= limb_prec))
    2410                 :         288 :         type = TREE_TYPE (op);
    2411                 :             :       else
    2412                 :         528 :         type = build_bitint_type (mp, 1);
    2413                 :         816 :       if (TREE_CODE (type) != BITINT_TYPE
    2414                 :         816 :           || bitint_precision_kind (type) == bitint_prec_small)
    2415                 :             :         {
    2416                 :         547 :           if (TYPE_PRECISION (type) <= limb_prec)
    2417                 :         547 :             type = m_limb_type;
    2418                 :             :           else
    2419                 :             :             {
    2420                 :           0 :               while (bitint_precision_kind (mp) == bitint_prec_small)
    2421                 :           0 :                 mp += limb_prec;
    2422                 :             :               /* This case is for targets which e.g. have 64-bit
    2423                 :             :                  limb but categorize up to 128-bits _BitInts as
    2424                 :             :                  small.  We could use type of m_limb_type[2] and
    2425                 :             :                  similar instead to save space.  */
    2426                 :           0 :               type = build_bitint_type (mp, 1);
    2427                 :             :             }
    2428                 :             :         }
    2429                 :         816 :       if (prec_stored)
    2430                 :             :         {
    2431                 :           0 :           if (tree_int_cst_sgn (op) >= 0)
    2432                 :           0 :             *prec_stored = MAX (TYPE_PRECISION (type), 1);
    2433                 :             :           else
    2434                 :           0 :             *prec_stored = MIN ((int) -TYPE_PRECISION (type), -2);
    2435                 :             :         }
    2436                 :         816 :       op = tree_output_constant_def (fold_convert (type, op));
    2437                 :         816 :       return build_fold_addr_expr (op);
    2438                 :           0 :     default:
    2439                 :           0 :       gcc_unreachable ();
    2440                 :             :     }
    2441                 :        3506 : }
    2442                 :             : 
    2443                 :             : /* Helper function, create a loop before the current location,
    2444                 :             :    start with sizetype INIT value from the preheader edge.  Return
    2445                 :             :    a PHI result and set *IDX_NEXT to SSA_NAME it creates and uses
    2446                 :             :    from the latch edge.  */
    2447                 :             : 
    2448                 :             : tree
    2449                 :       13597 : bitint_large_huge::create_loop (tree init, tree *idx_next)
    2450                 :             : {
    2451                 :       13597 :   if (!gsi_end_p (m_gsi))
    2452                 :       11648 :     gsi_prev (&m_gsi);
    2453                 :             :   else
    2454                 :        3898 :     m_gsi = gsi_last_bb (gsi_bb (m_gsi));
    2455                 :       13597 :   edge e1 = split_block (gsi_bb (m_gsi), gsi_stmt (m_gsi));
    2456                 :       13597 :   edge e2 = split_block (e1->dest, (gimple *) NULL);
    2457                 :       13597 :   edge e3 = make_edge (e1->dest, e1->dest, EDGE_TRUE_VALUE);
    2458                 :       13597 :   e3->probability = profile_probability::very_unlikely ();
    2459                 :       13597 :   e2->flags = EDGE_FALSE_VALUE;
    2460                 :       13597 :   e2->probability = e3->probability.invert ();
    2461                 :       13597 :   tree idx = make_ssa_name (sizetype);
    2462                 :       13597 :   gphi *phi = create_phi_node (idx, e1->dest);
    2463                 :       13597 :   add_phi_arg (phi, init, e1, UNKNOWN_LOCATION);
    2464                 :       13597 :   *idx_next = make_ssa_name (sizetype);
    2465                 :       13597 :   add_phi_arg (phi, *idx_next, e3, UNKNOWN_LOCATION);
    2466                 :       13597 :   m_gsi = gsi_after_labels (e1->dest);
    2467                 :       13597 :   m_bb = e1->dest;
    2468                 :       13597 :   m_preheader_bb = e1->src;
    2469                 :       13597 :   class loop *loop = alloc_loop ();
    2470                 :       13597 :   loop->header = e1->dest;
    2471                 :       13597 :   add_loop (loop, e1->src->loop_father);
    2472                 :       13597 :   return idx;
    2473                 :             : }
    2474                 :             : 
    2475                 :             : /* Lower large/huge _BitInt statement mergeable or similar STMT which can be
    2476                 :             :    lowered using iteration from the least significant limb up to the most
    2477                 :             :    significant limb.  For large _BitInt it is emitted as straight line code
    2478                 :             :    before current location, for huge _BitInt as a loop handling two limbs
    2479                 :             :    at once, followed by handling up to limbs in straight line code (at most
    2480                 :             :    one full and one partial limb).  It can also handle EQ_EXPR/NE_EXPR
    2481                 :             :    comparisons, in that case CMP_CODE should be the comparison code and
    2482                 :             :    CMP_OP1/CMP_OP2 the comparison operands.  */
    2483                 :             : 
    2484                 :             : tree
    2485                 :       22373 : bitint_large_huge::lower_mergeable_stmt (gimple *stmt, tree_code &cmp_code,
    2486                 :             :                                          tree cmp_op1, tree cmp_op2)
    2487                 :             : {
    2488                 :       22373 :   bool eq_p = cmp_code != ERROR_MARK;
    2489                 :       22373 :   tree type;
    2490                 :       22373 :   if (eq_p)
    2491                 :        6240 :     type = TREE_TYPE (cmp_op1);
    2492                 :             :   else
    2493                 :       16133 :     type = TREE_TYPE (gimple_assign_lhs (stmt));
    2494                 :       22373 :   gcc_assert (TREE_CODE (type) == BITINT_TYPE);
    2495                 :       22373 :   bitint_prec_kind kind = bitint_precision_kind (type);
    2496                 :       22373 :   gcc_assert (kind >= bitint_prec_large);
    2497                 :       22373 :   gimple *g;
    2498                 :       22373 :   tree lhs = gimple_get_lhs (stmt);
    2499                 :       22373 :   tree rhs1, lhs_type = lhs ? TREE_TYPE (lhs) : NULL_TREE;
    2500                 :       16565 :   if (lhs
    2501                 :       16565 :       && TREE_CODE (lhs) == SSA_NAME
    2502                 :        8390 :       && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
    2503                 :        7958 :       && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large)
    2504                 :             :     {
    2505                 :        7958 :       int p = var_to_partition (m_map, lhs);
    2506                 :        7958 :       gcc_assert (m_vars[p] != NULL_TREE);
    2507                 :        7958 :       m_lhs = lhs = m_vars[p];
    2508                 :             :     }
    2509                 :       22373 :   unsigned cnt, rem = 0, end = 0, prec = TYPE_PRECISION (type);
    2510                 :       22373 :   bool sext = false;
    2511                 :       22373 :   tree ext = NULL_TREE, store_operand = NULL_TREE;
    2512                 :       22373 :   bool eh = false;
    2513                 :       22373 :   basic_block eh_pad = NULL;
    2514                 :       22373 :   tree nlhs = NULL_TREE;
    2515                 :       22373 :   unsigned HOST_WIDE_INT bo_idx = 0;
    2516                 :       22373 :   unsigned HOST_WIDE_INT bo_bit = 0;
    2517                 :       22373 :   tree bf_cur = NULL_TREE, bf_next = NULL_TREE;
    2518                 :       22373 :   if (gimple_store_p (stmt))
    2519                 :             :     {
    2520                 :        8175 :       store_operand = gimple_assign_rhs1 (stmt);
    2521                 :        8175 :       eh = stmt_ends_bb_p (stmt);
    2522                 :        8175 :       if (eh)
    2523                 :             :         {
    2524                 :           2 :           edge e;
    2525                 :           2 :           edge_iterator ei;
    2526                 :           2 :           basic_block bb = gimple_bb (stmt);
    2527                 :             : 
    2528                 :           2 :           FOR_EACH_EDGE (e, ei, bb->succs)
    2529                 :           2 :             if (e->flags & EDGE_EH)
    2530                 :             :               {
    2531                 :           2 :                 eh_pad = e->dest;
    2532                 :           2 :                 break;
    2533                 :             :               }
    2534                 :             :         }
    2535                 :        8175 :       if (TREE_CODE (lhs) == COMPONENT_REF
    2536                 :        8175 :           && DECL_BIT_FIELD_TYPE (TREE_OPERAND (lhs, 1)))
    2537                 :             :         {
    2538                 :         100 :           tree fld = TREE_OPERAND (lhs, 1);
    2539                 :         100 :           gcc_assert (tree_fits_uhwi_p (DECL_FIELD_BIT_OFFSET (fld)));
    2540                 :         100 :           tree repr = DECL_BIT_FIELD_REPRESENTATIVE (fld);
    2541                 :         100 :           poly_int64 bitoffset;
    2542                 :         100 :           poly_uint64 field_offset, repr_offset;
    2543                 :         100 :           if ((tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld)) % BITS_PER_UNIT) == 0)
    2544                 :             :             nlhs = lhs;
    2545                 :             :           else
    2546                 :             :             {
    2547                 :          87 :               bool var_field_off = false;
    2548                 :          87 :               if (poly_int_tree_p (DECL_FIELD_OFFSET (fld), &field_offset)
    2549                 :         174 :                   && poly_int_tree_p (DECL_FIELD_OFFSET (repr), &repr_offset))
    2550                 :          87 :                 bitoffset = (field_offset - repr_offset) * BITS_PER_UNIT;
    2551                 :             :               else
    2552                 :             :                 {
    2553                 :             :                   bitoffset = 0;
    2554                 :             :                   var_field_off = true;
    2555                 :             :                 }
    2556                 :          87 :               bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld))
    2557                 :          87 :                             - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
    2558                 :         174 :               nlhs = build3 (COMPONENT_REF, TREE_TYPE (repr),
    2559                 :          87 :                              TREE_OPERAND (lhs, 0), repr,
    2560                 :             :                              var_field_off
    2561                 :           0 :                              ? TREE_OPERAND (lhs, 2) : NULL_TREE);
    2562                 :          87 :               HOST_WIDE_INT bo = bitoffset.to_constant ();
    2563                 :          87 :               bo_idx = (unsigned HOST_WIDE_INT) bo / limb_prec;
    2564                 :          87 :               bo_bit = (unsigned HOST_WIDE_INT) bo % limb_prec;
    2565                 :             :             }
    2566                 :             :         }
    2567                 :             :     }
    2568                 :       22373 :   if ((store_operand
    2569                 :        8175 :        && TREE_CODE (store_operand) == SSA_NAME
    2570                 :        7232 :        && (m_names == NULL
    2571                 :        7216 :            || !bitmap_bit_p (m_names, SSA_NAME_VERSION (store_operand)))
    2572                 :        1048 :        && gimple_assign_cast_p (SSA_NAME_DEF_STMT (store_operand)))
    2573                 :       30062 :       || gimple_assign_cast_p (stmt))
    2574                 :             :     {
    2575                 :        1930 :       rhs1 = gimple_assign_rhs1 (store_operand
    2576                 :         486 :                                  ? SSA_NAME_DEF_STMT (store_operand)
    2577                 :             :                                  : stmt);
    2578                 :        1444 :       if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR)
    2579                 :           2 :         rhs1 = TREE_OPERAND (rhs1, 0);
    2580                 :             :       /* Optimize mergeable ops ending with widening cast to _BitInt
    2581                 :             :          (or followed by store).  We can lower just the limbs of the
    2582                 :             :          cast operand and widen afterwards.  */
    2583                 :        1444 :       if (TREE_CODE (rhs1) == SSA_NAME
    2584                 :        1444 :           && (m_names == NULL
    2585                 :        1439 :               || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1)))
    2586                 :         524 :           && TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE
    2587                 :         398 :           && bitint_precision_kind (TREE_TYPE (rhs1)) >= bitint_prec_large
    2588                 :        1810 :           && (CEIL ((unsigned) TYPE_PRECISION (TREE_TYPE (rhs1)),
    2589                 :         366 :                     limb_prec) < CEIL (prec, limb_prec)
    2590                 :         294 :               || (kind == bitint_prec_huge
    2591                 :         251 :                   && TYPE_PRECISION (TREE_TYPE (rhs1)) < prec)))
    2592                 :             :         {
    2593                 :          75 :           store_operand = rhs1;
    2594                 :          75 :           prec = TYPE_PRECISION (TREE_TYPE (rhs1));
    2595                 :          75 :           kind = bitint_precision_kind (TREE_TYPE (rhs1));
    2596                 :          75 :           if (!TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    2597                 :          22 :             sext = true;
    2598                 :             :         }
    2599                 :             :     }
    2600                 :       22373 :   tree idx = NULL_TREE, idx_first = NULL_TREE, idx_next = NULL_TREE;
    2601                 :       22373 :   if (kind == bitint_prec_large)
    2602                 :       11913 :     cnt = CEIL (prec, limb_prec);
    2603                 :             :   else
    2604                 :             :     {
    2605                 :       10460 :       rem = (prec % (2 * limb_prec));
    2606                 :       10460 :       end = (prec - rem) / limb_prec;
    2607                 :       10460 :       cnt = 2 + CEIL (rem, limb_prec);
    2608                 :       10460 :       idx = idx_first = create_loop (size_zero_node, &idx_next);
    2609                 :             :     }
    2610                 :             : 
    2611                 :       22373 :   basic_block edge_bb = NULL;
    2612                 :       22373 :   if (eq_p)
    2613                 :             :     {
    2614                 :        6240 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    2615                 :        6240 :       gsi_prev (&gsi);
    2616                 :        6240 :       edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    2617                 :        6240 :       edge_bb = e->src;
    2618                 :        6240 :       if (kind == bitint_prec_large)
    2619                 :        6932 :         m_gsi = gsi_end_bb (edge_bb);
    2620                 :             :     }
    2621                 :             :   else
    2622                 :       16133 :     m_after_stmt = stmt;
    2623                 :       22373 :   if (kind != bitint_prec_large)
    2624                 :       10460 :     m_upwards_2limb = end;
    2625                 :       22373 :   m_upwards = true;
    2626                 :             : 
    2627                 :       22373 :   bool separate_ext
    2628                 :       22373 :     = (prec != (unsigned) TYPE_PRECISION (type)
    2629                 :       22373 :        && (CEIL ((unsigned) TYPE_PRECISION (type), limb_prec)
    2630                 :          75 :            > CEIL (prec, limb_prec)));
    2631                 :             : 
    2632                 :       89404 :   for (unsigned i = 0; i < cnt; i++)
    2633                 :             :     {
    2634                 :       67031 :       m_data_cnt = 0;
    2635                 :       67031 :       if (kind == bitint_prec_large)
    2636                 :       36154 :         idx = size_int (i);
    2637                 :       30877 :       else if (i >= 2)
    2638                 :        9957 :         idx = size_int (end + (i > 2));
    2639                 :       67031 :       if (eq_p)
    2640                 :             :         {
    2641                 :       18721 :           rhs1 = handle_operand (cmp_op1, idx);
    2642                 :       18721 :           tree rhs2 = handle_operand (cmp_op2, idx);
    2643                 :       18721 :           g = gimple_build_cond (NE_EXPR, rhs1, rhs2, NULL_TREE, NULL_TREE);
    2644                 :       18721 :           insert_before (g);
    2645                 :       18721 :           edge e1 = split_block (gsi_bb (m_gsi), g);
    2646                 :       18721 :           e1->flags = EDGE_FALSE_VALUE;
    2647                 :       18721 :           edge e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE);
    2648                 :       18721 :           e1->probability = profile_probability::unlikely ();
    2649                 :       18721 :           e2->probability = e1->probability.invert ();
    2650                 :       18721 :           if (i == 0)
    2651                 :        6240 :             set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    2652                 :       18721 :           m_gsi = gsi_after_labels (e1->dest);
    2653                 :             :         }
    2654                 :             :       else
    2655                 :             :         {
    2656                 :       48310 :           if (store_operand)
    2657                 :       24716 :             rhs1 = handle_operand (store_operand, idx);
    2658                 :             :           else
    2659                 :       23594 :             rhs1 = handle_stmt (stmt, idx);
    2660                 :       48310 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1)))
    2661                 :       11490 :             rhs1 = add_cast (m_limb_type, rhs1);
    2662                 :       48310 :           if (sext && i == cnt - 1)
    2663                 :       48310 :             ext = rhs1;
    2664                 :       48310 :           tree nidx = idx;
    2665                 :       48310 :           if (bo_idx)
    2666                 :             :             {
    2667                 :          12 :               if (tree_fits_uhwi_p (idx))
    2668                 :          12 :                 nidx = size_int (tree_to_uhwi (idx) + bo_idx);
    2669                 :             :               else
    2670                 :             :                 {
    2671                 :           0 :                   nidx = make_ssa_name (sizetype);
    2672                 :           0 :                   g = gimple_build_assign (nidx, PLUS_EXPR, idx,
    2673                 :             :                                            size_int (bo_idx));
    2674                 :           0 :                   insert_before (g);
    2675                 :             :                 }
    2676                 :             :             }
    2677                 :       48310 :           bool done = false;
    2678                 :       48310 :           basic_block new_bb = NULL;
    2679                 :             :           /* Handle stores into bit-fields.  */
    2680                 :       48310 :           if (bo_bit)
    2681                 :             :             {
    2682                 :         278 :               if (i == 0)
    2683                 :             :                 {
    2684                 :          87 :                   edge e2 = NULL;
    2685                 :          87 :                   if (kind != bitint_prec_large)
    2686                 :             :                     {
    2687                 :          69 :                       prepare_data_in_out (build_zero_cst (m_limb_type),
    2688                 :             :                                            idx, &bf_next);
    2689                 :          69 :                       bf_next = m_data.pop ();
    2690                 :          69 :                       bf_cur = m_data.pop ();
    2691                 :          69 :                       g = gimple_build_cond (EQ_EXPR, idx, size_zero_node,
    2692                 :             :                                              NULL_TREE, NULL_TREE);
    2693                 :          69 :                       edge edge_true;
    2694                 :          69 :                       if_then_else (g, profile_probability::unlikely (),
    2695                 :             :                                     edge_true, e2);
    2696                 :          69 :                       new_bb = e2->dest;
    2697                 :             :                     }
    2698                 :          87 :                   tree ftype
    2699                 :          87 :                     = build_nonstandard_integer_type (limb_prec - bo_bit, 1);
    2700                 :          87 :                   tree bfr = build_bit_field_ref (ftype, unshare_expr (nlhs),
    2701                 :             :                                                   limb_prec - bo_bit,
    2702                 :          87 :                                                   bo_idx * limb_prec + bo_bit);
    2703                 :          87 :                   tree t = add_cast (ftype, rhs1);
    2704                 :          87 :                   g = gimple_build_assign (bfr, t);
    2705                 :          87 :                   insert_before (g);
    2706                 :          87 :                   if (eh)
    2707                 :             :                     {
    2708                 :           0 :                       maybe_duplicate_eh_stmt (g, stmt);
    2709                 :           0 :                       if (eh_pad)
    2710                 :             :                         {
    2711                 :           0 :                           edge e = split_block (gsi_bb (m_gsi), g);
    2712                 :           0 :                           m_gsi = gsi_after_labels (e->dest);
    2713                 :           0 :                           add_eh_edge (e->src,
    2714                 :             :                                        find_edge (gimple_bb (stmt), eh_pad));
    2715                 :             :                         }
    2716                 :             :                     }
    2717                 :          87 :                   if (kind == bitint_prec_large)
    2718                 :             :                     {
    2719                 :             :                       bf_cur = rhs1;
    2720                 :             :                       done = true;
    2721                 :             :                     }
    2722                 :          69 :                   else if (e2)
    2723                 :          69 :                     m_gsi = gsi_after_labels (e2->src);
    2724                 :             :                 }
    2725                 :         278 :               if (!done)
    2726                 :             :                 {
    2727                 :         260 :                   tree t1 = make_ssa_name (m_limb_type);
    2728                 :         260 :                   tree t2 = make_ssa_name (m_limb_type);
    2729                 :         260 :                   tree t3 = make_ssa_name (m_limb_type);
    2730                 :         260 :                   g = gimple_build_assign (t1, RSHIFT_EXPR, bf_cur,
    2731                 :             :                                            build_int_cst (unsigned_type_node,
    2732                 :         260 :                                                           limb_prec - bo_bit));
    2733                 :         260 :                   insert_before (g);
    2734                 :         260 :                   g = gimple_build_assign (t2, LSHIFT_EXPR, rhs1,
    2735                 :             :                                            build_int_cst (unsigned_type_node,
    2736                 :             :                                                           bo_bit));
    2737                 :         260 :                   insert_before (g);
    2738                 :         260 :                   bf_cur = rhs1;
    2739                 :         260 :                   g = gimple_build_assign (t3, BIT_IOR_EXPR, t1, t2);
    2740                 :         260 :                   insert_before (g);
    2741                 :         260 :                   rhs1 = t3;
    2742                 :         260 :                   if (bf_next && i == 1)
    2743                 :             :                     {
    2744                 :          69 :                       g = gimple_build_assign (bf_next, bf_cur);
    2745                 :          69 :                       insert_before (g);
    2746                 :             :                     }
    2747                 :             :                 }
    2748                 :             :             }
    2749                 :       48310 :           if (!done)
    2750                 :             :             {
    2751                 :             :               /* Handle bit-field access to partial last limb if needed.  */
    2752                 :       48292 :               if (nlhs
    2753                 :         293 :                   && i == cnt - 1
    2754                 :         100 :                   && !separate_ext
    2755                 :         100 :                   && tree_fits_uhwi_p (idx))
    2756                 :             :                 {
    2757                 :          82 :                   unsigned int tprec = TYPE_PRECISION (type);
    2758                 :          82 :                   unsigned int rprec = (tprec - 1) % limb_prec + 1;
    2759                 :          82 :                   if (rprec + bo_bit < (unsigned) limb_prec)
    2760                 :             :                     {
    2761                 :          32 :                       tree ftype
    2762                 :          32 :                         = build_nonstandard_integer_type (rprec + bo_bit, 1);
    2763                 :          32 :                       tree bfr
    2764                 :          32 :                         = build_bit_field_ref (ftype, unshare_expr (nlhs),
    2765                 :             :                                                rprec + bo_bit,
    2766                 :          32 :                                                (bo_idx + tprec / limb_prec)
    2767                 :          32 :                                                * limb_prec);
    2768                 :          32 :                       tree t = add_cast (ftype, rhs1);
    2769                 :          32 :                       g = gimple_build_assign (bfr, t);
    2770                 :          32 :                       done = true;
    2771                 :          32 :                       bf_cur = NULL_TREE;
    2772                 :             :                     }
    2773                 :          50 :                   else if (rprec + bo_bit == (unsigned) limb_prec)
    2774                 :       48292 :                     bf_cur = NULL_TREE;
    2775                 :             :                 }
    2776                 :             :               /* Otherwise, stores to any other lhs.  */
    2777                 :       48292 :               if (!done)
    2778                 :             :                 {
    2779                 :       96259 :                   tree l = limb_access (nlhs ? NULL_TREE : lhs_type,
    2780                 :             :                                         nlhs ? nlhs : lhs, nidx, true);
    2781                 :       48260 :                   g = gimple_build_assign (l, rhs1);
    2782                 :             :                 }
    2783                 :       48292 :               insert_before (g);
    2784                 :       48292 :               if (eh)
    2785                 :             :                 {
    2786                 :           6 :                   maybe_duplicate_eh_stmt (g, stmt);
    2787                 :           6 :                   if (eh_pad)
    2788                 :             :                     {
    2789                 :           6 :                       edge e = split_block (gsi_bb (m_gsi), g);
    2790                 :           6 :                       m_gsi = gsi_after_labels (e->dest);
    2791                 :           6 :                       add_eh_edge (e->src,
    2792                 :             :                                    find_edge (gimple_bb (stmt), eh_pad));
    2793                 :             :                     }
    2794                 :             :                 }
    2795                 :       48292 :               if (new_bb)
    2796                 :          69 :                 m_gsi = gsi_after_labels (new_bb);
    2797                 :             :             }
    2798                 :             :         }
    2799                 :       67031 :       m_first = false;
    2800                 :       67031 :       if (kind == bitint_prec_huge && i <= 1)
    2801                 :             :         {
    2802                 :       20920 :           if (i == 0)
    2803                 :             :             {
    2804                 :       10460 :               idx = make_ssa_name (sizetype);
    2805                 :       10460 :               g = gimple_build_assign (idx, PLUS_EXPR, idx_first,
    2806                 :             :                                        size_one_node);
    2807                 :       10460 :               insert_before (g);
    2808                 :             :             }
    2809                 :             :           else
    2810                 :             :             {
    2811                 :       10460 :               g = gimple_build_assign (idx_next, PLUS_EXPR, idx_first,
    2812                 :       10460 :                                        size_int (2));
    2813                 :       10460 :               insert_before (g);
    2814                 :       10460 :               g = gimple_build_cond (NE_EXPR, idx_next, size_int (end),
    2815                 :             :                                      NULL_TREE, NULL_TREE);
    2816                 :       10460 :               insert_before (g);
    2817                 :       10460 :               if (eq_p)
    2818                 :        2774 :                 m_gsi = gsi_after_labels (edge_bb);
    2819                 :             :               else
    2820                 :        7686 :                 m_gsi = gsi_for_stmt (stmt);
    2821                 :       10460 :               m_bb = NULL;
    2822                 :             :             }
    2823                 :             :         }
    2824                 :             :     }
    2825                 :             : 
    2826                 :       22373 :   if (separate_ext)
    2827                 :             :     {
    2828                 :          72 :       if (sext)
    2829                 :             :         {
    2830                 :          19 :           ext = add_cast (signed_type_for (m_limb_type), ext);
    2831                 :          38 :           tree lpm1 = build_int_cst (unsigned_type_node,
    2832                 :          19 :                                      limb_prec - 1);
    2833                 :          19 :           tree n = make_ssa_name (TREE_TYPE (ext));
    2834                 :          19 :           g = gimple_build_assign (n, RSHIFT_EXPR, ext, lpm1);
    2835                 :          19 :           insert_before (g);
    2836                 :          19 :           ext = add_cast (m_limb_type, n);
    2837                 :             :         }
    2838                 :             :       else
    2839                 :          53 :         ext = build_zero_cst (m_limb_type);
    2840                 :          72 :       kind = bitint_precision_kind (type);
    2841                 :          72 :       unsigned start = CEIL (prec, limb_prec);
    2842                 :          72 :       prec = TYPE_PRECISION (type);
    2843                 :          72 :       idx = idx_first = idx_next = NULL_TREE;
    2844                 :          72 :       if (prec <= (start + 2 + (bo_bit != 0)) * limb_prec)
    2845                 :             :         kind = bitint_prec_large;
    2846                 :          52 :       if (kind == bitint_prec_large)
    2847                 :          20 :         cnt = CEIL (prec, limb_prec) - start;
    2848                 :             :       else
    2849                 :             :         {
    2850                 :          52 :           rem = prec % limb_prec;
    2851                 :          52 :           end = (prec - rem) / limb_prec;
    2852                 :         104 :           cnt = (bo_bit != 0) + 1 + (rem != 0);
    2853                 :             :         }
    2854                 :         174 :       for (unsigned i = 0; i < cnt; i++)
    2855                 :             :         {
    2856                 :         102 :           if (kind == bitint_prec_large || (i == 0 && bo_bit != 0))
    2857                 :          20 :             idx = size_int (start + i);
    2858                 :          82 :           else if (i == cnt - 1 && (rem != 0))
    2859                 :          30 :             idx = size_int (end);
    2860                 :          52 :           else if (i == (bo_bit != 0))
    2861                 :          52 :             idx = create_loop (size_int (start + i), &idx_next);
    2862                 :         102 :           rhs1 = ext;
    2863                 :         102 :           if (bf_cur != NULL_TREE && bf_cur != ext)
    2864                 :             :             {
    2865                 :           0 :               tree t1 = make_ssa_name (m_limb_type);
    2866                 :           0 :               g = gimple_build_assign (t1, RSHIFT_EXPR, bf_cur,
    2867                 :             :                                        build_int_cst (unsigned_type_node,
    2868                 :           0 :                                                       limb_prec - bo_bit));
    2869                 :           0 :               insert_before (g);
    2870                 :           0 :               if (integer_zerop (ext))
    2871                 :             :                 rhs1 = t1;
    2872                 :             :               else
    2873                 :             :                 {
    2874                 :           0 :                   tree t2 = make_ssa_name (m_limb_type);
    2875                 :           0 :                   rhs1 = make_ssa_name (m_limb_type);
    2876                 :           0 :                   g = gimple_build_assign (t2, LSHIFT_EXPR, ext,
    2877                 :             :                                            build_int_cst (unsigned_type_node,
    2878                 :             :                                                           bo_bit));
    2879                 :           0 :                   insert_before (g);
    2880                 :           0 :                   g = gimple_build_assign (rhs1, BIT_IOR_EXPR, t1, t2);
    2881                 :           0 :                   insert_before (g);
    2882                 :             :                 }
    2883                 :             :               bf_cur = ext;
    2884                 :             :             }
    2885                 :         102 :           tree nidx = idx;
    2886                 :         102 :           if (bo_idx)
    2887                 :             :             {
    2888                 :           0 :               if (tree_fits_uhwi_p (idx))
    2889                 :           0 :                 nidx = size_int (tree_to_uhwi (idx) + bo_idx);
    2890                 :             :               else
    2891                 :             :                 {
    2892                 :           0 :                   nidx = make_ssa_name (sizetype);
    2893                 :           0 :                   g = gimple_build_assign (nidx, PLUS_EXPR, idx,
    2894                 :             :                                            size_int (bo_idx));
    2895                 :           0 :                   insert_before (g);
    2896                 :             :                 }
    2897                 :             :             }
    2898                 :         102 :           bool done = false;
    2899                 :             :           /* Handle bit-field access to partial last limb if needed.  */
    2900                 :         102 :           if (nlhs && i == cnt - 1)
    2901                 :             :             {
    2902                 :           0 :               unsigned int tprec = TYPE_PRECISION (type);
    2903                 :           0 :               unsigned int rprec = (tprec - 1) % limb_prec + 1;
    2904                 :           0 :               if (rprec + bo_bit < (unsigned) limb_prec)
    2905                 :             :                 {
    2906                 :           0 :                   tree ftype
    2907                 :           0 :                     = build_nonstandard_integer_type (rprec + bo_bit, 1);
    2908                 :           0 :                   tree bfr
    2909                 :           0 :                     = build_bit_field_ref (ftype, unshare_expr (nlhs),
    2910                 :             :                                            rprec + bo_bit,
    2911                 :           0 :                                            (bo_idx + tprec / limb_prec)
    2912                 :           0 :                                            * limb_prec);
    2913                 :           0 :                   tree t = add_cast (ftype, rhs1);
    2914                 :           0 :                   g = gimple_build_assign (bfr, t);
    2915                 :           0 :                   done = true;
    2916                 :           0 :                   bf_cur = NULL_TREE;
    2917                 :             :                 }
    2918                 :           0 :               else if (rprec + bo_bit == (unsigned) limb_prec)
    2919                 :         102 :                 bf_cur = NULL_TREE;
    2920                 :             :             }
    2921                 :             :           /* Otherwise, stores to any other lhs.  */
    2922                 :         102 :           if (!done)
    2923                 :             :             {
    2924                 :         204 :               tree l = limb_access (nlhs ? NULL_TREE : lhs_type,
    2925                 :             :                                     nlhs ? nlhs : lhs, nidx, true);
    2926                 :         102 :               g = gimple_build_assign (l, rhs1);
    2927                 :             :             }
    2928                 :         102 :           insert_before (g);
    2929                 :         102 :           if (eh)
    2930                 :             :             {
    2931                 :           0 :               maybe_duplicate_eh_stmt (g, stmt);
    2932                 :           0 :               if (eh_pad)
    2933                 :             :                 {
    2934                 :           0 :                   edge e = split_block (gsi_bb (m_gsi), g);
    2935                 :           0 :                   m_gsi = gsi_after_labels (e->dest);
    2936                 :           0 :                   add_eh_edge (e->src, find_edge (gimple_bb (stmt), eh_pad));
    2937                 :             :                 }
    2938                 :             :             }
    2939                 :         102 :           if (kind == bitint_prec_huge && i == (bo_bit != 0))
    2940                 :             :             {
    2941                 :          52 :               g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    2942                 :             :                                        size_one_node);
    2943                 :          52 :               insert_before (g);
    2944                 :          52 :               g = gimple_build_cond (NE_EXPR, idx_next, size_int (end),
    2945                 :             :                                      NULL_TREE, NULL_TREE);
    2946                 :          52 :               insert_before (g);
    2947                 :          52 :               m_gsi = gsi_for_stmt (stmt);
    2948                 :          52 :               m_bb = NULL;
    2949                 :             :             }
    2950                 :             :         }
    2951                 :             :     }
    2952                 :       22373 :   if (bf_cur != NULL_TREE)
    2953                 :             :     {
    2954                 :          40 :       unsigned int tprec = TYPE_PRECISION (type);
    2955                 :          40 :       unsigned int rprec = (tprec + bo_bit) % limb_prec;
    2956                 :          40 :       tree ftype = build_nonstandard_integer_type (rprec, 1);
    2957                 :          40 :       tree bfr = build_bit_field_ref (ftype, unshare_expr (nlhs),
    2958                 :             :                                       rprec,
    2959                 :          40 :                                       (bo_idx + (tprec + bo_bit) / limb_prec)
    2960                 :             :                                       * limb_prec);
    2961                 :          40 :       rhs1 = bf_cur;
    2962                 :          40 :       if (bf_cur != ext)
    2963                 :             :         {
    2964                 :          40 :           rhs1 = make_ssa_name (TREE_TYPE (rhs1));
    2965                 :          40 :           g = gimple_build_assign (rhs1, RSHIFT_EXPR, bf_cur,
    2966                 :             :                                    build_int_cst (unsigned_type_node,
    2967                 :          40 :                                                   limb_prec - bo_bit));
    2968                 :          40 :           insert_before (g);
    2969                 :             :         }
    2970                 :          40 :       rhs1 = add_cast (ftype, rhs1);
    2971                 :          40 :       g = gimple_build_assign (bfr, rhs1);
    2972                 :          40 :       insert_before (g);
    2973                 :          40 :       if (eh)
    2974                 :             :         {
    2975                 :           0 :           maybe_duplicate_eh_stmt (g, stmt);
    2976                 :           0 :           if (eh_pad)
    2977                 :             :             {
    2978                 :           0 :               edge e = split_block (gsi_bb (m_gsi), g);
    2979                 :           0 :               m_gsi = gsi_after_labels (e->dest);
    2980                 :           0 :               add_eh_edge (e->src, find_edge (gimple_bb (stmt), eh_pad));
    2981                 :             :             }
    2982                 :             :         }
    2983                 :             :     }
    2984                 :             : 
    2985                 :       22373 :   if (gimple_store_p (stmt))
    2986                 :             :     {
    2987                 :        8175 :       unlink_stmt_vdef (stmt);
    2988                 :       16350 :       release_ssa_name (gimple_vdef (stmt));
    2989                 :        8175 :       gsi_remove (&m_gsi, true);
    2990                 :             :     }
    2991                 :       22373 :   if (eq_p)
    2992                 :             :     {
    2993                 :        6240 :       lhs = make_ssa_name (boolean_type_node);
    2994                 :        6240 :       basic_block bb = gimple_bb (stmt);
    2995                 :        6240 :       gphi *phi = create_phi_node (lhs, bb);
    2996                 :        6240 :       edge e = find_edge (gsi_bb (m_gsi), bb);
    2997                 :        6240 :       unsigned int n = EDGE_COUNT (bb->preds);
    2998                 :       31201 :       for (unsigned int i = 0; i < n; i++)
    2999                 :             :         {
    3000                 :       24961 :           edge e2 = EDGE_PRED (bb, i);
    3001                 :       24961 :           add_phi_arg (phi, e == e2 ? boolean_true_node : boolean_false_node,
    3002                 :             :                        e2, UNKNOWN_LOCATION);
    3003                 :             :         }
    3004                 :        6240 :       cmp_code = cmp_code == EQ_EXPR ? NE_EXPR : EQ_EXPR;
    3005                 :        6240 :       return lhs;
    3006                 :             :     }
    3007                 :             :   else
    3008                 :             :     return NULL_TREE;
    3009                 :             : }
    3010                 :             : 
    3011                 :             : /* Handle a large/huge _BitInt comparison statement STMT other than
    3012                 :             :    EQ_EXPR/NE_EXPR.  CMP_CODE, CMP_OP1 and CMP_OP2 meaning is like in
    3013                 :             :    lower_mergeable_stmt.  The {GT,GE,LT,LE}_EXPR comparisons are
    3014                 :             :    lowered by iteration from the most significant limb downwards to
    3015                 :             :    the least significant one, for large _BitInt in straight line code,
    3016                 :             :    otherwise with most significant limb handled in
    3017                 :             :    straight line code followed by a loop handling one limb at a time.
    3018                 :             :    Comparisons with unsigned huge _BitInt with precisions which are
    3019                 :             :    multiples of limb precision can use just the loop and don't need to
    3020                 :             :    handle most significant limb before the loop.  The loop or straight
    3021                 :             :    line code jumps to final basic block if a particular pair of limbs
    3022                 :             :    is not equal.  */
    3023                 :             : 
    3024                 :             : tree
    3025                 :         712 : bitint_large_huge::lower_comparison_stmt (gimple *stmt, tree_code &cmp_code,
    3026                 :             :                                           tree cmp_op1, tree cmp_op2)
    3027                 :             : {
    3028                 :         712 :   tree type = TREE_TYPE (cmp_op1);
    3029                 :         712 :   gcc_assert (TREE_CODE (type) == BITINT_TYPE);
    3030                 :         712 :   bitint_prec_kind kind = bitint_precision_kind (type);
    3031                 :         712 :   gcc_assert (kind >= bitint_prec_large);
    3032                 :         712 :   gimple *g;
    3033                 :         712 :   if (!TYPE_UNSIGNED (type)
    3034                 :         436 :       && integer_zerop (cmp_op2)
    3035                 :         740 :       && (cmp_code == GE_EXPR || cmp_code == LT_EXPR))
    3036                 :             :     {
    3037                 :          28 :       unsigned end = CEIL ((unsigned) TYPE_PRECISION (type), limb_prec) - 1;
    3038                 :          28 :       tree idx = size_int (end);
    3039                 :          28 :       m_data_cnt = 0;
    3040                 :          28 :       tree rhs1 = handle_operand (cmp_op1, idx);
    3041                 :          28 :       if (TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    3042                 :             :         {
    3043                 :          24 :           tree stype = signed_type_for (TREE_TYPE (rhs1));
    3044                 :          24 :           rhs1 = add_cast (stype, rhs1);
    3045                 :             :         }
    3046                 :          28 :       tree lhs = make_ssa_name (boolean_type_node);
    3047                 :          28 :       g = gimple_build_assign (lhs, cmp_code, rhs1,
    3048                 :          28 :                                build_zero_cst (TREE_TYPE (rhs1)));
    3049                 :          28 :       insert_before (g);
    3050                 :          28 :       cmp_code = NE_EXPR;
    3051                 :          28 :       return lhs;
    3052                 :             :     }
    3053                 :             : 
    3054                 :         684 :   unsigned cnt, rem = 0, end = 0;
    3055                 :         684 :   tree idx = NULL_TREE, idx_next = NULL_TREE;
    3056                 :         684 :   if (kind == bitint_prec_large)
    3057                 :         376 :     cnt = CEIL ((unsigned) TYPE_PRECISION (type), limb_prec);
    3058                 :             :   else
    3059                 :             :     {
    3060                 :         308 :       rem = ((unsigned) TYPE_PRECISION (type) % limb_prec);
    3061                 :         308 :       if (rem == 0 && !TYPE_UNSIGNED (type))
    3062                 :             :         rem = limb_prec;
    3063                 :         308 :       end = ((unsigned) TYPE_PRECISION (type) - rem) / limb_prec;
    3064                 :         308 :       cnt = 1 + (rem != 0);
    3065                 :             :     }
    3066                 :             : 
    3067                 :         684 :   basic_block edge_bb = NULL;
    3068                 :         684 :   gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    3069                 :         684 :   gsi_prev (&gsi);
    3070                 :         684 :   edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    3071                 :         684 :   edge_bb = e->src;
    3072                 :         684 :   m_gsi = gsi_end_bb (edge_bb);
    3073                 :             : 
    3074                 :         684 :   edge *edges = XALLOCAVEC (edge, cnt * 2);
    3075                 :        2487 :   for (unsigned i = 0; i < cnt; i++)
    3076                 :             :     {
    3077                 :        1803 :       m_data_cnt = 0;
    3078                 :        1803 :       if (kind == bitint_prec_large)
    3079                 :        1242 :         idx = size_int (cnt - i - 1);
    3080                 :         561 :       else if (i == cnt - 1)
    3081                 :         308 :         idx = create_loop (size_int (end - 1), &idx_next);
    3082                 :             :       else
    3083                 :         253 :         idx = size_int (end);
    3084                 :        1803 :       tree rhs1 = handle_operand (cmp_op1, idx);
    3085                 :        1803 :       tree rhs2 = handle_operand (cmp_op2, idx);
    3086                 :        1803 :       if (i == 0
    3087                 :         684 :           && !TYPE_UNSIGNED (type)
    3088                 :        2211 :           && TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    3089                 :             :         {
    3090                 :         112 :           tree stype = signed_type_for (TREE_TYPE (rhs1));
    3091                 :         112 :           rhs1 = add_cast (stype, rhs1);
    3092                 :         112 :           rhs2 = add_cast (stype, rhs2);
    3093                 :             :         }
    3094                 :        1803 :       g = gimple_build_cond (GT_EXPR, rhs1, rhs2, NULL_TREE, NULL_TREE);
    3095                 :        1803 :       insert_before (g);
    3096                 :        1803 :       edge e1 = split_block (gsi_bb (m_gsi), g);
    3097                 :        1803 :       e1->flags = EDGE_FALSE_VALUE;
    3098                 :        1803 :       edge e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE);
    3099                 :        1803 :       e1->probability = profile_probability::likely ();
    3100                 :        1803 :       e2->probability = e1->probability.invert ();
    3101                 :        1803 :       if (i == 0)
    3102                 :         684 :         set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    3103                 :        1803 :       m_gsi = gsi_after_labels (e1->dest);
    3104                 :        1803 :       edges[2 * i] = e2;
    3105                 :        1803 :       g = gimple_build_cond (LT_EXPR, rhs1, rhs2, NULL_TREE, NULL_TREE);
    3106                 :        1803 :       insert_before (g);
    3107                 :        1803 :       e1 = split_block (gsi_bb (m_gsi), g);
    3108                 :        1803 :       e1->flags = EDGE_FALSE_VALUE;
    3109                 :        1803 :       e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE);
    3110                 :        1803 :       e1->probability = profile_probability::unlikely ();
    3111                 :        1803 :       e2->probability = e1->probability.invert ();
    3112                 :        1803 :       m_gsi = gsi_after_labels (e1->dest);
    3113                 :        1803 :       edges[2 * i + 1] = e2;
    3114                 :        1803 :       m_first = false;
    3115                 :        1803 :       if (kind == bitint_prec_huge && i == cnt - 1)
    3116                 :             :         {
    3117                 :         308 :           g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_int (-1));
    3118                 :         308 :           insert_before (g);
    3119                 :         308 :           g = gimple_build_cond (NE_EXPR, idx, size_zero_node,
    3120                 :             :                                  NULL_TREE, NULL_TREE);
    3121                 :         308 :           insert_before (g);
    3122                 :         308 :           edge true_edge, false_edge;
    3123                 :         308 :           extract_true_false_edges_from_block (gsi_bb (m_gsi),
    3124                 :             :                                                &true_edge, &false_edge);
    3125                 :         308 :           m_gsi = gsi_after_labels (false_edge->dest);
    3126                 :         308 :           m_bb = NULL;
    3127                 :             :         }
    3128                 :             :     }
    3129                 :             : 
    3130                 :         684 :   tree lhs = make_ssa_name (boolean_type_node);
    3131                 :         684 :   basic_block bb = gimple_bb (stmt);
    3132                 :         684 :   gphi *phi = create_phi_node (lhs, bb);
    3133                 :        4290 :   for (unsigned int i = 0; i < cnt * 2; i++)
    3134                 :             :     {
    3135                 :        7212 :       tree val = ((cmp_code == GT_EXPR || cmp_code == GE_EXPR)
    3136                 :        3606 :                   ^ (i & 1)) ? boolean_true_node : boolean_false_node;
    3137                 :        3606 :       add_phi_arg (phi, val, edges[i], UNKNOWN_LOCATION);
    3138                 :             :     }
    3139                 :         684 :   add_phi_arg (phi, (cmp_code == GE_EXPR || cmp_code == LE_EXPR)
    3140                 :             :                     ? boolean_true_node : boolean_false_node,
    3141                 :             :                find_edge (gsi_bb (m_gsi), bb), UNKNOWN_LOCATION);
    3142                 :         684 :   cmp_code = NE_EXPR;
    3143                 :         684 :   return lhs;
    3144                 :             : }
    3145                 :             : 
    3146                 :             : /* Lower large/huge _BitInt left and right shift except for left
    3147                 :             :    shift by < limb_prec constant.  */
    3148                 :             : 
    3149                 :             : void
    3150                 :         515 : bitint_large_huge::lower_shift_stmt (tree obj, gimple *stmt)
    3151                 :             : {
    3152                 :         515 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    3153                 :         515 :   tree lhs = gimple_assign_lhs (stmt);
    3154                 :         515 :   tree_code rhs_code = gimple_assign_rhs_code (stmt);
    3155                 :         515 :   tree type = TREE_TYPE (rhs1);
    3156                 :         515 :   gimple *final_stmt = gsi_stmt (m_gsi);
    3157                 :         515 :   gcc_assert (TREE_CODE (type) == BITINT_TYPE
    3158                 :             :               && bitint_precision_kind (type) >= bitint_prec_large);
    3159                 :         515 :   int prec = TYPE_PRECISION (type);
    3160                 :         515 :   tree n = gimple_assign_rhs2 (stmt), n1, n2, n3, n4;
    3161                 :         515 :   gimple *g;
    3162                 :         515 :   if (obj == NULL_TREE)
    3163                 :             :     {
    3164                 :         417 :       int part = var_to_partition (m_map, lhs);
    3165                 :         417 :       gcc_assert (m_vars[part] != NULL_TREE);
    3166                 :             :       obj = m_vars[part];
    3167                 :             :     }
    3168                 :             :   /* Preparation code common for both left and right shifts.
    3169                 :             :      unsigned n1 = n % limb_prec;
    3170                 :             :      size_t n2 = n / limb_prec;
    3171                 :             :      size_t n3 = n1 != 0;
    3172                 :             :      unsigned n4 = (limb_prec - n1) % limb_prec;
    3173                 :             :      (for power of 2 limb_prec n4 can be -n1 & (limb_prec)).  */
    3174                 :         515 :   if (TREE_CODE (n) == INTEGER_CST)
    3175                 :             :     {
    3176                 :         207 :       tree lp = build_int_cst (TREE_TYPE (n), limb_prec);
    3177                 :         207 :       n1 = int_const_binop (TRUNC_MOD_EXPR, n, lp);
    3178                 :         207 :       n2 = fold_convert (sizetype, int_const_binop (TRUNC_DIV_EXPR, n, lp));
    3179                 :         207 :       n3 = size_int (!integer_zerop (n1));
    3180                 :         207 :       n4 = int_const_binop (TRUNC_MOD_EXPR,
    3181                 :         207 :                             int_const_binop (MINUS_EXPR, lp, n1), lp);
    3182                 :             :     }
    3183                 :             :   else
    3184                 :             :     {
    3185                 :         308 :       n1 = make_ssa_name (TREE_TYPE (n));
    3186                 :         308 :       n2 = make_ssa_name (sizetype);
    3187                 :         308 :       n3 = make_ssa_name (sizetype);
    3188                 :         308 :       n4 = make_ssa_name (TREE_TYPE (n));
    3189                 :         308 :       if (pow2p_hwi (limb_prec))
    3190                 :             :         {
    3191                 :         308 :           tree lpm1 = build_int_cst (TREE_TYPE (n), limb_prec - 1);
    3192                 :         308 :           g = gimple_build_assign (n1, BIT_AND_EXPR, n, lpm1);
    3193                 :         308 :           insert_before (g);
    3194                 :         908 :           g = gimple_build_assign (useless_type_conversion_p (sizetype,
    3195                 :         308 :                                                               TREE_TYPE (n))
    3196                 :         292 :                                    ? n2 : make_ssa_name (TREE_TYPE (n)),
    3197                 :             :                                    RSHIFT_EXPR, n,
    3198                 :         308 :                                    build_int_cst (TREE_TYPE (n),
    3199                 :         616 :                                                   exact_log2 (limb_prec)));
    3200                 :         308 :           insert_before (g);
    3201                 :         308 :           if (gimple_assign_lhs (g) != n2)
    3202                 :             :             {
    3203                 :         292 :               g = gimple_build_assign (n2, NOP_EXPR, gimple_assign_lhs (g));
    3204                 :         292 :               insert_before (g);
    3205                 :             :             }
    3206                 :         308 :           g = gimple_build_assign (make_ssa_name (TREE_TYPE (n)),
    3207                 :             :                                    NEGATE_EXPR, n1);
    3208                 :         308 :           insert_before (g);
    3209                 :         308 :           g = gimple_build_assign (n4, BIT_AND_EXPR, gimple_assign_lhs (g),
    3210                 :             :                                    lpm1);
    3211                 :         308 :           insert_before (g);
    3212                 :             :         }
    3213                 :             :       else
    3214                 :             :         {
    3215                 :           0 :           tree lp = build_int_cst (TREE_TYPE (n), limb_prec);
    3216                 :           0 :           g = gimple_build_assign (n1, TRUNC_MOD_EXPR, n, lp);
    3217                 :           0 :           insert_before (g);
    3218                 :           0 :           g = gimple_build_assign (useless_type_conversion_p (sizetype,
    3219                 :           0 :                                                               TREE_TYPE (n))
    3220                 :           0 :                                    ? n2 : make_ssa_name (TREE_TYPE (n)),
    3221                 :             :                                    TRUNC_DIV_EXPR, n, lp);
    3222                 :           0 :           insert_before (g);
    3223                 :           0 :           if (gimple_assign_lhs (g) != n2)
    3224                 :             :             {
    3225                 :           0 :               g = gimple_build_assign (n2, NOP_EXPR, gimple_assign_lhs (g));
    3226                 :           0 :               insert_before (g);
    3227                 :             :             }
    3228                 :           0 :           g = gimple_build_assign (make_ssa_name (TREE_TYPE (n)),
    3229                 :             :                                    MINUS_EXPR, lp, n1);
    3230                 :           0 :           insert_before (g);
    3231                 :           0 :           g = gimple_build_assign (n4, TRUNC_MOD_EXPR, gimple_assign_lhs (g),
    3232                 :             :                                    lp);
    3233                 :           0 :           insert_before (g);
    3234                 :             :         }
    3235                 :         308 :       g = gimple_build_assign (make_ssa_name (boolean_type_node), NE_EXPR, n1,
    3236                 :         308 :                                build_zero_cst (TREE_TYPE (n)));
    3237                 :         308 :       insert_before (g);
    3238                 :         308 :       g = gimple_build_assign (n3, NOP_EXPR, gimple_assign_lhs (g));
    3239                 :         308 :       insert_before (g);
    3240                 :             :     }
    3241                 :        1030 :   tree p = build_int_cst (sizetype,
    3242                 :         515 :                           prec / limb_prec - (prec % limb_prec == 0));
    3243                 :         515 :   if (rhs_code == RSHIFT_EXPR)
    3244                 :             :     {
    3245                 :             :       /* Lower
    3246                 :             :            dst = src >> n;
    3247                 :             :          as
    3248                 :             :            unsigned n1 = n % limb_prec;
    3249                 :             :            size_t n2 = n / limb_prec;
    3250                 :             :            size_t n3 = n1 != 0;
    3251                 :             :            unsigned n4 = (limb_prec - n1) % limb_prec;
    3252                 :             :            size_t idx;
    3253                 :             :            size_t p = prec / limb_prec - (prec % limb_prec == 0);
    3254                 :             :            int signed_p = (typeof (src) -1) < 0;
    3255                 :             :            for (idx = n2; idx < ((!signed_p && (prec % limb_prec == 0))
    3256                 :             :                                  ? p : p - n3); ++idx)
    3257                 :             :              dst[idx - n2] = (src[idx] >> n1) | (src[idx + n3] << n4);
    3258                 :             :            limb_type ext;
    3259                 :             :            if (prec % limb_prec == 0)
    3260                 :             :              ext = src[p];
    3261                 :             :            else if (signed_p)
    3262                 :             :              ext = ((signed limb_type) (src[p] << (limb_prec
    3263                 :             :                                                    - (prec % limb_prec))))
    3264                 :             :                    >> (limb_prec - (prec % limb_prec));
    3265                 :             :            else
    3266                 :             :              ext = src[p] & (((limb_type) 1 << (prec % limb_prec)) - 1);
    3267                 :             :            if (!signed_p && (prec % limb_prec == 0))
    3268                 :             :              ;
    3269                 :             :            else if (idx < prec / 64)
    3270                 :             :              {
    3271                 :             :                dst[idx - n2] = (src[idx] >> n1) | (ext << n4);
    3272                 :             :                ++idx;
    3273                 :             :              }
    3274                 :             :            idx -= n2;
    3275                 :             :            if (signed_p)
    3276                 :             :              {
    3277                 :             :                dst[idx] = ((signed limb_type) ext) >> n1;
    3278                 :             :                ext = ((signed limb_type) ext) >> (limb_prec - 1);
    3279                 :             :              }
    3280                 :             :            else
    3281                 :             :              {
    3282                 :             :                dst[idx] = ext >> n1;
    3283                 :             :                ext = 0;
    3284                 :             :              }
    3285                 :             :            for (++idx; idx <= p; ++idx)
    3286                 :             :              dst[idx] = ext;  */
    3287                 :         339 :       tree pmn3;
    3288                 :         339 :       if (TYPE_UNSIGNED (type) && prec % limb_prec == 0)
    3289                 :             :         pmn3 = p;
    3290                 :         254 :       else if (TREE_CODE (n3) == INTEGER_CST)
    3291                 :          90 :         pmn3 = int_const_binop (MINUS_EXPR, p, n3);
    3292                 :             :       else
    3293                 :             :         {
    3294                 :         164 :           pmn3 = make_ssa_name (sizetype);
    3295                 :         164 :           g = gimple_build_assign (pmn3, MINUS_EXPR, p, n3);
    3296                 :         164 :           insert_before (g);
    3297                 :             :         }
    3298                 :         339 :       g = gimple_build_cond (LT_EXPR, n2, pmn3, NULL_TREE, NULL_TREE);
    3299                 :         339 :       edge edge_true, edge_false;
    3300                 :         339 :       if_then (g, profile_probability::likely (), edge_true, edge_false);
    3301                 :         339 :       tree idx_next;
    3302                 :         339 :       tree idx = create_loop (n2, &idx_next);
    3303                 :         339 :       tree idxmn2 = make_ssa_name (sizetype);
    3304                 :         339 :       tree idxpn3 = make_ssa_name (sizetype);
    3305                 :         339 :       g = gimple_build_assign (idxmn2, MINUS_EXPR, idx, n2);
    3306                 :         339 :       insert_before (g);
    3307                 :         339 :       g = gimple_build_assign (idxpn3, PLUS_EXPR, idx, n3);
    3308                 :         339 :       insert_before (g);
    3309                 :         339 :       m_data_cnt = 0;
    3310                 :         339 :       tree t1 = handle_operand (rhs1, idx);
    3311                 :         339 :       m_first = false;
    3312                 :         339 :       g = gimple_build_assign (make_ssa_name (m_limb_type),
    3313                 :             :                                RSHIFT_EXPR, t1, n1);
    3314                 :         339 :       insert_before (g);
    3315                 :         339 :       t1 = gimple_assign_lhs (g);
    3316                 :         339 :       if (!integer_zerop (n3))
    3317                 :             :         {
    3318                 :         257 :           m_data_cnt = 0;
    3319                 :         257 :           tree t2 = handle_operand (rhs1, idxpn3);
    3320                 :         257 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3321                 :             :                                    LSHIFT_EXPR, t2, n4);
    3322                 :         257 :           insert_before (g);
    3323                 :         257 :           t2 = gimple_assign_lhs (g);
    3324                 :         257 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3325                 :             :                                    BIT_IOR_EXPR, t1, t2);
    3326                 :         257 :           insert_before (g);
    3327                 :         257 :           t1 = gimple_assign_lhs (g);
    3328                 :             :         }
    3329                 :         339 :       tree l = limb_access (TREE_TYPE (lhs), obj, idxmn2, true);
    3330                 :         339 :       g = gimple_build_assign (l, t1);
    3331                 :         339 :       insert_before (g);
    3332                 :         339 :       g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_one_node);
    3333                 :         339 :       insert_before (g);
    3334                 :         339 :       g = gimple_build_cond (LT_EXPR, idx_next, pmn3, NULL_TREE, NULL_TREE);
    3335                 :         339 :       insert_before (g);
    3336                 :         339 :       idx = make_ssa_name (sizetype);
    3337                 :         339 :       m_gsi = gsi_for_stmt (final_stmt);
    3338                 :         339 :       gphi *phi = create_phi_node (idx, gsi_bb (m_gsi));
    3339                 :         339 :       edge_false = find_edge (edge_false->src, gsi_bb (m_gsi));
    3340                 :         339 :       edge_true = EDGE_PRED (gsi_bb (m_gsi),
    3341                 :             :                              EDGE_PRED (gsi_bb (m_gsi), 0) == edge_false);
    3342                 :         339 :       add_phi_arg (phi, n2, edge_false, UNKNOWN_LOCATION);
    3343                 :         339 :       add_phi_arg (phi, idx_next, edge_true, UNKNOWN_LOCATION);
    3344                 :         339 :       m_data_cnt = 0;
    3345                 :         339 :       tree ms = handle_operand (rhs1, p);
    3346                 :         339 :       tree ext = ms;
    3347                 :         339 :       if (!types_compatible_p (TREE_TYPE (ms), m_limb_type))
    3348                 :         197 :         ext = add_cast (m_limb_type, ms);
    3349                 :         499 :       if (!(TYPE_UNSIGNED (type) && prec % limb_prec == 0)
    3350                 :         414 :           && !integer_zerop (n3))
    3351                 :             :         {
    3352                 :         216 :           g = gimple_build_cond (LT_EXPR, idx, p, NULL_TREE, NULL_TREE);
    3353                 :         216 :           if_then (g, profile_probability::likely (), edge_true, edge_false);
    3354                 :         216 :           m_data_cnt = 0;
    3355                 :         216 :           t1 = handle_operand (rhs1, idx);
    3356                 :         216 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3357                 :             :                                    RSHIFT_EXPR, t1, n1);
    3358                 :         216 :           insert_before (g);
    3359                 :         216 :           t1 = gimple_assign_lhs (g);
    3360                 :         216 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3361                 :             :                                    LSHIFT_EXPR, ext, n4);
    3362                 :         216 :           insert_before (g);
    3363                 :         216 :           tree t2 = gimple_assign_lhs (g);
    3364                 :         216 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3365                 :             :                                    BIT_IOR_EXPR, t1, t2);
    3366                 :         216 :           insert_before (g);
    3367                 :         216 :           t1 = gimple_assign_lhs (g);
    3368                 :         216 :           idxmn2 = make_ssa_name (sizetype);
    3369                 :         216 :           g = gimple_build_assign (idxmn2, MINUS_EXPR, idx, n2);
    3370                 :         216 :           insert_before (g);
    3371                 :         216 :           l = limb_access (TREE_TYPE (lhs), obj, idxmn2, true);
    3372                 :         216 :           g = gimple_build_assign (l, t1);
    3373                 :         216 :           insert_before (g);
    3374                 :         216 :           idx_next = make_ssa_name (sizetype);
    3375                 :         216 :           g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_one_node);
    3376                 :         216 :           insert_before (g);
    3377                 :         216 :           m_gsi = gsi_for_stmt (final_stmt);
    3378                 :         216 :           tree nidx = make_ssa_name (sizetype);
    3379                 :         216 :           phi = create_phi_node (nidx, gsi_bb (m_gsi));
    3380                 :         216 :           edge_false = find_edge (edge_false->src, gsi_bb (m_gsi));
    3381                 :         216 :           edge_true = EDGE_PRED (gsi_bb (m_gsi),
    3382                 :             :                                  EDGE_PRED (gsi_bb (m_gsi), 0) == edge_false);
    3383                 :         216 :           add_phi_arg (phi, idx, edge_false, UNKNOWN_LOCATION);
    3384                 :         216 :           add_phi_arg (phi, idx_next, edge_true, UNKNOWN_LOCATION);
    3385                 :         216 :           idx = nidx;
    3386                 :             :         }
    3387                 :         339 :       g = gimple_build_assign (make_ssa_name (sizetype), MINUS_EXPR, idx, n2);
    3388                 :         339 :       insert_before (g);
    3389                 :         339 :       idx = gimple_assign_lhs (g);
    3390                 :         339 :       tree sext = ext;
    3391                 :         339 :       if (!TYPE_UNSIGNED (type))
    3392                 :         179 :         sext = add_cast (signed_type_for (m_limb_type), ext);
    3393                 :         339 :       g = gimple_build_assign (make_ssa_name (TREE_TYPE (sext)),
    3394                 :             :                                RSHIFT_EXPR, sext, n1);
    3395                 :         339 :       insert_before (g);
    3396                 :         339 :       t1 = gimple_assign_lhs (g);
    3397                 :         339 :       if (!TYPE_UNSIGNED (type))
    3398                 :             :         {
    3399                 :         179 :           t1 = add_cast (m_limb_type, t1);
    3400                 :         179 :           g = gimple_build_assign (make_ssa_name (TREE_TYPE (sext)),
    3401                 :             :                                    RSHIFT_EXPR, sext,
    3402                 :         179 :                                    build_int_cst (TREE_TYPE (n),
    3403                 :         179 :                                                   limb_prec - 1));
    3404                 :         179 :           insert_before (g);
    3405                 :         179 :           ext = add_cast (m_limb_type, gimple_assign_lhs (g));
    3406                 :             :         }
    3407                 :             :       else
    3408                 :         160 :         ext = build_zero_cst (m_limb_type);
    3409                 :         339 :       l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    3410                 :         339 :       g = gimple_build_assign (l, t1);
    3411                 :         339 :       insert_before (g);
    3412                 :         339 :       g = gimple_build_assign (make_ssa_name (sizetype), PLUS_EXPR, idx,
    3413                 :             :                                size_one_node);
    3414                 :         339 :       insert_before (g);
    3415                 :         339 :       idx = gimple_assign_lhs (g);
    3416                 :         339 :       g = gimple_build_cond (LE_EXPR, idx, p, NULL_TREE, NULL_TREE);
    3417                 :         339 :       if_then (g, profile_probability::likely (), edge_true, edge_false);
    3418                 :         339 :       idx = create_loop (idx, &idx_next);
    3419                 :         339 :       l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    3420                 :         339 :       g = gimple_build_assign (l, ext);
    3421                 :         339 :       insert_before (g);
    3422                 :         339 :       g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_one_node);
    3423                 :         339 :       insert_before (g);
    3424                 :         339 :       g = gimple_build_cond (LE_EXPR, idx_next, p, NULL_TREE, NULL_TREE);
    3425                 :         339 :       insert_before (g);
    3426                 :             :     }
    3427                 :             :   else
    3428                 :             :     {
    3429                 :             :       /* Lower
    3430                 :             :            dst = src << n;
    3431                 :             :          as
    3432                 :             :            unsigned n1 = n % limb_prec;
    3433                 :             :            size_t n2 = n / limb_prec;
    3434                 :             :            size_t n3 = n1 != 0;
    3435                 :             :            unsigned n4 = (limb_prec - n1) % limb_prec;
    3436                 :             :            size_t idx;
    3437                 :             :            size_t p = prec / limb_prec - (prec % limb_prec == 0);
    3438                 :             :            for (idx = p; (ssize_t) idx >= (ssize_t) (n2 + n3); --idx)
    3439                 :             :              dst[idx] = (src[idx - n2] << n1) | (src[idx - n2 - n3] >> n4);
    3440                 :             :            if (n1)
    3441                 :             :              {
    3442                 :             :                dst[idx] = src[idx - n2] << n1;
    3443                 :             :                --idx;
    3444                 :             :              }
    3445                 :             :            for (; (ssize_t) idx >= 0; --idx)
    3446                 :             :              dst[idx] = 0;  */
    3447                 :         176 :       tree n2pn3;
    3448                 :         176 :       if (TREE_CODE (n2) == INTEGER_CST && TREE_CODE (n3) == INTEGER_CST)
    3449                 :          65 :         n2pn3 = int_const_binop (PLUS_EXPR, n2, n3);
    3450                 :             :       else
    3451                 :             :         {
    3452                 :         111 :           n2pn3 = make_ssa_name (sizetype);
    3453                 :         111 :           g = gimple_build_assign (n2pn3, PLUS_EXPR, n2, n3);
    3454                 :         111 :           insert_before (g);
    3455                 :             :         }
    3456                 :             :       /* For LSHIFT_EXPR, we can use handle_operand with non-INTEGER_CST
    3457                 :             :          idx even to access the most significant partial limb.  */
    3458                 :         176 :       m_var_msb = true;
    3459                 :         176 :       if (integer_zerop (n3))
    3460                 :             :         /* For n3 == 0 p >= n2 + n3 is always true for all valid shift
    3461                 :             :            counts.  Emit if (true) condition that can be optimized later.  */
    3462                 :          44 :         g = gimple_build_cond (NE_EXPR, boolean_true_node, boolean_false_node,
    3463                 :             :                                NULL_TREE, NULL_TREE);
    3464                 :             :       else
    3465                 :         132 :         g = gimple_build_cond (LE_EXPR, n2pn3, p, NULL_TREE, NULL_TREE);
    3466                 :         176 :       edge edge_true, edge_false;
    3467                 :         176 :       if_then (g, profile_probability::likely (), edge_true, edge_false);
    3468                 :         176 :       tree idx_next;
    3469                 :         176 :       tree idx = create_loop (p, &idx_next);
    3470                 :         176 :       tree idxmn2 = make_ssa_name (sizetype);
    3471                 :         176 :       tree idxmn2mn3 = make_ssa_name (sizetype);
    3472                 :         176 :       g = gimple_build_assign (idxmn2, MINUS_EXPR, idx, n2);
    3473                 :         176 :       insert_before (g);
    3474                 :         176 :       g = gimple_build_assign (idxmn2mn3, MINUS_EXPR, idxmn2, n3);
    3475                 :         176 :       insert_before (g);
    3476                 :         176 :       m_data_cnt = 0;
    3477                 :         176 :       tree t1 = handle_operand (rhs1, idxmn2);
    3478                 :         176 :       m_first = false;
    3479                 :         176 :       g = gimple_build_assign (make_ssa_name (m_limb_type),
    3480                 :             :                                LSHIFT_EXPR, t1, n1);
    3481                 :         176 :       insert_before (g);
    3482                 :         176 :       t1 = gimple_assign_lhs (g);
    3483                 :         176 :       if (!integer_zerop (n3))
    3484                 :             :         {
    3485                 :         132 :           m_data_cnt = 0;
    3486                 :         132 :           tree t2 = handle_operand (rhs1, idxmn2mn3);
    3487                 :         132 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3488                 :             :                                    RSHIFT_EXPR, t2, n4);
    3489                 :         132 :           insert_before (g);
    3490                 :         132 :           t2 = gimple_assign_lhs (g);
    3491                 :         132 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3492                 :             :                                    BIT_IOR_EXPR, t1, t2);
    3493                 :         132 :           insert_before (g);
    3494                 :         132 :           t1 = gimple_assign_lhs (g);
    3495                 :             :         }
    3496                 :         176 :       tree l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    3497                 :         176 :       g = gimple_build_assign (l, t1);
    3498                 :         176 :       insert_before (g);
    3499                 :         176 :       g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_int (-1));
    3500                 :         176 :       insert_before (g);
    3501                 :         176 :       tree sn2pn3 = add_cast (ssizetype, n2pn3);
    3502                 :         176 :       g = gimple_build_cond (GE_EXPR, add_cast (ssizetype, idx_next), sn2pn3,
    3503                 :             :                              NULL_TREE, NULL_TREE);
    3504                 :         176 :       insert_before (g);
    3505                 :         176 :       idx = make_ssa_name (sizetype);
    3506                 :         176 :       m_gsi = gsi_for_stmt (final_stmt);
    3507                 :         176 :       gphi *phi = create_phi_node (idx, gsi_bb (m_gsi));
    3508                 :         176 :       edge_false = find_edge (edge_false->src, gsi_bb (m_gsi));
    3509                 :         176 :       edge_true = EDGE_PRED (gsi_bb (m_gsi),
    3510                 :             :                              EDGE_PRED (gsi_bb (m_gsi), 0) == edge_false);
    3511                 :         176 :       add_phi_arg (phi, p, edge_false, UNKNOWN_LOCATION);
    3512                 :         176 :       add_phi_arg (phi, idx_next, edge_true, UNKNOWN_LOCATION);
    3513                 :         176 :       m_data_cnt = 0;
    3514                 :         176 :       if (!integer_zerop (n3))
    3515                 :             :         {
    3516                 :         132 :           g = gimple_build_cond (NE_EXPR, n3, size_zero_node,
    3517                 :             :                                  NULL_TREE, NULL_TREE);
    3518                 :         132 :           if_then (g, profile_probability::likely (), edge_true, edge_false);
    3519                 :         132 :           idxmn2 = make_ssa_name (sizetype);
    3520                 :         132 :           g = gimple_build_assign (idxmn2, MINUS_EXPR, idx, n2);
    3521                 :         132 :           insert_before (g);
    3522                 :         132 :           m_data_cnt = 0;
    3523                 :         132 :           t1 = handle_operand (rhs1, idxmn2);
    3524                 :         132 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3525                 :             :                                    LSHIFT_EXPR, t1, n1);
    3526                 :         132 :           insert_before (g);
    3527                 :         132 :           t1 = gimple_assign_lhs (g);
    3528                 :         132 :           l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    3529                 :         132 :           g = gimple_build_assign (l, t1);
    3530                 :         132 :           insert_before (g);
    3531                 :         132 :           idx_next = make_ssa_name (sizetype);
    3532                 :         132 :           g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_int (-1));
    3533                 :         132 :           insert_before (g);
    3534                 :         132 :           m_gsi = gsi_for_stmt (final_stmt);
    3535                 :         132 :           tree nidx = make_ssa_name (sizetype);
    3536                 :         132 :           phi = create_phi_node (nidx, gsi_bb (m_gsi));
    3537                 :         132 :           edge_false = find_edge (edge_false->src, gsi_bb (m_gsi));
    3538                 :         132 :           edge_true = EDGE_PRED (gsi_bb (m_gsi),
    3539                 :             :                                  EDGE_PRED (gsi_bb (m_gsi), 0) == edge_false);
    3540                 :         132 :           add_phi_arg (phi, idx, edge_false, UNKNOWN_LOCATION);
    3541                 :         132 :           add_phi_arg (phi, idx_next, edge_true, UNKNOWN_LOCATION);
    3542                 :         132 :           idx = nidx;
    3543                 :             :         }
    3544                 :         176 :       g = gimple_build_cond (GE_EXPR, add_cast (ssizetype, idx),
    3545                 :         176 :                              ssize_int (0), NULL_TREE, NULL_TREE);
    3546                 :         176 :       if_then (g, profile_probability::likely (), edge_true, edge_false);
    3547                 :         176 :       idx = create_loop (idx, &idx_next);
    3548                 :         176 :       l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    3549                 :         176 :       g = gimple_build_assign (l, build_zero_cst (m_limb_type));
    3550                 :         176 :       insert_before (g);
    3551                 :         176 :       g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_int (-1));
    3552                 :         176 :       insert_before (g);
    3553                 :         176 :       g = gimple_build_cond (GE_EXPR, add_cast (ssizetype, idx_next),
    3554                 :         176 :                              ssize_int (0), NULL_TREE, NULL_TREE);
    3555                 :         176 :       insert_before (g);
    3556                 :             :     }
    3557                 :         515 : }
    3558                 :             : 
    3559                 :             : /* Lower large/huge _BitInt multiplication or division.  */
    3560                 :             : 
    3561                 :             : void
    3562                 :         296 : bitint_large_huge::lower_muldiv_stmt (tree obj, gimple *stmt)
    3563                 :             : {
    3564                 :         296 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    3565                 :         296 :   tree rhs2 = gimple_assign_rhs2 (stmt);
    3566                 :         296 :   tree lhs = gimple_assign_lhs (stmt);
    3567                 :         296 :   tree_code rhs_code = gimple_assign_rhs_code (stmt);
    3568                 :         296 :   tree type = TREE_TYPE (rhs1);
    3569                 :         296 :   gcc_assert (TREE_CODE (type) == BITINT_TYPE
    3570                 :             :               && bitint_precision_kind (type) >= bitint_prec_large);
    3571                 :         296 :   int prec = TYPE_PRECISION (type), prec1, prec2;
    3572                 :         296 :   rhs1 = handle_operand_addr (rhs1, stmt, NULL, &prec1);
    3573                 :         296 :   rhs2 = handle_operand_addr (rhs2, stmt, NULL, &prec2);
    3574                 :         296 :   if (obj == NULL_TREE)
    3575                 :             :     {
    3576                 :         123 :       int part = var_to_partition (m_map, lhs);
    3577                 :         123 :       gcc_assert (m_vars[part] != NULL_TREE);
    3578                 :         123 :       obj = m_vars[part];
    3579                 :         123 :       lhs = build_fold_addr_expr (obj);
    3580                 :             :     }
    3581                 :             :   else
    3582                 :             :     {
    3583                 :         173 :       lhs = build_fold_addr_expr (obj);
    3584                 :         173 :       lhs = force_gimple_operand_gsi (&m_gsi, lhs, true,
    3585                 :             :                                       NULL_TREE, true, GSI_SAME_STMT);
    3586                 :             :     }
    3587                 :         296 :   tree sitype = lang_hooks.types.type_for_mode (SImode, 0);
    3588                 :         296 :   gimple *g;
    3589                 :         296 :   switch (rhs_code)
    3590                 :             :     {
    3591                 :         173 :     case MULT_EXPR:
    3592                 :         173 :       g = gimple_build_call_internal (IFN_MULBITINT, 6,
    3593                 :             :                                       lhs, build_int_cst (sitype, prec),
    3594                 :             :                                       rhs1, build_int_cst (sitype, prec1),
    3595                 :             :                                       rhs2, build_int_cst (sitype, prec2));
    3596                 :         173 :       insert_before (g);
    3597                 :         173 :       break;
    3598                 :          80 :     case TRUNC_DIV_EXPR:
    3599                 :          80 :       g = gimple_build_call_internal (IFN_DIVMODBITINT, 8,
    3600                 :             :                                       lhs, build_int_cst (sitype, prec),
    3601                 :             :                                       null_pointer_node,
    3602                 :          80 :                                       build_int_cst (sitype, 0),
    3603                 :             :                                       rhs1, build_int_cst (sitype, prec1),
    3604                 :             :                                       rhs2, build_int_cst (sitype, prec2));
    3605                 :          80 :       if (!stmt_ends_bb_p (stmt))
    3606                 :          79 :         gimple_call_set_nothrow (as_a <gcall *> (g), true);
    3607                 :          80 :       insert_before (g);
    3608                 :          80 :       break;
    3609                 :          43 :     case TRUNC_MOD_EXPR:
    3610                 :          43 :       g = gimple_build_call_internal (IFN_DIVMODBITINT, 8, null_pointer_node,
    3611                 :          43 :                                       build_int_cst (sitype, 0),
    3612                 :             :                                       lhs, build_int_cst (sitype, prec),
    3613                 :             :                                       rhs1, build_int_cst (sitype, prec1),
    3614                 :             :                                       rhs2, build_int_cst (sitype, prec2));
    3615                 :          43 :       if (!stmt_ends_bb_p (stmt))
    3616                 :          42 :         gimple_call_set_nothrow (as_a <gcall *> (g), true);
    3617                 :          43 :       insert_before (g);
    3618                 :          43 :       break;
    3619                 :           0 :     default:
    3620                 :           0 :       gcc_unreachable ();
    3621                 :             :     }
    3622                 :         296 :   if (stmt_ends_bb_p (stmt))
    3623                 :             :     {
    3624                 :           2 :       maybe_duplicate_eh_stmt (g, stmt);
    3625                 :           2 :       edge e1;
    3626                 :           2 :       edge_iterator ei;
    3627                 :           2 :       basic_block bb = gimple_bb (stmt);
    3628                 :             : 
    3629                 :           2 :       FOR_EACH_EDGE (e1, ei, bb->succs)
    3630                 :           2 :         if (e1->flags & EDGE_EH)
    3631                 :             :           break;
    3632                 :           2 :       if (e1)
    3633                 :             :         {
    3634                 :           2 :           edge e2 = split_block (gsi_bb (m_gsi), g);
    3635                 :           2 :           m_gsi = gsi_after_labels (e2->dest);
    3636                 :           2 :           add_eh_edge (e2->src, e1);
    3637                 :             :         }
    3638                 :             :     }
    3639                 :         296 : }
    3640                 :             : 
    3641                 :             : /* Lower large/huge _BitInt conversion to/from floating point.  */
    3642                 :             : 
    3643                 :             : void
    3644                 :         289 : bitint_large_huge::lower_float_conv_stmt (tree obj, gimple *stmt)
    3645                 :             : {
    3646                 :         289 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    3647                 :         289 :   tree lhs = gimple_assign_lhs (stmt);
    3648                 :         289 :   tree_code rhs_code = gimple_assign_rhs_code (stmt);
    3649                 :         289 :   tree sitype = lang_hooks.types.type_for_mode (SImode, 0);
    3650                 :         289 :   gimple *g;
    3651                 :         289 :   if (rhs_code == FIX_TRUNC_EXPR)
    3652                 :             :     {
    3653                 :         163 :       int prec = TYPE_PRECISION (TREE_TYPE (lhs));
    3654                 :         163 :       if (!TYPE_UNSIGNED (TREE_TYPE (lhs)))
    3655                 :          83 :         prec = -prec;
    3656                 :         163 :       if (obj == NULL_TREE)
    3657                 :             :         {
    3658                 :         124 :           int part = var_to_partition (m_map, lhs);
    3659                 :         124 :           gcc_assert (m_vars[part] != NULL_TREE);
    3660                 :         124 :           obj = m_vars[part];
    3661                 :         124 :           lhs = build_fold_addr_expr (obj);
    3662                 :             :         }
    3663                 :             :       else
    3664                 :             :         {
    3665                 :          39 :           lhs = build_fold_addr_expr (obj);
    3666                 :          39 :           lhs = force_gimple_operand_gsi (&m_gsi, lhs, true,
    3667                 :             :                                           NULL_TREE, true, GSI_SAME_STMT);
    3668                 :             :         }
    3669                 :         163 :       scalar_mode from_mode
    3670                 :         163 :         = as_a <scalar_mode> (TYPE_MODE (TREE_TYPE (rhs1)));
    3671                 :             : #ifdef HAVE_SFmode
    3672                 :             :       /* IEEE single is a full superset of both IEEE half and
    3673                 :             :          bfloat formats, convert to float first and then to _BitInt
    3674                 :             :          to avoid the need of another 2 library routines.  */
    3675                 :         163 :       if ((REAL_MODE_FORMAT (from_mode) == &arm_bfloat_half_format
    3676                 :         163 :            || REAL_MODE_FORMAT (from_mode) == &ieee_half_format)
    3677                 :         175 :           && REAL_MODE_FORMAT (SFmode) == &ieee_single_format)
    3678                 :             :         {
    3679                 :          12 :           tree type = lang_hooks.types.type_for_mode (SFmode, 0);
    3680                 :          12 :           if (type)
    3681                 :          12 :             rhs1 = add_cast (type, rhs1);
    3682                 :             :         }
    3683                 :             : #endif
    3684                 :         163 :       g = gimple_build_call_internal (IFN_FLOATTOBITINT, 3,
    3685                 :             :                                       lhs, build_int_cst (sitype, prec),
    3686                 :             :                                       rhs1);
    3687                 :         163 :       insert_before (g);
    3688                 :             :     }
    3689                 :             :   else
    3690                 :             :     {
    3691                 :         126 :       int prec;
    3692                 :         126 :       rhs1 = handle_operand_addr (rhs1, stmt, NULL, &prec);
    3693                 :         126 :       g = gimple_build_call_internal (IFN_BITINTTOFLOAT, 2,
    3694                 :             :                                       rhs1, build_int_cst (sitype, prec));
    3695                 :         126 :       gimple_call_set_lhs (g, lhs);
    3696                 :         126 :       if (!stmt_ends_bb_p (stmt))
    3697                 :         125 :         gimple_call_set_nothrow (as_a <gcall *> (g), true);
    3698                 :         126 :       gsi_replace (&m_gsi, g, true);
    3699                 :             :     }
    3700                 :         289 : }
    3701                 :             : 
    3702                 :             : /* Helper method for lower_addsub_overflow and lower_mul_overflow.
    3703                 :             :    If check_zero is true, caller wants to check if all bits in [start, end)
    3704                 :             :    are zero, otherwise if bits in [start, end) are either all zero or
    3705                 :             :    all ones.  L is the limb with index LIMB, START and END are measured
    3706                 :             :    in bits.  */
    3707                 :             : 
    3708                 :             : tree
    3709                 :        6108 : bitint_large_huge::arith_overflow_extract_bits (unsigned int start,
    3710                 :             :                                                 unsigned int end, tree l,
    3711                 :             :                                                 unsigned int limb,
    3712                 :             :                                                 bool check_zero)
    3713                 :             : {
    3714                 :        6108 :   unsigned startlimb = start / limb_prec;
    3715                 :        6108 :   unsigned endlimb = (end - 1) / limb_prec;
    3716                 :        6108 :   gimple *g;
    3717                 :             : 
    3718                 :        6108 :   if ((start % limb_prec) == 0 && (end % limb_prec) == 0)
    3719                 :             :     return l;
    3720                 :        5842 :   if (startlimb == endlimb && limb == startlimb)
    3721                 :             :     {
    3722                 :        1975 :       if (check_zero)
    3723                 :             :         {
    3724                 :        1450 :           wide_int w = wi::shifted_mask (start % limb_prec,
    3725                 :        1450 :                                          end - start, false, limb_prec);
    3726                 :        1450 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3727                 :             :                                    BIT_AND_EXPR, l,
    3728                 :             :                                    wide_int_to_tree (m_limb_type, w));
    3729                 :        1450 :           insert_before (g);
    3730                 :        1450 :           return gimple_assign_lhs (g);
    3731                 :        1450 :         }
    3732                 :         525 :       unsigned int shift = start % limb_prec;
    3733                 :         525 :       if ((end % limb_prec) != 0)
    3734                 :             :         {
    3735                 :         328 :           unsigned int lshift = (-end) % limb_prec;
    3736                 :         328 :           shift += lshift;
    3737                 :         328 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3738                 :             :                                    LSHIFT_EXPR, l,
    3739                 :             :                                    build_int_cst (unsigned_type_node,
    3740                 :             :                                                   lshift));
    3741                 :         328 :           insert_before (g);
    3742                 :         328 :           l = gimple_assign_lhs (g);
    3743                 :             :         }
    3744                 :         525 :       l = add_cast (signed_type_for (m_limb_type), l);
    3745                 :         525 :       g = gimple_build_assign (make_ssa_name (TREE_TYPE (l)),
    3746                 :             :                                RSHIFT_EXPR, l,
    3747                 :             :                                build_int_cst (unsigned_type_node, shift));
    3748                 :         525 :       insert_before (g);
    3749                 :         525 :       return add_cast (m_limb_type, gimple_assign_lhs (g));
    3750                 :             :     }
    3751                 :        3867 :   else if (limb == startlimb)
    3752                 :             :     {
    3753                 :        1875 :       if ((start % limb_prec) == 0)
    3754                 :             :         return l;
    3755                 :        1791 :       if (!check_zero)
    3756                 :         913 :         l = add_cast (signed_type_for (m_limb_type), l);
    3757                 :        1791 :       g = gimple_build_assign (make_ssa_name (TREE_TYPE (l)),
    3758                 :             :                                RSHIFT_EXPR, l,
    3759                 :             :                                build_int_cst (unsigned_type_node,
    3760                 :        1791 :                                               start % limb_prec));
    3761                 :        1791 :       insert_before (g);
    3762                 :        1791 :       l = gimple_assign_lhs (g);
    3763                 :        1791 :       if (!check_zero)
    3764                 :         913 :         l = add_cast (m_limb_type, l);
    3765                 :        1791 :       return l;
    3766                 :             :     }
    3767                 :        1992 :   else if (limb == endlimb)
    3768                 :             :     {
    3769                 :        1597 :       if ((end % limb_prec) == 0)
    3770                 :             :         return l;
    3771                 :        1596 :       if (check_zero)
    3772                 :             :         {
    3773                 :         840 :           wide_int w = wi::mask (end % limb_prec, false, limb_prec);
    3774                 :         840 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3775                 :             :                                    BIT_AND_EXPR, l,
    3776                 :             :                                    wide_int_to_tree (m_limb_type, w));
    3777                 :         840 :           insert_before (g);
    3778                 :         840 :           return gimple_assign_lhs (g);
    3779                 :         840 :         }
    3780                 :         756 :       unsigned int shift = (-end) % limb_prec;
    3781                 :         756 :       g = gimple_build_assign (make_ssa_name (m_limb_type),
    3782                 :             :                                LSHIFT_EXPR, l,
    3783                 :             :                                build_int_cst (unsigned_type_node, shift));
    3784                 :         756 :       insert_before (g);
    3785                 :         756 :       l = add_cast (signed_type_for (m_limb_type), gimple_assign_lhs (g));
    3786                 :         756 :       g = gimple_build_assign (make_ssa_name (TREE_TYPE (l)),
    3787                 :             :                                RSHIFT_EXPR, l,
    3788                 :             :                                build_int_cst (unsigned_type_node, shift));
    3789                 :         756 :       insert_before (g);
    3790                 :         756 :       return add_cast (m_limb_type, gimple_assign_lhs (g));
    3791                 :             :     }
    3792                 :             :   return l;
    3793                 :             : }
    3794                 :             : 
    3795                 :             : /* Helper method for lower_addsub_overflow and lower_mul_overflow.  Store
    3796                 :             :    result including overflow flag into the right locations.  */
    3797                 :             : 
    3798                 :             : void
    3799                 :        4028 : bitint_large_huge::finish_arith_overflow (tree var, tree obj, tree type,
    3800                 :             :                                           tree ovf, tree lhs, tree orig_obj,
    3801                 :             :                                           gimple *stmt, tree_code code)
    3802                 :             : {
    3803                 :        4028 :   gimple *g;
    3804                 :             : 
    3805                 :        4028 :   if (obj == NULL_TREE
    3806                 :        4028 :       && (TREE_CODE (type) != BITINT_TYPE
    3807                 :         218 :           || bitint_precision_kind (type) < bitint_prec_large))
    3808                 :             :     {
    3809                 :             :       /* Add support for 3 or more limbs filled in from normal integral
    3810                 :             :          type if this assert fails.  If no target chooses limb mode smaller
    3811                 :             :          than half of largest supported normal integral type, this will not
    3812                 :             :          be needed.  */
    3813                 :         237 :       gcc_assert (TYPE_PRECISION (type) <= 2 * limb_prec);
    3814                 :         237 :       tree lhs_type = type;
    3815                 :         237 :       if (TREE_CODE (type) == BITINT_TYPE
    3816                 :         237 :           && bitint_precision_kind (type) == bitint_prec_middle)
    3817                 :          44 :         lhs_type = build_nonstandard_integer_type (TYPE_PRECISION (type),
    3818                 :          44 :                                                    TYPE_UNSIGNED (type));
    3819                 :         237 :       tree r1 = limb_access (NULL_TREE, var, size_int (0), true);
    3820                 :         237 :       g = gimple_build_assign (make_ssa_name (m_limb_type), r1);
    3821                 :         237 :       insert_before (g);
    3822                 :         237 :       r1 = gimple_assign_lhs (g);
    3823                 :         237 :       if (!useless_type_conversion_p (lhs_type, TREE_TYPE (r1)))
    3824                 :         237 :         r1 = add_cast (lhs_type, r1);
    3825                 :         237 :       if (TYPE_PRECISION (lhs_type) > limb_prec)
    3826                 :             :         {
    3827                 :          88 :           tree r2 = limb_access (NULL_TREE, var, size_int (1), true);
    3828                 :          88 :           g = gimple_build_assign (make_ssa_name (m_limb_type), r2);
    3829                 :          88 :           insert_before (g);
    3830                 :          88 :           r2 = gimple_assign_lhs (g);
    3831                 :          88 :           r2 = add_cast (lhs_type, r2);
    3832                 :          88 :           g = gimple_build_assign (make_ssa_name (lhs_type), LSHIFT_EXPR, r2,
    3833                 :             :                                    build_int_cst (unsigned_type_node,
    3834                 :             :                                                   limb_prec));
    3835                 :          88 :           insert_before (g);
    3836                 :          88 :           g = gimple_build_assign (make_ssa_name (lhs_type), BIT_IOR_EXPR, r1,
    3837                 :             :                                    gimple_assign_lhs (g));
    3838                 :          88 :           insert_before (g);
    3839                 :          88 :           r1 = gimple_assign_lhs (g);
    3840                 :             :         }
    3841                 :         237 :       if (lhs_type != type)
    3842                 :          44 :         r1 = add_cast (type, r1);
    3843                 :         237 :       ovf = add_cast (lhs_type, ovf);
    3844                 :         237 :       if (lhs_type != type)
    3845                 :          44 :         ovf = add_cast (type, ovf);
    3846                 :         237 :       g = gimple_build_assign (lhs, COMPLEX_EXPR, r1, ovf);
    3847                 :         237 :       m_gsi = gsi_for_stmt (stmt);
    3848                 :         237 :       gsi_replace (&m_gsi, g, true);
    3849                 :             :     }
    3850                 :             :   else
    3851                 :             :     {
    3852                 :        3791 :       unsigned HOST_WIDE_INT nelts = 0;
    3853                 :        3791 :       tree atype = NULL_TREE;
    3854                 :        3791 :       if (obj)
    3855                 :             :         {
    3856                 :        3705 :           nelts = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (obj))) / limb_prec;
    3857                 :        3705 :           if (orig_obj == NULL_TREE)
    3858                 :        2139 :             nelts >>= 1;
    3859                 :        3705 :           atype = build_array_type_nelts (m_limb_type, nelts);
    3860                 :             :         }
    3861                 :        3791 :       if (var && obj)
    3862                 :             :         {
    3863                 :         480 :           tree v1, v2;
    3864                 :         480 :           tree zero;
    3865                 :         480 :           if (orig_obj == NULL_TREE)
    3866                 :             :             {
    3867                 :           0 :               zero = build_zero_cst (build_pointer_type (TREE_TYPE (obj)));
    3868                 :           0 :               v1 = build2 (MEM_REF, atype,
    3869                 :             :                            build_fold_addr_expr (unshare_expr (obj)), zero);
    3870                 :             :             }
    3871                 :         480 :           else if (!useless_type_conversion_p (atype, TREE_TYPE (obj)))
    3872                 :           8 :             v1 = build1 (VIEW_CONVERT_EXPR, atype, unshare_expr (obj));
    3873                 :             :           else
    3874                 :         472 :             v1 = unshare_expr (obj);
    3875                 :         480 :           zero = build_zero_cst (build_pointer_type (TREE_TYPE (var)));
    3876                 :         480 :           v2 = build2 (MEM_REF, atype, build_fold_addr_expr (var), zero);
    3877                 :         480 :           g = gimple_build_assign (v1, v2);
    3878                 :         480 :           insert_before (g);
    3879                 :             :         }
    3880                 :        3791 :       if (orig_obj == NULL_TREE && obj)
    3881                 :             :         {
    3882                 :        2139 :           ovf = add_cast (m_limb_type, ovf);
    3883                 :        2139 :           tree l = limb_access (NULL_TREE, obj, size_int (nelts), true);
    3884                 :        2139 :           g = gimple_build_assign (l, ovf);
    3885                 :        2139 :           insert_before (g);
    3886                 :        2139 :           if (nelts > 1)
    3887                 :             :             {
    3888                 :        2139 :               atype = build_array_type_nelts (m_limb_type, nelts - 1);
    3889                 :        2139 :               tree off = build_int_cst (build_pointer_type (TREE_TYPE (obj)),
    3890                 :        2139 :                                         (nelts + 1) * m_limb_size);
    3891                 :        2139 :               tree v1 = build2 (MEM_REF, atype,
    3892                 :             :                                 build_fold_addr_expr (unshare_expr (obj)),
    3893                 :             :                                 off);
    3894                 :        2139 :               g = gimple_build_assign (v1, build_zero_cst (atype));
    3895                 :        2139 :               insert_before (g);
    3896                 :             :             }
    3897                 :             :         }
    3898                 :        1652 :       else if (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE)
    3899                 :             :         {
    3900                 :        1625 :           imm_use_iterator ui;
    3901                 :        1625 :           use_operand_p use_p;
    3902                 :        1625 :           FOR_EACH_IMM_USE_FAST (use_p, ui, lhs)
    3903                 :             :             {
    3904                 :        1625 :               g = USE_STMT (use_p);
    3905                 :        1625 :               if (!is_gimple_assign (g)
    3906                 :        1625 :                   || gimple_assign_rhs_code (g) != IMAGPART_EXPR)
    3907                 :           0 :                 continue;
    3908                 :        1625 :               tree lhs2 = gimple_assign_lhs (g);
    3909                 :        1625 :               gimple *use_stmt;
    3910                 :        1625 :               single_imm_use (lhs2, &use_p, &use_stmt);
    3911                 :        1625 :               lhs2 = gimple_assign_lhs (use_stmt);
    3912                 :        1625 :               gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
    3913                 :        1625 :               if (useless_type_conversion_p (TREE_TYPE (lhs2), TREE_TYPE (ovf)))
    3914                 :        1611 :                 g = gimple_build_assign (lhs2, ovf);
    3915                 :             :               else
    3916                 :          14 :                 g = gimple_build_assign (lhs2, NOP_EXPR, ovf);
    3917                 :        1625 :               gsi_replace (&gsi, g, true);
    3918                 :        1625 :               if (gsi_stmt (m_gsi) == use_stmt)
    3919                 :          86 :                 m_gsi = gsi_for_stmt (g);
    3920                 :        1625 :               break;
    3921                 :             :             }
    3922                 :             :         }
    3923                 :          27 :       else if (ovf != boolean_false_node)
    3924                 :             :         {
    3925                 :          27 :           g = gimple_build_cond (NE_EXPR, ovf, boolean_false_node,
    3926                 :             :                                  NULL_TREE, NULL_TREE);
    3927                 :          27 :           edge edge_true, edge_false;
    3928                 :          27 :           if_then (g, profile_probability::very_unlikely (),
    3929                 :             :                    edge_true, edge_false);
    3930                 :          27 :           tree zero = build_zero_cst (TREE_TYPE (lhs));
    3931                 :          27 :           tree fn = ubsan_build_overflow_builtin (code, m_loc,
    3932                 :          27 :                                                   TREE_TYPE (lhs),
    3933                 :             :                                                   zero, zero, NULL);
    3934                 :          27 :           force_gimple_operand_gsi (&m_gsi, fn, true, NULL_TREE,
    3935                 :             :                                     true, GSI_SAME_STMT);
    3936                 :          27 :           m_gsi = gsi_after_labels (edge_true->dest);
    3937                 :             :         }
    3938                 :             :     }
    3939                 :        4028 :   if (var)
    3940                 :             :     {
    3941                 :         729 :       tree clobber = build_clobber (TREE_TYPE (var), CLOBBER_STORAGE_END);
    3942                 :         729 :       g = gimple_build_assign (var, clobber);
    3943                 :         729 :       gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
    3944                 :             :     }
    3945                 :        4028 : }
    3946                 :             : 
    3947                 :             : /* Helper function for lower_addsub_overflow and lower_mul_overflow.
    3948                 :             :    Given precisions of result TYPE (PREC), argument 0 precision PREC0,
    3949                 :             :    argument 1 precision PREC1 and minimum precision for the result
    3950                 :             :    PREC2, compute *START, *END, *CHECK_ZERO and return OVF.  */
    3951                 :             : 
    3952                 :             : static tree
    3953                 :        4028 : arith_overflow (tree_code code, tree type, int prec, int prec0, int prec1,
    3954                 :             :                 int prec2, unsigned *start, unsigned *end, bool *check_zero)
    3955                 :             : {
    3956                 :        4028 :   *start = 0;
    3957                 :        4028 :   *end = 0;
    3958                 :        4028 :   *check_zero = true;
    3959                 :             :   /* Ignore this special rule for subtraction, even if both
    3960                 :             :      prec0 >= 0 and prec1 >= 0, their subtraction can be negative
    3961                 :             :      in infinite precision.  */
    3962                 :        4028 :   if (code != MINUS_EXPR && prec0 >= 0 && prec1 >= 0)
    3963                 :             :     {
    3964                 :             :       /* Result in [0, prec2) is unsigned, if prec > prec2,
    3965                 :             :          all bits above it will be zero.  */
    3966                 :         626 :       if ((prec - !TYPE_UNSIGNED (type)) >= prec2)
    3967                 :           0 :         return boolean_false_node;
    3968                 :             :       else
    3969                 :             :         {
    3970                 :             :           /* ovf if any of bits in [start, end) is non-zero.  */
    3971                 :         626 :           *start = prec - !TYPE_UNSIGNED (type);
    3972                 :         626 :           *end = prec2;
    3973                 :             :         }
    3974                 :             :     }
    3975                 :        3402 :   else if (TYPE_UNSIGNED (type))
    3976                 :             :     {
    3977                 :             :       /* If result in [0, prec2) is signed and if prec > prec2,
    3978                 :             :          all bits above it will be sign bit copies.  */
    3979                 :        1920 :       if (prec >= prec2)
    3980                 :             :         {
    3981                 :             :           /* ovf if bit prec - 1 is non-zero.  */
    3982                 :         178 :           *start = prec - 1;
    3983                 :         178 :           *end = prec;
    3984                 :             :         }
    3985                 :             :       else
    3986                 :             :         {
    3987                 :             :           /* ovf if any of bits in [start, end) is non-zero.  */
    3988                 :        1742 :           *start = prec;
    3989                 :        1742 :           *end = prec2;
    3990                 :             :         }
    3991                 :             :     }
    3992                 :        1482 :   else if (prec >= prec2)
    3993                 :           0 :     return boolean_false_node;
    3994                 :             :   else
    3995                 :             :     {
    3996                 :             :       /* ovf if [start, end) bits aren't all zeros or all ones.  */
    3997                 :        1482 :       *start = prec - 1;
    3998                 :        1482 :       *end = prec2;
    3999                 :        1482 :       *check_zero = false;
    4000                 :             :     }
    4001                 :             :   return NULL_TREE;
    4002                 :             : }
    4003                 :             : 
    4004                 :             : /* Lower a .{ADD,SUB}_OVERFLOW call with at least one large/huge _BitInt
    4005                 :             :    argument or return type _Complex large/huge _BitInt.  */
    4006                 :             : 
    4007                 :             : void
    4008                 :        2641 : bitint_large_huge::lower_addsub_overflow (tree obj, gimple *stmt)
    4009                 :             : {
    4010                 :        2641 :   tree arg0 = gimple_call_arg (stmt, 0);
    4011                 :        2641 :   tree arg1 = gimple_call_arg (stmt, 1);
    4012                 :        2641 :   tree lhs = gimple_call_lhs (stmt);
    4013                 :        2641 :   gimple *g;
    4014                 :             : 
    4015                 :        2641 :   if (!lhs)
    4016                 :             :     {
    4017                 :           0 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    4018                 :           0 :       gsi_remove (&gsi, true);
    4019                 :           0 :       return;
    4020                 :             :     }
    4021                 :        2641 :   gimple *final_stmt = gsi_stmt (m_gsi);
    4022                 :        2641 :   tree type = TREE_TYPE (lhs);
    4023                 :        2641 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    4024                 :        2623 :     type = TREE_TYPE (type);
    4025                 :        2641 :   int prec = TYPE_PRECISION (type);
    4026                 :        2641 :   int prec0 = range_to_prec (arg0, stmt);
    4027                 :        2641 :   int prec1 = range_to_prec (arg1, stmt);
    4028                 :             :   /* If PREC0 >= 0 && PREC1 >= 0 and CODE is not MINUS_EXPR, PREC2 is
    4029                 :             :      the be minimum unsigned precision of any possible operation's
    4030                 :             :      result, otherwise it is minimum signed precision.
    4031                 :             :      Some examples:
    4032                 :             :      If PREC0 or PREC1 is 8, it means that argument is [0, 0xff],
    4033                 :             :      if PREC0 or PREC1 is 10, it means that argument is [0, 0x3ff],
    4034                 :             :      if PREC0 or PREC1 is -8, it means that argument is [-0x80, 0x7f],
    4035                 :             :      if PREC0 or PREC1 is -10, it means that argument is [-0x200, 0x1ff].
    4036                 :             :      PREC0  CODE  PREC1  RESULT          PREC2  SIGNED vs. UNSIGNED
    4037                 :             :        8      +     8    [0, 0x1fe]        9    UNSIGNED
    4038                 :             :        8      +    10    [0, 0x4fe]       11    UNSIGNED
    4039                 :             :       -8      +    -8    [-0x100, 0xfe]    9    SIGNED
    4040                 :             :       -8      +   -10    [-0x280, 0x27e]  11    SIGNED
    4041                 :             :        8      +    -8    [-0x80, 0x17e]   10    SIGNED
    4042                 :             :        8      +   -10    [-0x200, 0x2fe]  11    SIGNED
    4043                 :             :       10      +    -8    [-0x80, 0x47e]   12    SIGNED
    4044                 :             :        8      -     8    [-0xff, 0xff]     9    SIGNED
    4045                 :             :        8      -    10    [-0x3ff, 0xff]   11    SIGNED
    4046                 :             :       10      -     8    [-0xff, 0x3ff]   11    SIGNED
    4047                 :             :       -8      -    -8    [-0xff, 0xff]     9    SIGNED
    4048                 :             :       -8      -   -10    [-0x27f, 0x27f]  11    SIGNED
    4049                 :             :      -10      -    -8    [-0x27f, 0x27f]  11    SIGNED
    4050                 :             :        8      -    -8    [-0x7f, 0x17f]   10    SIGNED
    4051                 :             :        8      -   -10    [-0x1ff, 0x2ff]  11    SIGNED
    4052                 :             :       10      -    -8    [-0x7f, 0x47f]   12    SIGNED
    4053                 :             :       -8      -     8    [-0x17f, 0x7f]   10    SIGNED
    4054                 :             :       -8      -    10    [-0x47f, 0x7f]   12    SIGNED
    4055                 :             :      -10      -     8    [-0x2ff, 0x1ff]  11    SIGNED  */
    4056                 :        2641 :   int prec2 = MAX (prec0 < 0 ? -prec0 : prec0,
    4057                 :             :                    prec1 < 0 ? -prec1 : prec1);
    4058                 :             :             /* If operands are either both signed or both unsigned,
    4059                 :             :                we need just one additional bit.  */
    4060                 :        5282 :   prec2 = (((prec0 < 0) == (prec1 < 0)
    4061                 :             :                /* If one operand is signed and one unsigned and
    4062                 :             :                   the signed one has larger precision, we need
    4063                 :             :                   just one extra bit, otherwise two.  */
    4064                 :         700 :             || (prec0 < 0 ? (prec2 == -prec0 && prec2 != prec1)
    4065                 :         336 :                           : (prec2 == -prec1 && prec2 != prec0)))
    4066                 :        3677 :            ? prec2 + 1 : prec2 + 2);
    4067                 :        2641 :   int prec3 = MAX (prec0 < 0 ? -prec0 : prec0,
    4068                 :             :                    prec1 < 0 ? -prec1 : prec1);
    4069                 :        2641 :   prec3 = MAX (prec3, prec);
    4070                 :        2641 :   tree var = NULL_TREE;
    4071                 :        2641 :   tree orig_obj = obj;
    4072                 :        2641 :   if (obj == NULL_TREE
    4073                 :        1663 :       && TREE_CODE (type) == BITINT_TYPE
    4074                 :        1564 :       && bitint_precision_kind (type) >= bitint_prec_large
    4075                 :        1454 :       && m_names
    4076                 :        4075 :       && bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs)))
    4077                 :             :     {
    4078                 :        1380 :       int part = var_to_partition (m_map, lhs);
    4079                 :        1380 :       gcc_assert (m_vars[part] != NULL_TREE);
    4080                 :        1380 :       obj = m_vars[part];
    4081                 :        1380 :       if (TREE_TYPE (lhs) == type)
    4082                 :           2 :         orig_obj = obj;
    4083                 :             :     }
    4084                 :        2641 :   if (TREE_CODE (type) != BITINT_TYPE
    4085                 :        2641 :       || bitint_precision_kind (type) < bitint_prec_large)
    4086                 :             :     {
    4087                 :         209 :       unsigned HOST_WIDE_INT nelts = CEIL (prec, limb_prec);
    4088                 :         209 :       tree atype = build_array_type_nelts (m_limb_type, nelts);
    4089                 :         209 :       var = create_tmp_var (atype);
    4090                 :             :     }
    4091                 :             : 
    4092                 :        2641 :   enum tree_code code;
    4093                 :        2641 :   switch (gimple_call_internal_fn (stmt))
    4094                 :             :     {
    4095                 :             :     case IFN_ADD_OVERFLOW:
    4096                 :             :     case IFN_UBSAN_CHECK_ADD:
    4097                 :             :       code = PLUS_EXPR;
    4098                 :             :       break;
    4099                 :        1349 :     case IFN_SUB_OVERFLOW:
    4100                 :        1349 :     case IFN_UBSAN_CHECK_SUB:
    4101                 :        1349 :       code = MINUS_EXPR;
    4102                 :        1349 :       break;
    4103                 :           0 :     default:
    4104                 :           0 :       gcc_unreachable ();
    4105                 :             :     }
    4106                 :        2641 :   unsigned start, end;
    4107                 :        2641 :   bool check_zero;
    4108                 :        2641 :   tree ovf = arith_overflow (code, type, prec, prec0, prec1, prec2,
    4109                 :             :                              &start, &end, &check_zero);
    4110                 :             : 
    4111                 :        2641 :   unsigned startlimb, endlimb;
    4112                 :        2641 :   if (ovf)
    4113                 :             :     {
    4114                 :             :       startlimb = ~0U;
    4115                 :             :       endlimb = ~0U;
    4116                 :             :     }
    4117                 :             :   else
    4118                 :             :     {
    4119                 :        2641 :       startlimb = start / limb_prec;
    4120                 :        2641 :       endlimb = (end - 1) / limb_prec;
    4121                 :             :     }
    4122                 :             : 
    4123                 :        2641 :   int prec4 = ovf != NULL_TREE ? prec : prec3;
    4124                 :        2641 :   bitint_prec_kind kind = bitint_precision_kind (prec4);
    4125                 :        2641 :   unsigned cnt, rem = 0, fin = 0;
    4126                 :        2641 :   tree idx = NULL_TREE, idx_first = NULL_TREE, idx_next = NULL_TREE;
    4127                 :        5282 :   bool last_ovf = (ovf == NULL_TREE
    4128                 :        2641 :                    && CEIL (prec2, limb_prec) > CEIL (prec3, limb_prec));
    4129                 :        2641 :   if (kind != bitint_prec_huge)
    4130                 :        1537 :     cnt = CEIL (prec4, limb_prec) + last_ovf;
    4131                 :             :   else
    4132                 :             :     {
    4133                 :        1104 :       rem = (prec4 % (2 * limb_prec));
    4134                 :        1104 :       fin = (prec4 - rem) / limb_prec;
    4135                 :        1104 :       cnt = 2 + CEIL (rem, limb_prec) + last_ovf;
    4136                 :        1104 :       idx = idx_first = create_loop (size_zero_node, &idx_next);
    4137                 :             :     }
    4138                 :             : 
    4139                 :        2641 :   if (kind == bitint_prec_huge)
    4140                 :        1104 :     m_upwards_2limb = fin;
    4141                 :        2641 :   m_upwards = true;
    4142                 :             : 
    4143                 :        2641 :   tree type0 = TREE_TYPE (arg0);
    4144                 :        2641 :   tree type1 = TREE_TYPE (arg1);
    4145                 :        2641 :   int prec5 = prec3;
    4146                 :        2641 :   if (bitint_precision_kind (prec5) < bitint_prec_large)
    4147                 :          10 :     prec5 = MAX (TYPE_PRECISION (type0), TYPE_PRECISION (type1));
    4148                 :        2641 :   if (TYPE_PRECISION (type0) < prec5)
    4149                 :             :     {
    4150                 :         136 :       type0 = build_bitint_type (prec5, TYPE_UNSIGNED (type0));
    4151                 :         136 :       if (TREE_CODE (arg0) == INTEGER_CST)
    4152                 :          25 :         arg0 = fold_convert (type0, arg0);
    4153                 :             :     }
    4154                 :        2641 :   if (TYPE_PRECISION (type1) < prec5)
    4155                 :             :     {
    4156                 :         148 :       type1 = build_bitint_type (prec5, TYPE_UNSIGNED (type1));
    4157                 :         148 :       if (TREE_CODE (arg1) == INTEGER_CST)
    4158                 :          70 :         arg1 = fold_convert (type1, arg1);
    4159                 :             :     }
    4160                 :        2641 :   unsigned int data_cnt = 0;
    4161                 :        2641 :   tree last_rhs1 = NULL_TREE, last_rhs2 = NULL_TREE;
    4162                 :        2641 :   tree cmp = build_zero_cst (m_limb_type);
    4163                 :        2641 :   unsigned prec_limbs = CEIL ((unsigned) prec, limb_prec);
    4164                 :        2641 :   tree ovf_out = NULL_TREE, cmp_out = NULL_TREE;
    4165                 :       11506 :   for (unsigned i = 0; i < cnt; i++)
    4166                 :             :     {
    4167                 :        8865 :       m_data_cnt = 0;
    4168                 :        8865 :       tree rhs1, rhs2;
    4169                 :        8865 :       if (kind != bitint_prec_huge)
    4170                 :        5295 :         idx = size_int (i);
    4171                 :        3570 :       else if (i >= 2)
    4172                 :        1362 :         idx = size_int (fin + i - 2);
    4173                 :        8865 :       if (!last_ovf || i < cnt - 1)
    4174                 :             :         {
    4175                 :        7925 :           if (type0 != TREE_TYPE (arg0))
    4176                 :         312 :             rhs1 = handle_cast (type0, arg0, idx);
    4177                 :             :           else
    4178                 :        7613 :             rhs1 = handle_operand (arg0, idx);
    4179                 :        7925 :           if (type1 != TREE_TYPE (arg1))
    4180                 :         242 :             rhs2 = handle_cast (type1, arg1, idx);
    4181                 :             :           else
    4182                 :        7683 :             rhs2 = handle_operand (arg1, idx);
    4183                 :        7925 :           if (i == 0)
    4184                 :        2641 :             data_cnt = m_data_cnt;
    4185                 :        7925 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1)))
    4186                 :        1901 :             rhs1 = add_cast (m_limb_type, rhs1);
    4187                 :        7925 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs2)))
    4188                 :        1901 :             rhs2 = add_cast (m_limb_type, rhs2);
    4189                 :             :           last_rhs1 = rhs1;
    4190                 :             :           last_rhs2 = rhs2;
    4191                 :             :         }
    4192                 :             :       else
    4193                 :             :         {
    4194                 :         940 :           m_data_cnt = data_cnt;
    4195                 :         940 :           if (TYPE_UNSIGNED (type0))
    4196                 :         390 :             rhs1 = build_zero_cst (m_limb_type);
    4197                 :             :           else
    4198                 :             :             {
    4199                 :         550 :               rhs1 = add_cast (signed_type_for (m_limb_type), last_rhs1);
    4200                 :         550 :               if (TREE_CODE (rhs1) == INTEGER_CST)
    4201                 :          83 :                 rhs1 = build_int_cst (m_limb_type,
    4202                 :         136 :                                       tree_int_cst_sgn (rhs1) < 0 ? -1 : 0);
    4203                 :             :               else
    4204                 :             :                 {
    4205                 :         934 :                   tree lpm1 = build_int_cst (unsigned_type_node,
    4206                 :         467 :                                              limb_prec - 1);
    4207                 :         467 :                   g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)),
    4208                 :             :                                            RSHIFT_EXPR, rhs1, lpm1);
    4209                 :         467 :                   insert_before (g);
    4210                 :         467 :                   rhs1 = add_cast (m_limb_type, gimple_assign_lhs (g));
    4211                 :             :                 }
    4212                 :             :             }
    4213                 :         940 :           if (TYPE_UNSIGNED (type1))
    4214                 :         486 :             rhs2 = build_zero_cst (m_limb_type);
    4215                 :             :           else
    4216                 :             :             {
    4217                 :         454 :               rhs2 = add_cast (signed_type_for (m_limb_type), last_rhs2);
    4218                 :         454 :               if (TREE_CODE (rhs2) == INTEGER_CST)
    4219                 :         169 :                 rhs2 = build_int_cst (m_limb_type,
    4220                 :         263 :                                       tree_int_cst_sgn (rhs2) < 0 ? -1 : 0);
    4221                 :             :               else
    4222                 :             :                 {
    4223                 :         570 :                   tree lpm1 = build_int_cst (unsigned_type_node,
    4224                 :         285 :                                              limb_prec - 1);
    4225                 :         285 :                   g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs2)),
    4226                 :             :                                            RSHIFT_EXPR, rhs2, lpm1);
    4227                 :         285 :                   insert_before (g);
    4228                 :         285 :                   rhs2 = add_cast (m_limb_type, gimple_assign_lhs (g));
    4229                 :             :                 }
    4230                 :             :             }
    4231                 :             :         }
    4232                 :        8865 :       tree rhs = handle_plus_minus (code, rhs1, rhs2, idx);
    4233                 :        8865 :       if (ovf != boolean_false_node)
    4234                 :             :         {
    4235                 :        8865 :           if (tree_fits_uhwi_p (idx))
    4236                 :             :             {
    4237                 :        6657 :               unsigned limb = tree_to_uhwi (idx);
    4238                 :        6657 :               if (limb >= startlimb && limb <= endlimb)
    4239                 :             :                 {
    4240                 :        3266 :                   tree l = arith_overflow_extract_bits (start, end, rhs,
    4241                 :             :                                                         limb, check_zero);
    4242                 :        3266 :                   tree this_ovf = make_ssa_name (boolean_type_node);
    4243                 :        3266 :                   if (ovf == NULL_TREE && !check_zero)
    4244                 :             :                     {
    4245                 :         879 :                       cmp = l;
    4246                 :         879 :                       g = gimple_build_assign (make_ssa_name (m_limb_type),
    4247                 :             :                                                PLUS_EXPR, l,
    4248                 :         879 :                                                build_int_cst (m_limb_type, 1));
    4249                 :         879 :                       insert_before (g);
    4250                 :         879 :                       g = gimple_build_assign (this_ovf, GT_EXPR,
    4251                 :             :                                                gimple_assign_lhs (g),
    4252                 :         879 :                                                build_int_cst (m_limb_type, 1));
    4253                 :             :                     }
    4254                 :             :                   else
    4255                 :        2387 :                     g = gimple_build_assign (this_ovf, NE_EXPR, l, cmp);
    4256                 :        3266 :                   insert_before (g);
    4257                 :        3266 :                   if (ovf == NULL_TREE)
    4258                 :             :                     ovf = this_ovf;
    4259                 :             :                   else
    4260                 :             :                     {
    4261                 :        1006 :                       tree b = make_ssa_name (boolean_type_node);
    4262                 :        1006 :                       g = gimple_build_assign (b, BIT_IOR_EXPR, ovf, this_ovf);
    4263                 :        1006 :                       insert_before (g);
    4264                 :        1006 :                       ovf = b;
    4265                 :             :                     }
    4266                 :             :                 }
    4267                 :             :             }
    4268                 :        2208 :           else if (startlimb < fin)
    4269                 :             :             {
    4270                 :         762 :               if (m_first && startlimb + 2 < fin)
    4271                 :             :                 {
    4272                 :         284 :                   tree data_out;
    4273                 :         284 :                   ovf = prepare_data_in_out (boolean_false_node, idx, &data_out);
    4274                 :         284 :                   ovf_out = m_data.pop ();
    4275                 :         284 :                   m_data.pop ();
    4276                 :         284 :                   if (!check_zero)
    4277                 :             :                     {
    4278                 :         145 :                       cmp = prepare_data_in_out (cmp, idx, &data_out);
    4279                 :         145 :                       cmp_out = m_data.pop ();
    4280                 :         145 :                       m_data.pop ();
    4281                 :             :                     }
    4282                 :             :                 }
    4283                 :         762 :               if (i != 0 || startlimb != fin - 1)
    4284                 :             :                 {
    4285                 :         753 :                   tree_code cmp_code;
    4286                 :        1506 :                   bool single_comparison
    4287                 :         753 :                     = (startlimb + 2 >= fin || (startlimb & 1) != (i & 1));
    4288                 :         284 :                   if (!single_comparison)
    4289                 :             :                     {
    4290                 :         284 :                       cmp_code = GE_EXPR;
    4291                 :         284 :                       if (!check_zero && (start % limb_prec) == 0)
    4292                 :         753 :                         single_comparison = true;
    4293                 :             :                     }
    4294                 :         469 :                   else if ((startlimb & 1) == (i & 1))
    4295                 :             :                     cmp_code = EQ_EXPR;
    4296                 :             :                   else
    4297                 :         372 :                     cmp_code = GT_EXPR;
    4298                 :         753 :                   g = gimple_build_cond (cmp_code, idx, size_int (startlimb),
    4299                 :             :                                          NULL_TREE, NULL_TREE);
    4300                 :         753 :                   edge edge_true_true, edge_true_false, edge_false;
    4301                 :         753 :                   gimple *g2 = NULL;
    4302                 :         753 :                   if (!single_comparison)
    4303                 :         240 :                     g2 = gimple_build_cond (NE_EXPR, idx,
    4304                 :             :                                             size_int (startlimb), NULL_TREE,
    4305                 :             :                                             NULL_TREE);
    4306                 :         753 :                   if_then_if_then_else (g, g2, profile_probability::likely (),
    4307                 :             :                                         profile_probability::likely (),
    4308                 :             :                                         edge_true_true, edge_true_false,
    4309                 :             :                                         edge_false);
    4310                 :         753 :                   unsigned tidx = startlimb + (cmp_code == GT_EXPR);
    4311                 :         753 :                   tree l = arith_overflow_extract_bits (start, end, rhs, tidx,
    4312                 :             :                                                         check_zero);
    4313                 :         753 :                   tree this_ovf = make_ssa_name (boolean_type_node);
    4314                 :         753 :                   if (cmp_code != GT_EXPR && !check_zero)
    4315                 :             :                     {
    4316                 :         147 :                       g = gimple_build_assign (make_ssa_name (m_limb_type),
    4317                 :             :                                                PLUS_EXPR, l,
    4318                 :         147 :                                                build_int_cst (m_limb_type, 1));
    4319                 :         147 :                       insert_before (g);
    4320                 :         147 :                       g = gimple_build_assign (this_ovf, GT_EXPR,
    4321                 :             :                                                gimple_assign_lhs (g),
    4322                 :         147 :                                                build_int_cst (m_limb_type, 1));
    4323                 :             :                     }
    4324                 :             :                   else
    4325                 :         606 :                     g = gimple_build_assign (this_ovf, NE_EXPR, l, cmp);
    4326                 :         753 :                   insert_before (g);
    4327                 :         753 :                   if (cmp_code == GT_EXPR)
    4328                 :             :                     {
    4329                 :         372 :                       tree t = make_ssa_name (boolean_type_node);
    4330                 :         372 :                       g = gimple_build_assign (t, BIT_IOR_EXPR, ovf, this_ovf);
    4331                 :         372 :                       insert_before (g);
    4332                 :         372 :                       this_ovf = t;
    4333                 :             :                     }
    4334                 :         753 :                   tree this_ovf2 = NULL_TREE;
    4335                 :         753 :                   if (!single_comparison)
    4336                 :             :                     {
    4337                 :         240 :                       m_gsi = gsi_after_labels (edge_true_true->src);
    4338                 :         240 :                       tree t = make_ssa_name (boolean_type_node);
    4339                 :         240 :                       g = gimple_build_assign (t, NE_EXPR, rhs, cmp);
    4340                 :         240 :                       insert_before (g);
    4341                 :         240 :                       this_ovf2 = make_ssa_name (boolean_type_node);
    4342                 :         240 :                       g = gimple_build_assign (this_ovf2, BIT_IOR_EXPR,
    4343                 :             :                                                ovf, t);
    4344                 :         240 :                       insert_before (g);
    4345                 :             :                     }
    4346                 :         753 :                   m_gsi = gsi_after_labels (edge_true_false->dest);
    4347                 :         753 :                   tree t;
    4348                 :         753 :                   if (i == 1 && ovf_out)
    4349                 :             :                     t = ovf_out;
    4350                 :             :                   else
    4351                 :         469 :                     t = make_ssa_name (boolean_type_node);
    4352                 :         753 :                   gphi *phi = create_phi_node (t, edge_true_false->dest);
    4353                 :         753 :                   add_phi_arg (phi, this_ovf, edge_true_false,
    4354                 :             :                                UNKNOWN_LOCATION);
    4355                 :         753 :                   add_phi_arg (phi, ovf ? ovf
    4356                 :             :                                     : boolean_false_node, edge_false,
    4357                 :             :                                UNKNOWN_LOCATION);
    4358                 :         753 :                   if (edge_true_true)
    4359                 :         240 :                     add_phi_arg (phi, this_ovf2, edge_true_true,
    4360                 :             :                                  UNKNOWN_LOCATION);
    4361                 :         753 :                   ovf = t;
    4362                 :         753 :                   if (!check_zero && cmp_code != GT_EXPR)
    4363                 :             :                     {
    4364                 :         147 :                       t = cmp_out ? cmp_out : make_ssa_name (m_limb_type);
    4365                 :         147 :                       phi = create_phi_node (t, edge_true_false->dest);
    4366                 :         147 :                       add_phi_arg (phi, l, edge_true_false, UNKNOWN_LOCATION);
    4367                 :         147 :                       add_phi_arg (phi, cmp, edge_false, UNKNOWN_LOCATION);
    4368                 :         147 :                       if (edge_true_true)
    4369                 :         101 :                         add_phi_arg (phi, cmp, edge_true_true,
    4370                 :             :                                      UNKNOWN_LOCATION);
    4371                 :             :                       cmp = t;
    4372                 :             :                     }
    4373                 :             :                 }
    4374                 :             :             }
    4375                 :             :         }
    4376                 :             : 
    4377                 :        8865 :       if (var || obj)
    4378                 :             :         {
    4379                 :        8648 :           if (tree_fits_uhwi_p (idx) && tree_to_uhwi (idx) >= prec_limbs)
    4380                 :             :             ;
    4381                 :        7317 :           else if (!tree_fits_uhwi_p (idx)
    4382                 :        2100 :                    && (unsigned) prec < (fin - (i == 0)) * limb_prec)
    4383                 :             :             {
    4384                 :        1296 :               bool single_comparison
    4385                 :         648 :                 = (((unsigned) prec % limb_prec) == 0
    4386                 :         490 :                    || prec_limbs + 1 >= fin
    4387                 :        1070 :                    || (prec_limbs & 1) == (i & 1));
    4388                 :         648 :               g = gimple_build_cond (LE_EXPR, idx, size_int (prec_limbs - 1),
    4389                 :             :                                      NULL_TREE, NULL_TREE);
    4390                 :         648 :               gimple *g2 = NULL;
    4391                 :         648 :               if (!single_comparison)
    4392                 :         211 :                 g2 = gimple_build_cond (EQ_EXPR, idx,
    4393                 :         211 :                                         size_int (prec_limbs - 1),
    4394                 :             :                                         NULL_TREE, NULL_TREE);
    4395                 :         648 :               edge edge_true_true, edge_true_false, edge_false;
    4396                 :         648 :               if_then_if_then_else (g, g2, profile_probability::likely (),
    4397                 :             :                                     profile_probability::unlikely (),
    4398                 :             :                                     edge_true_true, edge_true_false,
    4399                 :             :                                     edge_false);
    4400                 :         936 :               tree l = limb_access (type, var ? var : obj, idx, true);
    4401                 :         648 :               g = gimple_build_assign (l, rhs);
    4402                 :         648 :               insert_before (g);
    4403                 :         648 :               if (!single_comparison)
    4404                 :             :                 {
    4405                 :         211 :                   m_gsi = gsi_after_labels (edge_true_true->src);
    4406                 :         211 :                   tree plm1idx = size_int (prec_limbs - 1);
    4407                 :         211 :                   tree plm1type = limb_access_type (type, plm1idx);
    4408                 :         211 :                   l = limb_access (type, var ? var : obj, plm1idx, true);
    4409                 :         211 :                   if (!useless_type_conversion_p (plm1type, TREE_TYPE (rhs)))
    4410                 :         211 :                     rhs = add_cast (plm1type, rhs);
    4411                 :         211 :                   if (!useless_type_conversion_p (TREE_TYPE (l),
    4412                 :         211 :                                                   TREE_TYPE (rhs)))
    4413                 :         211 :                     rhs = add_cast (TREE_TYPE (l), rhs);
    4414                 :         211 :                   g = gimple_build_assign (l, rhs);
    4415                 :         211 :                   insert_before (g);
    4416                 :             :                 }
    4417                 :         648 :               m_gsi = gsi_after_labels (edge_true_false->dest);
    4418                 :         648 :             }
    4419                 :             :           else
    4420                 :             :             {
    4421                 :       13309 :               tree l = limb_access (type, var ? var : obj, idx, true);
    4422                 :        6669 :               if (!useless_type_conversion_p (TREE_TYPE (l), TREE_TYPE (rhs)))
    4423                 :           0 :                 rhs = add_cast (TREE_TYPE (l), rhs);
    4424                 :        6669 :               g = gimple_build_assign (l, rhs);
    4425                 :        6669 :               insert_before (g);
    4426                 :             :             }
    4427                 :             :         }
    4428                 :        8865 :       m_first = false;
    4429                 :        8865 :       if (kind == bitint_prec_huge && i <= 1)
    4430                 :             :         {
    4431                 :        2208 :           if (i == 0)
    4432                 :             :             {
    4433                 :        1104 :               idx = make_ssa_name (sizetype);
    4434                 :        1104 :               g = gimple_build_assign (idx, PLUS_EXPR, idx_first,
    4435                 :             :                                        size_one_node);
    4436                 :        1104 :               insert_before (g);
    4437                 :             :             }
    4438                 :             :           else
    4439                 :             :             {
    4440                 :        1104 :               g = gimple_build_assign (idx_next, PLUS_EXPR, idx_first,
    4441                 :        1104 :                                        size_int (2));
    4442                 :        1104 :               insert_before (g);
    4443                 :        1104 :               g = gimple_build_cond (NE_EXPR, idx_next, size_int (fin),
    4444                 :             :                                      NULL_TREE, NULL_TREE);
    4445                 :        1104 :               insert_before (g);
    4446                 :        1104 :               m_gsi = gsi_for_stmt (final_stmt);
    4447                 :        1104 :               m_bb = NULL;
    4448                 :             :             }
    4449                 :             :         }
    4450                 :             :     }
    4451                 :             : 
    4452                 :        2641 :   finish_arith_overflow (var, obj, type, ovf, lhs, orig_obj, stmt, code);
    4453                 :             : }
    4454                 :             : 
    4455                 :             : /* Lower a .MUL_OVERFLOW call with at least one large/huge _BitInt
    4456                 :             :    argument or return type _Complex large/huge _BitInt.  */
    4457                 :             : 
    4458                 :             : void
    4459                 :        1387 : bitint_large_huge::lower_mul_overflow (tree obj, gimple *stmt)
    4460                 :             : {
    4461                 :        1387 :   tree arg0 = gimple_call_arg (stmt, 0);
    4462                 :        1387 :   tree arg1 = gimple_call_arg (stmt, 1);
    4463                 :        1387 :   tree lhs = gimple_call_lhs (stmt);
    4464                 :        1387 :   if (!lhs)
    4465                 :             :     {
    4466                 :           0 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    4467                 :           0 :       gsi_remove (&gsi, true);
    4468                 :           0 :       return;
    4469                 :             :     }
    4470                 :        1387 :   gimple *final_stmt = gsi_stmt (m_gsi);
    4471                 :        1387 :   tree type = TREE_TYPE (lhs);
    4472                 :        1387 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    4473                 :        1378 :     type = TREE_TYPE (type);
    4474                 :        1387 :   int prec = TYPE_PRECISION (type), prec0, prec1;
    4475                 :        1387 :   arg0 = handle_operand_addr (arg0, stmt, NULL, &prec0);
    4476                 :        1387 :   arg1 = handle_operand_addr (arg1, stmt, NULL, &prec1);
    4477                 :        1387 :   int prec2 = ((prec0 < 0 ? -prec0 : prec0)
    4478                 :        1387 :                + (prec1 < 0 ? -prec1 : prec1));
    4479                 :        1387 :   if (prec0 == 1 || prec1 == 1)
    4480                 :          18 :     --prec2;
    4481                 :        1387 :   tree var = NULL_TREE;
    4482                 :        1387 :   tree orig_obj = obj;
    4483                 :        1387 :   bool force_var = false;
    4484                 :        1387 :   if (obj == NULL_TREE
    4485                 :         802 :       && TREE_CODE (type) == BITINT_TYPE
    4486                 :         796 :       && bitint_precision_kind (type) >= bitint_prec_large
    4487                 :         774 :       && m_names
    4488                 :        2149 :       && bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs)))
    4489                 :             :     {
    4490                 :         762 :       int part = var_to_partition (m_map, lhs);
    4491                 :         762 :       gcc_assert (m_vars[part] != NULL_TREE);
    4492                 :         762 :       obj = m_vars[part];
    4493                 :         762 :       if (TREE_TYPE (lhs) == type)
    4494                 :           1 :         orig_obj = obj;
    4495                 :             :     }
    4496                 :         625 :   else if (obj != NULL_TREE && DECL_P (obj))
    4497                 :             :     {
    4498                 :        1731 :       for (int i = 0; i < 2; ++i)
    4499                 :             :         {
    4500                 :        1154 :           tree arg = i ? arg1 : arg0;
    4501                 :        1154 :           if (TREE_CODE (arg) == ADDR_EXPR)
    4502                 :        1154 :             arg = TREE_OPERAND (arg, 0);
    4503                 :        1154 :           if (get_base_address (arg) == obj)
    4504                 :             :             {
    4505                 :             :               force_var = true;
    4506                 :             :               break;
    4507                 :             :             }
    4508                 :             :         }
    4509                 :             :     }
    4510                 :        1387 :   if (obj == NULL_TREE
    4511                 :        1387 :       || force_var
    4512                 :        1347 :       || TREE_CODE (type) != BITINT_TYPE
    4513                 :        1347 :       || bitint_precision_kind (type) < bitint_prec_large
    4514                 :        3495 :       || prec2 > (CEIL (prec, limb_prec) * limb_prec * (orig_obj ? 1 : 2)))
    4515                 :             :     {
    4516                 :         520 :       unsigned HOST_WIDE_INT nelts = CEIL (MAX (prec, prec2), limb_prec);
    4517                 :         520 :       tree atype = build_array_type_nelts (m_limb_type, nelts);
    4518                 :         520 :       var = create_tmp_var (atype);
    4519                 :             :     }
    4520                 :        1387 :   tree addr = build_fold_addr_expr (var ? var : obj);
    4521                 :        1387 :   addr = force_gimple_operand_gsi (&m_gsi, addr, true,
    4522                 :             :                                    NULL_TREE, true, GSI_SAME_STMT);
    4523                 :        1387 :   tree sitype = lang_hooks.types.type_for_mode (SImode, 0);
    4524                 :        1387 :   gimple *g
    4525                 :        2774 :     = gimple_build_call_internal (IFN_MULBITINT, 6,
    4526                 :             :                                   addr, build_int_cst (sitype,
    4527                 :        1387 :                                                        MAX (prec2, prec)),
    4528                 :             :                                   arg0, build_int_cst (sitype, prec0),
    4529                 :             :                                   arg1, build_int_cst (sitype, prec1));
    4530                 :        1387 :   insert_before (g);
    4531                 :             : 
    4532                 :        1387 :   unsigned start, end;
    4533                 :        1387 :   bool check_zero;
    4534                 :        1387 :   tree ovf = arith_overflow (MULT_EXPR, type, prec, prec0, prec1, prec2,
    4535                 :             :                              &start, &end, &check_zero);
    4536                 :        1387 :   if (ovf == NULL_TREE)
    4537                 :             :     {
    4538                 :        1387 :       unsigned startlimb = start / limb_prec;
    4539                 :        1387 :       unsigned endlimb = (end - 1) / limb_prec;
    4540                 :        1387 :       unsigned cnt;
    4541                 :        1387 :       bool use_loop = false;
    4542                 :        1387 :       if (startlimb == endlimb)
    4543                 :             :         cnt = 1;
    4544                 :        1114 :       else if (startlimb + 1 == endlimb)
    4545                 :             :         cnt = 2;
    4546                 :         943 :       else if ((end % limb_prec) == 0)
    4547                 :             :         {
    4548                 :             :           cnt = 2;
    4549                 :             :           use_loop = true;
    4550                 :             :         }
    4551                 :             :       else
    4552                 :             :         {
    4553                 :         702 :           cnt = 3;
    4554                 :         702 :           use_loop = startlimb + 2 < endlimb;
    4555                 :             :         }
    4556                 :         702 :       if (cnt == 1)
    4557                 :             :         {
    4558                 :         480 :           tree l = limb_access (NULL_TREE, var ? var : obj,
    4559                 :             :                                 size_int (startlimb), true);
    4560                 :         273 :           g = gimple_build_assign (make_ssa_name (m_limb_type), l);
    4561                 :         273 :           insert_before (g);
    4562                 :         273 :           l = arith_overflow_extract_bits (start, end, gimple_assign_lhs (g),
    4563                 :             :                                            startlimb, check_zero);
    4564                 :         273 :           ovf = make_ssa_name (boolean_type_node);
    4565                 :         273 :           if (check_zero)
    4566                 :         233 :             g = gimple_build_assign (ovf, NE_EXPR, l,
    4567                 :             :                                      build_zero_cst (m_limb_type));
    4568                 :             :           else
    4569                 :             :             {
    4570                 :          40 :               g = gimple_build_assign (make_ssa_name (m_limb_type),
    4571                 :             :                                        PLUS_EXPR, l,
    4572                 :          40 :                                        build_int_cst (m_limb_type, 1));
    4573                 :          40 :               insert_before (g);
    4574                 :          40 :               g = gimple_build_assign (ovf, GT_EXPR, gimple_assign_lhs (g),
    4575                 :          40 :                                        build_int_cst (m_limb_type, 1));
    4576                 :             :             }
    4577                 :         273 :           insert_before (g);
    4578                 :             :         }
    4579                 :             :       else
    4580                 :             :         {
    4581                 :        1114 :           basic_block edge_bb = NULL;
    4582                 :        1114 :           gimple_stmt_iterator gsi = m_gsi;
    4583                 :        1114 :           gsi_prev (&gsi);
    4584                 :        1114 :           edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    4585                 :        1114 :           edge_bb = e->src;
    4586                 :        1114 :           m_gsi = gsi_end_bb (edge_bb);
    4587                 :             : 
    4588                 :        1114 :           tree cmp = build_zero_cst (m_limb_type);
    4589                 :        4044 :           for (unsigned i = 0; i < cnt; i++)
    4590                 :             :             {
    4591                 :        2930 :               tree idx, idx_next = NULL_TREE;
    4592                 :        2930 :               if (i == 0)
    4593                 :        1114 :                 idx = size_int (startlimb);
    4594                 :        1816 :               else if (i == 2)
    4595                 :         702 :                 idx = size_int (endlimb);
    4596                 :        1114 :               else if (use_loop)
    4597                 :         595 :                 idx = create_loop (size_int (startlimb + 1), &idx_next);
    4598                 :             :               else
    4599                 :         519 :                 idx = size_int (startlimb + 1);
    4600                 :        4673 :               tree l = limb_access (NULL_TREE, var ? var : obj, idx, true);
    4601                 :        2930 :               g = gimple_build_assign (make_ssa_name (m_limb_type), l);
    4602                 :        2930 :               insert_before (g);
    4603                 :        2930 :               l = gimple_assign_lhs (g);
    4604                 :        2930 :               if (i == 0 || i == 2)
    4605                 :        1816 :                 l = arith_overflow_extract_bits (start, end, l,
    4606                 :        1816 :                                                  tree_to_uhwi (idx),
    4607                 :             :                                                  check_zero);
    4608                 :        1816 :               if (i == 0 && !check_zero)
    4609                 :             :                 {
    4610                 :         416 :                   cmp = l;
    4611                 :         416 :                   g = gimple_build_assign (make_ssa_name (m_limb_type),
    4612                 :             :                                            PLUS_EXPR, l,
    4613                 :         416 :                                            build_int_cst (m_limb_type, 1));
    4614                 :         416 :                   insert_before (g);
    4615                 :         416 :                   g = gimple_build_cond (GT_EXPR, gimple_assign_lhs (g),
    4616                 :         416 :                                          build_int_cst (m_limb_type, 1),
    4617                 :             :                                          NULL_TREE, NULL_TREE);
    4618                 :             :                 }
    4619                 :             :               else
    4620                 :        2514 :                 g = gimple_build_cond (NE_EXPR, l, cmp, NULL_TREE, NULL_TREE);
    4621                 :        2930 :               insert_before (g);
    4622                 :        2930 :               edge e1 = split_block (gsi_bb (m_gsi), g);
    4623                 :        2930 :               e1->flags = EDGE_FALSE_VALUE;
    4624                 :        2930 :               edge e2 = make_edge (e1->src, gimple_bb (final_stmt),
    4625                 :             :                                    EDGE_TRUE_VALUE);
    4626                 :        2930 :               e1->probability = profile_probability::likely ();
    4627                 :        2930 :               e2->probability = e1->probability.invert ();
    4628                 :        2930 :               if (i == 0)
    4629                 :        1114 :                 set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    4630                 :        2930 :               m_gsi = gsi_after_labels (e1->dest);
    4631                 :        2930 :               if (i == 1 && use_loop)
    4632                 :             :                 {
    4633                 :         595 :                   g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    4634                 :             :                                            size_one_node);
    4635                 :         595 :                   insert_before (g);
    4636                 :         595 :                   g = gimple_build_cond (NE_EXPR, idx_next,
    4637                 :         595 :                                          size_int (endlimb + (cnt == 2)),
    4638                 :             :                                          NULL_TREE, NULL_TREE);
    4639                 :         595 :                   insert_before (g);
    4640                 :         595 :                   edge true_edge, false_edge;
    4641                 :         595 :                   extract_true_false_edges_from_block (gsi_bb (m_gsi),
    4642                 :             :                                                        &true_edge,
    4643                 :             :                                                        &false_edge);
    4644                 :         595 :                   m_gsi = gsi_after_labels (false_edge->dest);
    4645                 :         595 :                   m_bb = NULL;
    4646                 :             :                 }
    4647                 :             :             }
    4648                 :             : 
    4649                 :        1114 :           ovf = make_ssa_name (boolean_type_node);
    4650                 :        1114 :           basic_block bb = gimple_bb (final_stmt);
    4651                 :        1114 :           gphi *phi = create_phi_node (ovf, bb);
    4652                 :        1114 :           edge e1 = find_edge (gsi_bb (m_gsi), bb);
    4653                 :        1114 :           edge_iterator ei;
    4654                 :        5158 :           FOR_EACH_EDGE (e, ei, bb->preds)
    4655                 :             :             {
    4656                 :        4044 :               tree val = e == e1 ? boolean_false_node : boolean_true_node;
    4657                 :        4044 :               add_phi_arg (phi, val, e, UNKNOWN_LOCATION);
    4658                 :             :             }
    4659                 :        1114 :           m_gsi = gsi_for_stmt (final_stmt);
    4660                 :             :         }
    4661                 :             :     }
    4662                 :             : 
    4663                 :        1387 :   finish_arith_overflow (var, obj, type, ovf, lhs, orig_obj, stmt, MULT_EXPR);
    4664                 :             : }
    4665                 :             : 
    4666                 :             : /* Lower REALPART_EXPR or IMAGPART_EXPR stmt extracting part of result from
    4667                 :             :    .{ADD,SUB,MUL}_OVERFLOW call.  */
    4668                 :             : 
    4669                 :             : void
    4670                 :        5717 : bitint_large_huge::lower_cplxpart_stmt (tree obj, gimple *stmt)
    4671                 :             : {
    4672                 :        5717 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    4673                 :        5717 :   rhs1 = TREE_OPERAND (rhs1, 0);
    4674                 :        5717 :   if (obj == NULL_TREE)
    4675                 :             :     {
    4676                 :        5715 :       int part = var_to_partition (m_map, gimple_assign_lhs (stmt));
    4677                 :        5715 :       gcc_assert (m_vars[part] != NULL_TREE);
    4678                 :             :       obj = m_vars[part];
    4679                 :             :     }
    4680                 :        5717 :   if (TREE_CODE (rhs1) == SSA_NAME
    4681                 :        5717 :       && (m_names == NULL
    4682                 :        5717 :           || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1))))
    4683                 :             :     {
    4684                 :        1539 :       lower_call (obj, SSA_NAME_DEF_STMT (rhs1));
    4685                 :        1539 :       return;
    4686                 :             :     }
    4687                 :        4178 :   int part = var_to_partition (m_map, rhs1);
    4688                 :        4178 :   gcc_assert (m_vars[part] != NULL_TREE);
    4689                 :        4178 :   tree var = m_vars[part];
    4690                 :        4178 :   unsigned HOST_WIDE_INT nelts
    4691                 :        4178 :     = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (obj))) / limb_prec;
    4692                 :        4178 :   tree atype = build_array_type_nelts (m_limb_type, nelts);
    4693                 :        4178 :   if (!useless_type_conversion_p (atype, TREE_TYPE (obj)))
    4694                 :           0 :     obj = build1 (VIEW_CONVERT_EXPR, atype, obj);
    4695                 :        4178 :   tree off = build_int_cst (build_pointer_type (TREE_TYPE (var)),
    4696                 :        4178 :                             gimple_assign_rhs_code (stmt) == REALPART_EXPR
    4697                 :        4178 :                             ? 0 : nelts * m_limb_size);
    4698                 :        4178 :   tree v2 = build2 (MEM_REF, atype, build_fold_addr_expr (var), off);
    4699                 :        4178 :   gimple *g = gimple_build_assign (obj, v2);
    4700                 :        4178 :   insert_before (g);
    4701                 :             : }
    4702                 :             : 
    4703                 :             : /* Lower COMPLEX_EXPR stmt.  */
    4704                 :             : 
    4705                 :             : void
    4706                 :          18 : bitint_large_huge::lower_complexexpr_stmt (gimple *stmt)
    4707                 :             : {
    4708                 :          18 :   tree lhs = gimple_assign_lhs (stmt);
    4709                 :          18 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    4710                 :          18 :   tree rhs2 = gimple_assign_rhs2 (stmt);
    4711                 :          18 :   int part = var_to_partition (m_map, lhs);
    4712                 :          18 :   gcc_assert (m_vars[part] != NULL_TREE);
    4713                 :          18 :   lhs = m_vars[part];
    4714                 :          18 :   unsigned HOST_WIDE_INT nelts
    4715                 :          18 :     = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (rhs1))) / limb_prec;
    4716                 :          18 :   tree atype = build_array_type_nelts (m_limb_type, nelts);
    4717                 :          18 :   tree zero = build_zero_cst (build_pointer_type (TREE_TYPE (lhs)));
    4718                 :          18 :   tree v1 = build2 (MEM_REF, atype, build_fold_addr_expr (lhs), zero);
    4719                 :          18 :   tree v2;
    4720                 :          18 :   if (TREE_CODE (rhs1) == SSA_NAME)
    4721                 :             :     {
    4722                 :          18 :       part = var_to_partition (m_map, rhs1);
    4723                 :          18 :       gcc_assert (m_vars[part] != NULL_TREE);
    4724                 :             :       v2 = m_vars[part];
    4725                 :             :     }
    4726                 :           0 :   else if (integer_zerop (rhs1))
    4727                 :           0 :     v2 = build_zero_cst (atype);
    4728                 :             :   else
    4729                 :           0 :     v2 = tree_output_constant_def (rhs1);
    4730                 :          18 :   if (!useless_type_conversion_p (atype, TREE_TYPE (v2)))
    4731                 :          18 :     v2 = build1 (VIEW_CONVERT_EXPR, atype, v2);
    4732                 :          18 :   gimple *g = gimple_build_assign (v1, v2);
    4733                 :          18 :   insert_before (g);
    4734                 :          18 :   tree off = fold_convert (build_pointer_type (TREE_TYPE (lhs)),
    4735                 :             :                            TYPE_SIZE_UNIT (atype));
    4736                 :          18 :   v1 = build2 (MEM_REF, atype, build_fold_addr_expr (lhs), off);
    4737                 :          18 :   if (TREE_CODE (rhs2) == SSA_NAME)
    4738                 :             :     {
    4739                 :           0 :       part = var_to_partition (m_map, rhs2);
    4740                 :           0 :       gcc_assert (m_vars[part] != NULL_TREE);
    4741                 :             :       v2 = m_vars[part];
    4742                 :             :     }
    4743                 :          18 :   else if (integer_zerop (rhs2))
    4744                 :          18 :     v2 = build_zero_cst (atype);
    4745                 :             :   else
    4746                 :           0 :     v2 = tree_output_constant_def (rhs2);
    4747                 :          18 :   if (!useless_type_conversion_p (atype, TREE_TYPE (v2)))
    4748                 :           0 :     v2 = build1 (VIEW_CONVERT_EXPR, atype, v2);
    4749                 :          18 :   g = gimple_build_assign (v1, v2);
    4750                 :          18 :   insert_before (g);
    4751                 :          18 : }
    4752                 :             : 
    4753                 :             : /* Lower a .{CLZ,CTZ,CLRSB,FFS,PARITY,POPCOUNT} call with one large/huge _BitInt
    4754                 :             :    argument.  */
    4755                 :             : 
    4756                 :             : void
    4757                 :          90 : bitint_large_huge::lower_bit_query (gimple *stmt)
    4758                 :             : {
    4759                 :          90 :   tree arg0 = gimple_call_arg (stmt, 0);
    4760                 :          90 :   tree arg1 = (gimple_call_num_args (stmt) == 2
    4761                 :          90 :                ? gimple_call_arg (stmt, 1) : NULL_TREE);
    4762                 :          90 :   tree lhs = gimple_call_lhs (stmt);
    4763                 :          90 :   gimple *g;
    4764                 :             : 
    4765                 :          90 :   if (!lhs)
    4766                 :             :     {
    4767                 :           0 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    4768                 :           0 :       gsi_remove (&gsi, true);
    4769                 :           0 :       return;
    4770                 :             :     }
    4771                 :          90 :   tree type = TREE_TYPE (arg0);
    4772                 :          90 :   gcc_assert (TREE_CODE (type) == BITINT_TYPE);
    4773                 :          90 :   bitint_prec_kind kind = bitint_precision_kind (type);
    4774                 :          90 :   gcc_assert (kind >= bitint_prec_large);
    4775                 :          90 :   enum internal_fn ifn = gimple_call_internal_fn (stmt);
    4776                 :          90 :   enum built_in_function fcode = END_BUILTINS;
    4777                 :          90 :   gcc_assert (TYPE_PRECISION (unsigned_type_node) == limb_prec
    4778                 :             :               || TYPE_PRECISION (long_unsigned_type_node) == limb_prec
    4779                 :             :               || TYPE_PRECISION (long_long_unsigned_type_node) == limb_prec);
    4780                 :          90 :   switch (ifn)
    4781                 :             :     {
    4782                 :          24 :     case IFN_CLZ:
    4783                 :          24 :       if (TYPE_PRECISION (unsigned_type_node) == limb_prec)
    4784                 :             :         fcode = BUILT_IN_CLZ;
    4785                 :          24 :       else if (TYPE_PRECISION (long_unsigned_type_node) == limb_prec)
    4786                 :             :         fcode = BUILT_IN_CLZL;
    4787                 :             :       else
    4788                 :           0 :         fcode = BUILT_IN_CLZLL;
    4789                 :             :       break;
    4790                 :          10 :     case IFN_FFS:
    4791                 :             :       /* .FFS (X) is .CTZ (X, -1) + 1, though under the hood
    4792                 :             :          we don't add the addend at the end.  */
    4793                 :          10 :       arg1 = integer_zero_node;
    4794                 :             :       /* FALLTHRU */
    4795                 :          37 :     case IFN_CTZ:
    4796                 :          37 :       if (TYPE_PRECISION (unsigned_type_node) == limb_prec)
    4797                 :             :         fcode = BUILT_IN_CTZ;
    4798                 :          37 :       else if (TYPE_PRECISION (long_unsigned_type_node) == limb_prec)
    4799                 :             :         fcode = BUILT_IN_CTZL;
    4800                 :             :       else
    4801                 :           0 :         fcode = BUILT_IN_CTZLL;
    4802                 :          37 :       m_upwards = true;
    4803                 :          37 :       break;
    4804                 :           8 :     case IFN_CLRSB:
    4805                 :           8 :       if (TYPE_PRECISION (unsigned_type_node) == limb_prec)
    4806                 :             :         fcode = BUILT_IN_CLRSB;
    4807                 :           8 :       else if (TYPE_PRECISION (long_unsigned_type_node) == limb_prec)
    4808                 :             :         fcode = BUILT_IN_CLRSBL;
    4809                 :             :       else
    4810                 :           0 :         fcode = BUILT_IN_CLRSBLL;
    4811                 :             :       break;
    4812                 :          11 :     case IFN_PARITY:
    4813                 :          11 :       if (TYPE_PRECISION (unsigned_type_node) == limb_prec)
    4814                 :             :         fcode = BUILT_IN_PARITY;
    4815                 :          11 :       else if (TYPE_PRECISION (long_unsigned_type_node) == limb_prec)
    4816                 :             :         fcode = BUILT_IN_PARITYL;
    4817                 :             :       else
    4818                 :           0 :         fcode = BUILT_IN_PARITYLL;
    4819                 :          11 :       m_upwards = true;
    4820                 :          11 :       break;
    4821                 :          10 :     case IFN_POPCOUNT:
    4822                 :          10 :       if (TYPE_PRECISION (unsigned_type_node) == limb_prec)
    4823                 :             :         fcode = BUILT_IN_POPCOUNT;
    4824                 :          10 :       else if (TYPE_PRECISION (long_unsigned_type_node) == limb_prec)
    4825                 :             :         fcode = BUILT_IN_POPCOUNTL;
    4826                 :             :       else
    4827                 :           0 :         fcode = BUILT_IN_POPCOUNTLL;
    4828                 :          10 :       m_upwards = true;
    4829                 :          10 :       break;
    4830                 :           0 :     default:
    4831                 :           0 :       gcc_unreachable ();
    4832                 :             :     }
    4833                 :          90 :   tree fndecl = builtin_decl_explicit (fcode), res = NULL_TREE;
    4834                 :          90 :   unsigned cnt = 0, rem = 0, end = 0, prec = TYPE_PRECISION (type);
    4835                 :          90 :   struct bq_details { edge e; tree val, addend; } *bqp = NULL;
    4836                 :          90 :   basic_block edge_bb = NULL;
    4837                 :          90 :   if (m_upwards)
    4838                 :             :     {
    4839                 :          58 :       tree idx = NULL_TREE, idx_first = NULL_TREE, idx_next = NULL_TREE;
    4840                 :          58 :       if (kind == bitint_prec_large)
    4841                 :          26 :         cnt = CEIL (prec, limb_prec);
    4842                 :             :       else
    4843                 :             :         {
    4844                 :          32 :           rem = (prec % (2 * limb_prec));
    4845                 :          32 :           end = (prec - rem) / limb_prec;
    4846                 :          32 :           cnt = 2 + CEIL (rem, limb_prec);
    4847                 :          32 :           idx = idx_first = create_loop (size_zero_node, &idx_next);
    4848                 :             :         }
    4849                 :             : 
    4850                 :          58 :       if (ifn == IFN_CTZ || ifn == IFN_FFS)
    4851                 :             :         {
    4852                 :          37 :           gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    4853                 :          37 :           gsi_prev (&gsi);
    4854                 :          37 :           edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    4855                 :          37 :           edge_bb = e->src;
    4856                 :          37 :           if (kind == bitint_prec_large)
    4857                 :          32 :             m_gsi = gsi_end_bb (edge_bb);
    4858                 :          37 :           bqp = XALLOCAVEC (struct bq_details, cnt);
    4859                 :             :         }
    4860                 :             :       else
    4861                 :          21 :         m_after_stmt = stmt;
    4862                 :          58 :       if (kind != bitint_prec_large)
    4863                 :          32 :         m_upwards_2limb = end;
    4864                 :             : 
    4865                 :         214 :       for (unsigned i = 0; i < cnt; i++)
    4866                 :             :         {
    4867                 :         156 :           m_data_cnt = 0;
    4868                 :         156 :           if (kind == bitint_prec_large)
    4869                 :          80 :             idx = size_int (i);
    4870                 :          76 :           else if (i >= 2)
    4871                 :          12 :             idx = size_int (end + (i > 2));
    4872                 :             : 
    4873                 :         156 :           tree rhs1 = handle_operand (arg0, idx);
    4874                 :         156 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1)))
    4875                 :             :             {
    4876                 :          26 :               if (!TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    4877                 :           4 :                 rhs1 = add_cast (unsigned_type_for (TREE_TYPE (rhs1)), rhs1);
    4878                 :          26 :               rhs1 = add_cast (m_limb_type, rhs1);
    4879                 :             :             }
    4880                 :             : 
    4881                 :         156 :           tree in, out, tem;
    4882                 :         156 :           if (ifn == IFN_PARITY)
    4883                 :          30 :             in = prepare_data_in_out (build_zero_cst (m_limb_type), idx, &out);
    4884                 :         126 :           else if (ifn == IFN_FFS)
    4885                 :          26 :             in = prepare_data_in_out (integer_one_node, idx, &out);
    4886                 :             :           else
    4887                 :         100 :             in = prepare_data_in_out (integer_zero_node, idx, &out);
    4888                 :             : 
    4889                 :         156 :           switch (ifn)
    4890                 :             :             {
    4891                 :          98 :             case IFN_CTZ:
    4892                 :          98 :             case IFN_FFS:
    4893                 :          98 :               g = gimple_build_cond (NE_EXPR, rhs1,
    4894                 :             :                                      build_zero_cst (m_limb_type),
    4895                 :             :                                      NULL_TREE, NULL_TREE);
    4896                 :          98 :               insert_before (g);
    4897                 :          98 :               edge e1, e2;
    4898                 :          98 :               e1 = split_block (gsi_bb (m_gsi), g);
    4899                 :          98 :               e1->flags = EDGE_FALSE_VALUE;
    4900                 :          98 :               e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE);
    4901                 :          98 :               e1->probability = profile_probability::unlikely ();
    4902                 :          98 :               e2->probability = e1->probability.invert ();
    4903                 :          98 :               if (i == 0)
    4904                 :          37 :                 set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    4905                 :          98 :               m_gsi = gsi_after_labels (e1->dest);
    4906                 :          98 :               bqp[i].e = e2;
    4907                 :          98 :               bqp[i].val = rhs1;
    4908                 :          98 :               if (tree_fits_uhwi_p (idx))
    4909                 :          56 :                 bqp[i].addend
    4910                 :          56 :                   = build_int_cst (integer_type_node,
    4911                 :          56 :                                    tree_to_uhwi (idx) * limb_prec
    4912                 :          56 :                                    + (ifn == IFN_FFS));
    4913                 :             :               else
    4914                 :             :                 {
    4915                 :          42 :                   bqp[i].addend = in;
    4916                 :          42 :                   if (i == 1)
    4917                 :          21 :                     res = out;
    4918                 :             :                   else
    4919                 :          21 :                     res = make_ssa_name (integer_type_node);
    4920                 :          42 :                   g = gimple_build_assign (res, PLUS_EXPR, in,
    4921                 :             :                                            build_int_cst (integer_type_node,
    4922                 :             :                                                           limb_prec));
    4923                 :          42 :                   insert_before (g);
    4924                 :          42 :                   m_data[m_data_cnt] = res;
    4925                 :             :                 }
    4926                 :             :               break;
    4927                 :          30 :             case IFN_PARITY:
    4928                 :          30 :               if (!integer_zerop (in))
    4929                 :             :                 {
    4930                 :          25 :                   if (kind == bitint_prec_huge && i == 1)
    4931                 :           6 :                     res = out;
    4932                 :             :                   else
    4933                 :          19 :                     res = make_ssa_name (m_limb_type);
    4934                 :          25 :                   g = gimple_build_assign (res, BIT_XOR_EXPR, in, rhs1);
    4935                 :          25 :                   insert_before (g);
    4936                 :             :                 }
    4937                 :             :               else
    4938                 :             :                 res = rhs1;
    4939                 :          30 :               m_data[m_data_cnt] = res;
    4940                 :          30 :               break;
    4941                 :          28 :             case IFN_POPCOUNT:
    4942                 :          28 :               g = gimple_build_call (fndecl, 1, rhs1);
    4943                 :          28 :               tem = make_ssa_name (integer_type_node);
    4944                 :          28 :               gimple_call_set_lhs (g, tem);
    4945                 :          28 :               insert_before (g);
    4946                 :          28 :               if (!integer_zerop (in))
    4947                 :             :                 {
    4948                 :          23 :                   if (kind == bitint_prec_huge && i == 1)
    4949                 :           5 :                     res = out;
    4950                 :             :                   else
    4951                 :          18 :                     res = make_ssa_name (integer_type_node);
    4952                 :          23 :                   g = gimple_build_assign (res, PLUS_EXPR, in, tem);
    4953                 :          23 :                   insert_before (g);
    4954                 :             :                 }
    4955                 :             :               else
    4956                 :             :                 res = tem;
    4957                 :          28 :               m_data[m_data_cnt] = res;
    4958                 :          28 :               break;
    4959                 :           0 :             default:
    4960                 :           0 :               gcc_unreachable ();
    4961                 :             :             }
    4962                 :             : 
    4963                 :         156 :           m_first = false;
    4964                 :         156 :           if (kind == bitint_prec_huge && i <= 1)
    4965                 :             :             {
    4966                 :          64 :               if (i == 0)
    4967                 :             :                 {
    4968                 :          32 :                   idx = make_ssa_name (sizetype);
    4969                 :          32 :                   g = gimple_build_assign (idx, PLUS_EXPR, idx_first,
    4970                 :             :                                            size_one_node);
    4971                 :          32 :                   insert_before (g);
    4972                 :             :                 }
    4973                 :             :               else
    4974                 :             :                 {
    4975                 :          32 :                   g = gimple_build_assign (idx_next, PLUS_EXPR, idx_first,
    4976                 :          32 :                                            size_int (2));
    4977                 :          32 :                   insert_before (g);
    4978                 :          32 :                   g = gimple_build_cond (NE_EXPR, idx_next, size_int (end),
    4979                 :             :                                          NULL_TREE, NULL_TREE);
    4980                 :          32 :                   insert_before (g);
    4981                 :          32 :                   if (ifn == IFN_CTZ || ifn == IFN_FFS)
    4982                 :          21 :                     m_gsi = gsi_after_labels (edge_bb);
    4983                 :             :                   else
    4984                 :          11 :                     m_gsi = gsi_for_stmt (stmt);
    4985                 :          32 :                   m_bb = NULL;
    4986                 :             :                 }
    4987                 :             :             }
    4988                 :             :         }
    4989                 :             :     }
    4990                 :             :   else
    4991                 :             :     {
    4992                 :          32 :       tree idx = NULL_TREE, idx_next = NULL_TREE, first = NULL_TREE;
    4993                 :          32 :       int sub_one = 0;
    4994                 :          32 :       if (kind == bitint_prec_large)
    4995                 :          16 :         cnt = CEIL (prec, limb_prec);
    4996                 :             :       else
    4997                 :             :         {
    4998                 :          16 :           rem = prec % limb_prec;
    4999                 :          16 :           if (rem == 0 && (!TYPE_UNSIGNED (type) || ifn == IFN_CLRSB))
    5000                 :             :             rem = limb_prec;
    5001                 :          16 :           end = (prec - rem) / limb_prec;
    5002                 :          16 :           cnt = 1 + (rem != 0);
    5003                 :          16 :           if (ifn == IFN_CLRSB)
    5004                 :           4 :             sub_one = 1;
    5005                 :             :         }
    5006                 :             : 
    5007                 :          32 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    5008                 :          32 :       gsi_prev (&gsi);
    5009                 :          32 :       edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    5010                 :          32 :       edge_bb = e->src;
    5011                 :          32 :       m_gsi = gsi_end_bb (edge_bb);
    5012                 :             : 
    5013                 :          32 :       if (ifn == IFN_CLZ)
    5014                 :          24 :         bqp = XALLOCAVEC (struct bq_details, cnt);
    5015                 :             :       else
    5016                 :             :         {
    5017                 :           8 :           gsi = gsi_for_stmt (stmt);
    5018                 :           8 :           gsi_prev (&gsi);
    5019                 :           8 :           e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    5020                 :           8 :           edge_bb = e->src;
    5021                 :           8 :           bqp = XALLOCAVEC (struct bq_details, 2 * cnt);
    5022                 :             :         }
    5023                 :             : 
    5024                 :         106 :       for (unsigned i = 0; i < cnt; i++)
    5025                 :             :         {
    5026                 :          74 :           m_data_cnt = 0;
    5027                 :          74 :           if (kind == bitint_prec_large)
    5028                 :          48 :             idx = size_int (cnt - i - 1);
    5029                 :          26 :           else if (i == cnt - 1)
    5030                 :          16 :             idx = create_loop (size_int (end - 1), &idx_next);
    5031                 :             :           else
    5032                 :          10 :             idx = size_int (end);
    5033                 :             : 
    5034                 :          74 :           tree rhs1 = handle_operand (arg0, idx);
    5035                 :          74 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1)))
    5036                 :             :             {
    5037                 :          16 :               if (ifn == IFN_CLZ && !TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    5038                 :           0 :                 rhs1 = add_cast (unsigned_type_for (TREE_TYPE (rhs1)), rhs1);
    5039                 :          16 :               else if (ifn == IFN_CLRSB && TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    5040                 :           0 :                 rhs1 = add_cast (signed_type_for (TREE_TYPE (rhs1)), rhs1);
    5041                 :          16 :               rhs1 = add_cast (m_limb_type, rhs1);
    5042                 :             :             }
    5043                 :             : 
    5044                 :          74 :           if (ifn == IFN_CLZ)
    5045                 :             :             {
    5046                 :          54 :               g = gimple_build_cond (NE_EXPR, rhs1,
    5047                 :             :                                      build_zero_cst (m_limb_type),
    5048                 :             :                                      NULL_TREE, NULL_TREE);
    5049                 :          54 :               insert_before (g);
    5050                 :          54 :               edge e1 = split_block (gsi_bb (m_gsi), g);
    5051                 :          54 :               e1->flags = EDGE_FALSE_VALUE;
    5052                 :          54 :               edge e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE);
    5053                 :          54 :               e1->probability = profile_probability::unlikely ();
    5054                 :          54 :               e2->probability = e1->probability.invert ();
    5055                 :          54 :               if (i == 0)
    5056                 :          24 :                 set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    5057                 :          54 :               m_gsi = gsi_after_labels (e1->dest);
    5058                 :          54 :               bqp[i].e = e2;
    5059                 :          54 :               bqp[i].val = rhs1;
    5060                 :             :             }
    5061                 :             :           else
    5062                 :             :             {
    5063                 :          20 :               if (i == 0)
    5064                 :             :                 {
    5065                 :           8 :                   first = rhs1;
    5066                 :           8 :                   g = gimple_build_assign (make_ssa_name (m_limb_type),
    5067                 :             :                                            PLUS_EXPR, rhs1,
    5068                 :           8 :                                            build_int_cst (m_limb_type, 1));
    5069                 :           8 :                   insert_before (g);
    5070                 :           8 :                   g = gimple_build_cond (GT_EXPR, gimple_assign_lhs (g),
    5071                 :           8 :                                          build_int_cst (m_limb_type, 1),
    5072                 :             :                                          NULL_TREE, NULL_TREE);
    5073                 :           8 :                   insert_before (g);
    5074                 :             :                 }
    5075                 :             :               else
    5076                 :             :                 {
    5077                 :          12 :                   g = gimple_build_assign (make_ssa_name (m_limb_type),
    5078                 :             :                                            BIT_XOR_EXPR, rhs1, first);
    5079                 :          12 :                   insert_before (g);
    5080                 :          12 :                   tree stype = signed_type_for (m_limb_type);
    5081                 :          12 :                   g = gimple_build_cond (LT_EXPR,
    5082                 :             :                                          add_cast (stype,
    5083                 :             :                                                    gimple_assign_lhs (g)),
    5084                 :             :                                          build_zero_cst (stype),
    5085                 :             :                                          NULL_TREE, NULL_TREE);
    5086                 :          12 :                   insert_before (g);
    5087                 :          12 :                   edge e1 = split_block (gsi_bb (m_gsi), g);
    5088                 :          12 :                   e1->flags = EDGE_FALSE_VALUE;
    5089                 :          12 :                   edge e2 = make_edge (e1->src, gimple_bb (stmt),
    5090                 :             :                                        EDGE_TRUE_VALUE);
    5091                 :          12 :                   e1->probability = profile_probability::unlikely ();
    5092                 :          12 :                   e2->probability = e1->probability.invert ();
    5093                 :          12 :                   if (i == 1)
    5094                 :           8 :                     set_immediate_dominator (CDI_DOMINATORS, e2->dest,
    5095                 :             :                                              e2->src);
    5096                 :          12 :                   m_gsi = gsi_after_labels (e1->dest);
    5097                 :          12 :                   bqp[2 * i].e = e2;
    5098                 :          12 :                   g = gimple_build_cond (NE_EXPR, rhs1, first,
    5099                 :             :                                          NULL_TREE, NULL_TREE);
    5100                 :          12 :                   insert_before (g);
    5101                 :             :                 }
    5102                 :          20 :               edge e1 = split_block (gsi_bb (m_gsi), g);
    5103                 :          20 :               e1->flags = EDGE_FALSE_VALUE;
    5104                 :          20 :               edge e2 = make_edge (e1->src, edge_bb, EDGE_TRUE_VALUE);
    5105                 :          20 :               e1->probability = profile_probability::unlikely ();
    5106                 :          20 :               e2->probability = e1->probability.invert ();
    5107                 :          20 :               if (i == 0)
    5108                 :           8 :                 set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    5109                 :          20 :               m_gsi = gsi_after_labels (e1->dest);
    5110                 :          20 :               bqp[2 * i + 1].e = e2;
    5111                 :          20 :               bqp[i].val = rhs1;
    5112                 :             :             }
    5113                 :          74 :           if (tree_fits_uhwi_p (idx))
    5114                 :          58 :             bqp[i].addend
    5115                 :          58 :               = build_int_cst (integer_type_node,
    5116                 :          58 :                                (int) prec
    5117                 :          58 :                                - (((int) tree_to_uhwi (idx) + 1)
    5118                 :          58 :                                   * limb_prec) - sub_one);
    5119                 :             :           else
    5120                 :             :             {
    5121                 :          16 :               tree in, out;
    5122                 :          16 :               in = build_int_cst (integer_type_node, rem - sub_one);
    5123                 :          16 :               m_first = true;
    5124                 :          16 :               in = prepare_data_in_out (in, idx, &out);
    5125                 :          16 :               out = m_data[m_data_cnt + 1];
    5126                 :          16 :               bqp[i].addend = in;
    5127                 :          16 :               g = gimple_build_assign (out, PLUS_EXPR, in,
    5128                 :             :                                        build_int_cst (integer_type_node,
    5129                 :             :                                                       limb_prec));
    5130                 :          16 :               insert_before (g);
    5131                 :          16 :               m_data[m_data_cnt] = out;
    5132                 :             :             }
    5133                 :             : 
    5134                 :          74 :           m_first = false;
    5135                 :          74 :           if (kind == bitint_prec_huge && i == cnt - 1)
    5136                 :             :             {
    5137                 :          16 :               g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    5138                 :          16 :                                        size_int (-1));
    5139                 :          16 :               insert_before (g);
    5140                 :          16 :               g = gimple_build_cond (NE_EXPR, idx, size_zero_node,
    5141                 :             :                                      NULL_TREE, NULL_TREE);
    5142                 :          16 :               insert_before (g);
    5143                 :          16 :               edge true_edge, false_edge;
    5144                 :          16 :               extract_true_false_edges_from_block (gsi_bb (m_gsi),
    5145                 :             :                                                    &true_edge, &false_edge);
    5146                 :          16 :               m_gsi = gsi_after_labels (false_edge->dest);
    5147                 :          16 :               m_bb = NULL;
    5148                 :             :             }
    5149                 :             :         }
    5150                 :             :     }
    5151                 :          90 :   switch (ifn)
    5152                 :             :     {
    5153                 :          61 :     case IFN_CLZ:
    5154                 :          61 :     case IFN_CTZ:
    5155                 :          61 :     case IFN_FFS:
    5156                 :          61 :       gphi *phi1, *phi2, *phi3;
    5157                 :          61 :       basic_block bb;
    5158                 :          61 :       bb = gsi_bb (m_gsi);
    5159                 :          61 :       remove_edge (find_edge (bb, gimple_bb (stmt)));
    5160                 :          61 :       phi1 = create_phi_node (make_ssa_name (m_limb_type),
    5161                 :             :                               gimple_bb (stmt));
    5162                 :          61 :       phi2 = create_phi_node (make_ssa_name (integer_type_node),
    5163                 :             :                               gimple_bb (stmt));
    5164                 :         213 :       for (unsigned i = 0; i < cnt; i++)
    5165                 :             :         {
    5166                 :         152 :           add_phi_arg (phi1, bqp[i].val, bqp[i].e, UNKNOWN_LOCATION);
    5167                 :         152 :           add_phi_arg (phi2, bqp[i].addend, bqp[i].e, UNKNOWN_LOCATION);
    5168                 :             :         }
    5169                 :          61 :       if (arg1 == NULL_TREE)
    5170                 :             :         {
    5171                 :          35 :           g = gimple_build_builtin_unreachable (m_loc);
    5172                 :          35 :           insert_before (g);
    5173                 :             :         }
    5174                 :          61 :       m_gsi = gsi_for_stmt (stmt);
    5175                 :          61 :       g = gimple_build_call (fndecl, 1, gimple_phi_result (phi1));
    5176                 :          61 :       gimple_call_set_lhs (g, make_ssa_name (integer_type_node));
    5177                 :          61 :       insert_before (g);
    5178                 :          61 :       if (arg1 == NULL_TREE)
    5179                 :          35 :         g = gimple_build_assign (lhs, PLUS_EXPR,
    5180                 :             :                                  gimple_phi_result (phi2),
    5181                 :             :                                  gimple_call_lhs (g));
    5182                 :             :       else
    5183                 :             :         {
    5184                 :          26 :           g = gimple_build_assign (make_ssa_name (integer_type_node),
    5185                 :             :                                    PLUS_EXPR, gimple_phi_result (phi2),
    5186                 :             :                                    gimple_call_lhs (g));
    5187                 :          26 :           insert_before (g);
    5188                 :          26 :           edge e1 = split_block (gimple_bb (stmt), g);
    5189                 :          26 :           edge e2 = make_edge (bb, e1->dest, EDGE_FALLTHRU);
    5190                 :          26 :           e2->probability = profile_probability::always ();
    5191                 :          26 :           set_immediate_dominator (CDI_DOMINATORS, e1->dest,
    5192                 :             :                                    get_immediate_dominator (CDI_DOMINATORS,
    5193                 :             :                                                             e1->src));
    5194                 :          26 :           phi3 = create_phi_node (make_ssa_name (integer_type_node), e1->dest);
    5195                 :          26 :           add_phi_arg (phi3, gimple_assign_lhs (g), e1, UNKNOWN_LOCATION);
    5196                 :          26 :           add_phi_arg (phi3, arg1, e2, UNKNOWN_LOCATION);
    5197                 :          26 :           m_gsi = gsi_for_stmt (stmt);
    5198                 :          26 :           g = gimple_build_assign (lhs, gimple_phi_result (phi3));
    5199                 :             :         }
    5200                 :          61 :       gsi_replace (&m_gsi, g, true);
    5201                 :          61 :       break;
    5202                 :           8 :     case IFN_CLRSB:
    5203                 :           8 :       bb = gsi_bb (m_gsi);
    5204                 :           8 :       remove_edge (find_edge (bb, edge_bb));
    5205                 :           8 :       edge e;
    5206                 :           8 :       e = make_edge (bb, gimple_bb (stmt), EDGE_FALLTHRU);
    5207                 :           8 :       e->probability = profile_probability::always ();
    5208                 :           8 :       set_immediate_dominator (CDI_DOMINATORS, gimple_bb (stmt),
    5209                 :             :                                get_immediate_dominator (CDI_DOMINATORS,
    5210                 :             :                                                         edge_bb));
    5211                 :           8 :       phi1 = create_phi_node (make_ssa_name (m_limb_type),
    5212                 :             :                               edge_bb);
    5213                 :           8 :       phi2 = create_phi_node (make_ssa_name (integer_type_node),
    5214                 :             :                               edge_bb);
    5215                 :           8 :       phi3 = create_phi_node (make_ssa_name (integer_type_node),
    5216                 :             :                               gimple_bb (stmt));
    5217                 :          28 :       for (unsigned i = 0; i < cnt; i++)
    5218                 :             :         {
    5219                 :          20 :           add_phi_arg (phi1, bqp[i].val, bqp[2 * i + 1].e, UNKNOWN_LOCATION);
    5220                 :          20 :           add_phi_arg (phi2, bqp[i].addend, bqp[2 * i + 1].e,
    5221                 :             :                        UNKNOWN_LOCATION);
    5222                 :          20 :           tree a = bqp[i].addend;
    5223                 :          20 :           if (i && kind == bitint_prec_large)
    5224                 :           8 :             a = int_const_binop (PLUS_EXPR, a, integer_minus_one_node);
    5225                 :          20 :           if (i)
    5226                 :          12 :             add_phi_arg (phi3, a, bqp[2 * i].e, UNKNOWN_LOCATION);
    5227                 :             :         }
    5228                 :           8 :       add_phi_arg (phi3, build_int_cst (integer_type_node, prec - 1), e,
    5229                 :             :                    UNKNOWN_LOCATION);
    5230                 :           8 :       m_gsi = gsi_after_labels (edge_bb);
    5231                 :           8 :       g = gimple_build_call (fndecl, 1,
    5232                 :             :                              add_cast (signed_type_for (m_limb_type),
    5233                 :             :                                        gimple_phi_result (phi1)));
    5234                 :           8 :       gimple_call_set_lhs (g, make_ssa_name (integer_type_node));
    5235                 :           8 :       insert_before (g);
    5236                 :           8 :       g = gimple_build_assign (make_ssa_name (integer_type_node),
    5237                 :             :                                PLUS_EXPR, gimple_call_lhs (g),
    5238                 :             :                                gimple_phi_result (phi2));
    5239                 :           8 :       insert_before (g);
    5240                 :           8 :       if (kind != bitint_prec_large)
    5241                 :             :         {
    5242                 :           4 :           g = gimple_build_assign (make_ssa_name (integer_type_node),
    5243                 :             :                                    PLUS_EXPR, gimple_assign_lhs (g),
    5244                 :             :                                    integer_one_node);
    5245                 :           4 :           insert_before (g);
    5246                 :             :         }
    5247                 :           8 :       add_phi_arg (phi3, gimple_assign_lhs (g),
    5248                 :             :                    find_edge (edge_bb, gimple_bb (stmt)), UNKNOWN_LOCATION);
    5249                 :           8 :       m_gsi = gsi_for_stmt (stmt);
    5250                 :           8 :       g = gimple_build_assign (lhs, gimple_phi_result (phi3));
    5251                 :           8 :       gsi_replace (&m_gsi, g, true);
    5252                 :           8 :       break;
    5253                 :          11 :     case IFN_PARITY:
    5254                 :          11 :       g = gimple_build_call (fndecl, 1, res);
    5255                 :          11 :       gimple_call_set_lhs (g, lhs);
    5256                 :          11 :       gsi_replace (&m_gsi, g, true);
    5257                 :          11 :       break;
    5258                 :          10 :     case IFN_POPCOUNT:
    5259                 :          10 :       g = gimple_build_assign (lhs, res);
    5260                 :          10 :       gsi_replace (&m_gsi, g, true);
    5261                 :          10 :       break;
    5262                 :           0 :     default:
    5263                 :           0 :       gcc_unreachable ();
    5264                 :             :     }
    5265                 :             : }
    5266                 :             : 
    5267                 :             : /* Lower a call statement with one or more large/huge _BitInt
    5268                 :             :    arguments or large/huge _BitInt return value.  */
    5269                 :             : 
    5270                 :             : void
    5271                 :        8547 : bitint_large_huge::lower_call (tree obj, gimple *stmt)
    5272                 :             : {
    5273                 :        8547 :   gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    5274                 :        8547 :   unsigned int nargs = gimple_call_num_args (stmt);
    5275                 :        8547 :   if (gimple_call_internal_p (stmt))
    5276                 :        4118 :     switch (gimple_call_internal_fn (stmt))
    5277                 :             :       {
    5278                 :        2641 :       case IFN_ADD_OVERFLOW:
    5279                 :        2641 :       case IFN_SUB_OVERFLOW:
    5280                 :        2641 :       case IFN_UBSAN_CHECK_ADD:
    5281                 :        2641 :       case IFN_UBSAN_CHECK_SUB:
    5282                 :        2641 :         lower_addsub_overflow (obj, stmt);
    5283                 :        6759 :         return;
    5284                 :        1387 :       case IFN_MUL_OVERFLOW:
    5285                 :        1387 :       case IFN_UBSAN_CHECK_MUL:
    5286                 :        1387 :         lower_mul_overflow (obj, stmt);
    5287                 :        1387 :         return;
    5288                 :          90 :       case IFN_CLZ:
    5289                 :          90 :       case IFN_CTZ:
    5290                 :          90 :       case IFN_CLRSB:
    5291                 :          90 :       case IFN_FFS:
    5292                 :          90 :       case IFN_PARITY:
    5293                 :          90 :       case IFN_POPCOUNT:
    5294                 :          90 :         lower_bit_query (stmt);
    5295                 :          90 :         return;
    5296                 :             :       default:
    5297                 :             :         break;
    5298                 :             :       }
    5299                 :        4429 :   bool returns_twice = (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0;
    5300                 :        9953 :   for (unsigned int i = 0; i < nargs; ++i)
    5301                 :             :     {
    5302                 :        5524 :       tree arg = gimple_call_arg (stmt, i);
    5303                 :        8720 :       if (TREE_CODE (arg) != SSA_NAME
    5304                 :        2425 :           || TREE_CODE (TREE_TYPE (arg)) != BITINT_TYPE
    5305                 :        7887 :           || bitint_precision_kind (TREE_TYPE (arg)) <= bitint_prec_middle)
    5306                 :        3196 :         continue;
    5307                 :        2328 :       if (SSA_NAME_IS_DEFAULT_DEF (arg)
    5308                 :        2328 :           && (!SSA_NAME_VAR (arg) || VAR_P (SSA_NAME_VAR (arg))))
    5309                 :             :         {
    5310                 :           1 :           tree var = create_tmp_reg (TREE_TYPE (arg));
    5311                 :           1 :           arg = get_or_create_ssa_default_def (cfun, var);
    5312                 :             :         }
    5313                 :             :       else
    5314                 :             :         {
    5315                 :        2327 :           int p = var_to_partition (m_map, arg);
    5316                 :        2327 :           tree v = m_vars[p];
    5317                 :        2327 :           gcc_assert (v != NULL_TREE);
    5318                 :        2327 :           if (!types_compatible_p (TREE_TYPE (arg), TREE_TYPE (v)))
    5319                 :        2307 :             v = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (arg), v);
    5320                 :        2327 :           arg = make_ssa_name (TREE_TYPE (arg));
    5321                 :        2327 :           gimple *g = gimple_build_assign (arg, v);
    5322                 :        2327 :           gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    5323                 :        2327 :           if (returns_twice && bb_has_abnormal_pred (gimple_bb (stmt)))
    5324                 :             :             {
    5325                 :          11 :               m_returns_twice_calls.safe_push (stmt);
    5326                 :          11 :               returns_twice = false;
    5327                 :             :             }
    5328                 :             :         }
    5329                 :        2328 :       gimple_call_set_arg (stmt, i, arg);
    5330                 :        2328 :       if (m_preserved == NULL)
    5331                 :         399 :         m_preserved = BITMAP_ALLOC (NULL);
    5332                 :        2328 :       bitmap_set_bit (m_preserved, SSA_NAME_VERSION (arg));
    5333                 :             :     }
    5334                 :        4429 :   tree lhs = gimple_call_lhs (stmt);
    5335                 :        4429 :   if (lhs
    5336                 :        4304 :       && TREE_CODE (lhs) == SSA_NAME
    5337                 :        4304 :       && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
    5338                 :        8663 :       && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large)
    5339                 :             :     {
    5340                 :        4208 :       int p = var_to_partition (m_map, lhs);
    5341                 :        4208 :       tree v = m_vars[p];
    5342                 :        4208 :       gcc_assert (v != NULL_TREE);
    5343                 :        4208 :       if (!types_compatible_p (TREE_TYPE (lhs), TREE_TYPE (v)))
    5344                 :        4208 :         v = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), v);
    5345                 :        4208 :       gimple_call_set_lhs (stmt, v);
    5346                 :        4208 :       SSA_NAME_DEF_STMT (lhs) = gimple_build_nop ();
    5347                 :             :     }
    5348                 :        4429 :   update_stmt (stmt);
    5349                 :             : }
    5350                 :             : 
    5351                 :             : /* Lower __asm STMT which involves large/huge _BitInt values.  */
    5352                 :             : 
    5353                 :             : void
    5354                 :           3 : bitint_large_huge::lower_asm (gimple *stmt)
    5355                 :             : {
    5356                 :           3 :   gasm *g = as_a <gasm *> (stmt);
    5357                 :           3 :   unsigned noutputs = gimple_asm_noutputs (g);
    5358                 :           3 :   unsigned ninputs = gimple_asm_ninputs (g);
    5359                 :             : 
    5360                 :           5 :   for (unsigned i = 0; i < noutputs; ++i)
    5361                 :             :     {
    5362                 :           2 :       tree t = gimple_asm_output_op (g, i);
    5363                 :           2 :       tree s = TREE_VALUE (t);
    5364                 :           2 :       if (TREE_CODE (s) == SSA_NAME
    5365                 :           1 :           && TREE_CODE (TREE_TYPE (s)) == BITINT_TYPE
    5366                 :           3 :           && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large)
    5367                 :             :         {
    5368                 :           1 :           int part = var_to_partition (m_map, s);
    5369                 :           1 :           gcc_assert (m_vars[part] != NULL_TREE);
    5370                 :           1 :           TREE_VALUE (t) = m_vars[part];
    5371                 :             :         }
    5372                 :             :     }
    5373                 :           8 :   for (unsigned i = 0; i < ninputs; ++i)
    5374                 :             :     {
    5375                 :           5 :       tree t = gimple_asm_input_op (g, i);
    5376                 :           5 :       tree s = TREE_VALUE (t);
    5377                 :           5 :       if (TREE_CODE (s) == SSA_NAME
    5378                 :           4 :           && TREE_CODE (TREE_TYPE (s)) == BITINT_TYPE
    5379                 :           9 :           && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large)
    5380                 :             :         {
    5381                 :           4 :           if (SSA_NAME_IS_DEFAULT_DEF (s)
    5382                 :           4 :               && (!SSA_NAME_VAR (s) || VAR_P (SSA_NAME_VAR (s))))
    5383                 :             :             {
    5384                 :           1 :               TREE_VALUE (t) = create_tmp_var (TREE_TYPE (s), "bitint");
    5385                 :           1 :               mark_addressable (TREE_VALUE (t));
    5386                 :             :             }
    5387                 :             :           else
    5388                 :             :             {
    5389                 :           3 :               int part = var_to_partition (m_map, s);
    5390                 :           3 :               gcc_assert (m_vars[part] != NULL_TREE);
    5391                 :           3 :               TREE_VALUE (t) = m_vars[part];
    5392                 :             :             }
    5393                 :             :         }
    5394                 :             :     }
    5395                 :           3 :   update_stmt (stmt);
    5396                 :           3 : }
    5397                 :             : 
    5398                 :             : /* Lower statement STMT which involves large/huge _BitInt values
    5399                 :             :    into code accessing individual limbs.  */
    5400                 :             : 
    5401                 :             : void
    5402                 :       40948 : bitint_large_huge::lower_stmt (gimple *stmt)
    5403                 :             : {
    5404                 :       40948 :   m_first = true;
    5405                 :       40948 :   m_lhs = NULL_TREE;
    5406                 :       40948 :   m_data.truncate (0);
    5407                 :       40948 :   m_data_cnt = 0;
    5408                 :       40948 :   m_gsi = gsi_for_stmt (stmt);
    5409                 :       40948 :   m_after_stmt = NULL;
    5410                 :       40948 :   m_bb = NULL;
    5411                 :       40948 :   m_init_gsi = m_gsi;
    5412                 :       40948 :   gsi_prev (&m_init_gsi);
    5413                 :       40948 :   m_preheader_bb = NULL;
    5414                 :       40948 :   m_upwards_2limb = 0;
    5415                 :       40948 :   m_upwards = false;
    5416                 :       40948 :   m_var_msb = false;
    5417                 :       40948 :   m_cast_conditional = false;
    5418                 :       40948 :   m_bitfld_load = 0;
    5419                 :       40948 :   m_loc = gimple_location (stmt);
    5420                 :       40948 :   if (is_gimple_call (stmt))
    5421                 :             :     {
    5422                 :        6898 :       lower_call (NULL_TREE, stmt);
    5423                 :        6898 :       return;
    5424                 :             :     }
    5425                 :       34050 :   if (gimple_code (stmt) == GIMPLE_ASM)
    5426                 :             :     {
    5427                 :           3 :       lower_asm (stmt);
    5428                 :           3 :       return;
    5429                 :             :     }
    5430                 :       34047 :   tree lhs = NULL_TREE, cmp_op1 = NULL_TREE, cmp_op2 = NULL_TREE;
    5431                 :       34047 :   tree_code cmp_code = comparison_op (stmt, &cmp_op1, &cmp_op2);
    5432                 :       34047 :   bool eq_p = (cmp_code == EQ_EXPR || cmp_code == NE_EXPR);
    5433                 :       34047 :   bool mergeable_cast_p = false;
    5434                 :       34047 :   bool final_cast_p = false;
    5435                 :       34047 :   if (gimple_assign_cast_p (stmt))
    5436                 :             :     {
    5437                 :        5178 :       lhs = gimple_assign_lhs (stmt);
    5438                 :        5178 :       tree rhs1 = gimple_assign_rhs1 (stmt);
    5439                 :        5178 :       if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR)
    5440                 :          43 :         rhs1 = TREE_OPERAND (rhs1, 0);
    5441                 :        5178 :       if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
    5442                 :        1114 :           && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large
    5443                 :        6267 :           && INTEGRAL_TYPE_P (TREE_TYPE (rhs1)))
    5444                 :             :         mergeable_cast_p = true;
    5445                 :        4220 :       else if (TREE_CODE (TREE_TYPE (rhs1)) == BITINT_TYPE
    5446                 :        4089 :                && bitint_precision_kind (TREE_TYPE (rhs1)) >= bitint_prec_large
    5447                 :        8309 :                && (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    5448                 :          37 :                    || POINTER_TYPE_P (TREE_TYPE (lhs))
    5449                 :          35 :                    || gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR))
    5450                 :             :         {
    5451                 :        4089 :           final_cast_p = true;
    5452                 :        4089 :           if (((TREE_CODE (TREE_TYPE (lhs)) == INTEGER_TYPE
    5453                 :         456 :                 && TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE)
    5454                 :        4089 :                || (!INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    5455                 :          37 :                    && !POINTER_TYPE_P (TREE_TYPE (lhs))))
    5456                 :        4124 :               && gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR)
    5457                 :             :             {
    5458                 :             :               /* Handle VIEW_CONVERT_EXPRs to not generally supported
    5459                 :             :                  huge INTEGER_TYPEs like uint256_t or uint512_t.  These
    5460                 :             :                  are usually emitted from memcpy folding and backends
    5461                 :             :                  support moves with them but that is usually it.
    5462                 :             :                  Similarly handle VCEs to vector/complex types etc.  */
    5463                 :          35 :               gcc_assert (TREE_CODE (rhs1) == SSA_NAME);
    5464                 :          35 :               if (SSA_NAME_IS_DEFAULT_DEF (rhs1)
    5465                 :          35 :                   && (!SSA_NAME_VAR (rhs1) || VAR_P (SSA_NAME_VAR (rhs1))))
    5466                 :             :                 {
    5467                 :           0 :                   tree var = create_tmp_reg (TREE_TYPE (lhs));
    5468                 :           0 :                   rhs1 = get_or_create_ssa_default_def (cfun, var);
    5469                 :           0 :                   gimple_assign_set_rhs1 (stmt, rhs1);
    5470                 :           0 :                   gimple_assign_set_rhs_code (stmt, SSA_NAME);
    5471                 :             :                 }
    5472                 :          35 :               else if (m_names == NULL
    5473                 :          35 :                        || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1)))
    5474                 :             :                 {
    5475                 :           0 :                   gimple *g = SSA_NAME_DEF_STMT (rhs1);
    5476                 :           0 :                   gcc_assert (gimple_assign_load_p (g));
    5477                 :           0 :                   tree mem = gimple_assign_rhs1 (g);
    5478                 :           0 :                   tree ltype = TREE_TYPE (lhs);
    5479                 :           0 :                   addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (mem));
    5480                 :           0 :                   if (as != TYPE_ADDR_SPACE (ltype))
    5481                 :           0 :                     ltype
    5482                 :           0 :                       = build_qualified_type (ltype,
    5483                 :           0 :                                               TYPE_QUALS (ltype)
    5484                 :           0 :                                               | ENCODE_QUAL_ADDR_SPACE (as));
    5485                 :           0 :                   rhs1 = build1 (VIEW_CONVERT_EXPR, ltype, unshare_expr (mem));
    5486                 :           0 :                   gimple_assign_set_rhs1 (stmt, rhs1);
    5487                 :             :                 }
    5488                 :             :               else
    5489                 :             :                 {
    5490                 :          35 :                   int part = var_to_partition (m_map, rhs1);
    5491                 :          35 :                   gcc_assert (m_vars[part] != NULL_TREE);
    5492                 :          35 :                   rhs1 = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs),
    5493                 :             :                                  m_vars[part]);
    5494                 :          35 :                   gimple_assign_set_rhs1 (stmt, rhs1);
    5495                 :             :                 }
    5496                 :          35 :               update_stmt (stmt);
    5497                 :          35 :               return;
    5498                 :             :             }
    5499                 :        4054 :           if (TREE_CODE (rhs1) == SSA_NAME
    5500                 :        4054 :               && (m_names == NULL
    5501                 :        4022 :                   || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1))))
    5502                 :             :             {
    5503                 :        1676 :               gimple *g = SSA_NAME_DEF_STMT (rhs1);
    5504                 :        1676 :               if (is_gimple_assign (g)
    5505                 :        1676 :                   && gimple_assign_rhs_code (g) == IMAGPART_EXPR)
    5506                 :             :                 {
    5507                 :        1625 :                   tree rhs2 = TREE_OPERAND (gimple_assign_rhs1 (g), 0);
    5508                 :        1625 :                   if (TREE_CODE (rhs2) == SSA_NAME
    5509                 :        1625 :                       && (m_names == NULL
    5510                 :        1593 :                           || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs2))))
    5511                 :             :                     {
    5512                 :        1625 :                       g = SSA_NAME_DEF_STMT (rhs2);
    5513                 :        1625 :                       int ovf = optimizable_arith_overflow (g);
    5514                 :        1625 :                       if (ovf == 2)
    5515                 :             :                         /* If .{ADD,SUB,MUL}_OVERFLOW has both REALPART_EXPR
    5516                 :             :                            and IMAGPART_EXPR uses, where the latter is cast to
    5517                 :             :                            non-_BitInt, it will be optimized when handling
    5518                 :             :                            the REALPART_EXPR.  */
    5519                 :             :                         return;
    5520                 :          86 :                       if (ovf == 1)
    5521                 :             :                         {
    5522                 :          86 :                           lower_call (NULL_TREE, g);
    5523                 :          86 :                           return;
    5524                 :             :                         }
    5525                 :             :                     }
    5526                 :             :                 }
    5527                 :             :             }
    5528                 :             :         }
    5529                 :         131 :       else if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
    5530                 :         131 :                && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large
    5531                 :         131 :                && !INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    5532                 :         131 :                && !POINTER_TYPE_P (TREE_TYPE (rhs1))
    5533                 :         262 :                && gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR)
    5534                 :             :         {
    5535                 :           7 :           int part = var_to_partition (m_map, lhs);
    5536                 :           7 :           gcc_assert (m_vars[part] != NULL_TREE);
    5537                 :           7 :           lhs = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (rhs1), m_vars[part]);
    5538                 :           7 :           insert_before (gimple_build_assign (lhs, rhs1));
    5539                 :           7 :           return;
    5540                 :             :         }
    5541                 :             :     }
    5542                 :       32380 :   if (gimple_store_p (stmt))
    5543                 :             :     {
    5544                 :        8518 :       tree rhs1 = gimple_assign_rhs1 (stmt);
    5545                 :        8518 :       if (TREE_CODE (rhs1) == SSA_NAME
    5546                 :        8518 :           && (m_names == NULL
    5547                 :        7513 :               || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1))))
    5548                 :             :         {
    5549                 :        1391 :           gimple *g = SSA_NAME_DEF_STMT (rhs1);
    5550                 :        1391 :           m_loc = gimple_location (g);
    5551                 :        1391 :           lhs = gimple_assign_lhs (stmt);
    5552                 :        1391 :           if (is_gimple_assign (g) && !mergeable_op (g))
    5553                 :         461 :             switch (gimple_assign_rhs_code (g))
    5554                 :             :               {
    5555                 :          98 :               case LSHIFT_EXPR:
    5556                 :          98 :               case RSHIFT_EXPR:
    5557                 :          98 :                 lower_shift_stmt (lhs, g);
    5558                 :         336 :               handled:
    5559                 :         336 :                 m_gsi = gsi_for_stmt (stmt);
    5560                 :         336 :                 unlink_stmt_vdef (stmt);
    5561                 :         672 :                 release_ssa_name (gimple_vdef (stmt));
    5562                 :         336 :                 gsi_remove (&m_gsi, true);
    5563                 :         336 :                 return;
    5564                 :         173 :               case MULT_EXPR:
    5565                 :         173 :               case TRUNC_DIV_EXPR:
    5566                 :         173 :               case TRUNC_MOD_EXPR:
    5567                 :         173 :                 lower_muldiv_stmt (lhs, g);
    5568                 :         173 :                 goto handled;
    5569                 :          39 :               case FIX_TRUNC_EXPR:
    5570                 :          39 :                 lower_float_conv_stmt (lhs, g);
    5571                 :          39 :                 goto handled;
    5572                 :           2 :               case REALPART_EXPR:
    5573                 :           2 :               case IMAGPART_EXPR:
    5574                 :           2 :                 lower_cplxpart_stmt (lhs, g);
    5575                 :           2 :                 goto handled;
    5576                 :           8 :               case VIEW_CONVERT_EXPR:
    5577                 :           8 :                 {
    5578                 :           8 :                   tree rhs1 = gimple_assign_rhs1 (g);
    5579                 :           8 :                   rhs1 = TREE_OPERAND (rhs1, 0);
    5580                 :           8 :                   if (!INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    5581                 :           7 :                       && !POINTER_TYPE_P (TREE_TYPE (rhs1)))
    5582                 :             :                     {
    5583                 :           7 :                       tree ltype = TREE_TYPE (rhs1);
    5584                 :           7 :                       addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (lhs));
    5585                 :           7 :                       ltype
    5586                 :          14 :                         = build_qualified_type (ltype,
    5587                 :           7 :                                                 TYPE_QUALS (TREE_TYPE (lhs))
    5588                 :           7 :                                                 | ENCODE_QUAL_ADDR_SPACE (as));
    5589                 :           7 :                       lhs = build1 (VIEW_CONVERT_EXPR, ltype, lhs);
    5590                 :           7 :                       gimple_assign_set_lhs (stmt, lhs);
    5591                 :           7 :                       gimple_assign_set_rhs1 (stmt, rhs1);
    5592                 :           7 :                       gimple_assign_set_rhs_code (stmt, TREE_CODE (rhs1));
    5593                 :           7 :                       update_stmt (stmt);
    5594                 :           7 :                       return;
    5595                 :             :                     }
    5596                 :             :                 }
    5597                 :             :                 break;
    5598                 :             :               default:
    5599                 :             :                 break;
    5600                 :             :               }
    5601                 :         930 :           else if (optimizable_arith_overflow (g) == 3)
    5602                 :             :             {
    5603                 :          24 :               lower_call (lhs, g);
    5604                 :          24 :               goto handled;
    5605                 :             :             }
    5606                 :        1048 :           m_loc = gimple_location (stmt);
    5607                 :             :         }
    5608                 :             :     }
    5609                 :       32037 :   if (mergeable_op (stmt)
    5610                 :       21077 :       || gimple_store_p (stmt)
    5611                 :       21077 :       || gimple_assign_load_p (stmt)
    5612                 :             :       || eq_p
    5613                 :       48447 :       || mergeable_cast_p)
    5614                 :             :     {
    5615                 :       22373 :       lhs = lower_mergeable_stmt (stmt, cmp_code, cmp_op1, cmp_op2);
    5616                 :       22373 :       if (!eq_p)
    5617                 :             :         return;
    5618                 :             :     }
    5619                 :        9664 :   else if (cmp_code != ERROR_MARK)
    5620                 :         712 :     lhs = lower_comparison_stmt (stmt, cmp_code, cmp_op1, cmp_op2);
    5621                 :       15904 :   if (cmp_code != ERROR_MARK)
    5622                 :             :     {
    5623                 :        6952 :       if (gimple_code (stmt) == GIMPLE_COND)
    5624                 :             :         {
    5625                 :        6186 :           gcond *cstmt = as_a <gcond *> (stmt);
    5626                 :        6186 :           gimple_cond_set_lhs (cstmt, lhs);
    5627                 :        6186 :           gimple_cond_set_rhs (cstmt, boolean_false_node);
    5628                 :        6186 :           gimple_cond_set_code (cstmt, cmp_code);
    5629                 :        6186 :           update_stmt (stmt);
    5630                 :        6186 :           return;
    5631                 :             :         }
    5632                 :         766 :       if (gimple_assign_rhs_code (stmt) == COND_EXPR)
    5633                 :             :         {
    5634                 :           0 :           tree cond = build2 (cmp_code, boolean_type_node, lhs,
    5635                 :             :                               boolean_false_node);
    5636                 :           0 :           gimple_assign_set_rhs1 (stmt, cond);
    5637                 :           0 :           lhs = gimple_assign_lhs (stmt);
    5638                 :           0 :           gcc_assert (TREE_CODE (TREE_TYPE (lhs)) != BITINT_TYPE
    5639                 :             :                       || (bitint_precision_kind (TREE_TYPE (lhs))
    5640                 :             :                           <= bitint_prec_middle));
    5641                 :           0 :           update_stmt (stmt);
    5642                 :           0 :           return;
    5643                 :             :         }
    5644                 :         766 :       gimple_assign_set_rhs1 (stmt, lhs);
    5645                 :         766 :       gimple_assign_set_rhs2 (stmt, boolean_false_node);
    5646                 :         766 :       gimple_assign_set_rhs_code (stmt, cmp_code);
    5647                 :         766 :       update_stmt (stmt);
    5648                 :         766 :       return;
    5649                 :             :     }
    5650                 :        8952 :   if (final_cast_p)
    5651                 :             :     {
    5652                 :        2429 :       tree lhs_type = TREE_TYPE (lhs);
    5653                 :             :       /* Add support for 3 or more limbs filled in from normal integral
    5654                 :             :          type if this assert fails.  If no target chooses limb mode smaller
    5655                 :             :          than half of largest supported normal integral type, this will not
    5656                 :             :          be needed.  */
    5657                 :        2429 :       gcc_assert (TYPE_PRECISION (lhs_type) <= 2 * limb_prec);
    5658                 :        2429 :       gimple *g;
    5659                 :        2429 :       if ((TREE_CODE (lhs_type) == BITINT_TYPE
    5660                 :          25 :            && bitint_precision_kind (lhs_type) == bitint_prec_middle)
    5661                 :        2447 :           || POINTER_TYPE_P (lhs_type))
    5662                 :           9 :         lhs_type = build_nonstandard_integer_type (TYPE_PRECISION (lhs_type),
    5663                 :           9 :                                                    TYPE_UNSIGNED (lhs_type));
    5664                 :        2429 :       m_data_cnt = 0;
    5665                 :        2429 :       tree rhs1 = gimple_assign_rhs1 (stmt);
    5666                 :        2429 :       tree r1 = handle_operand (rhs1, size_int (0));
    5667                 :        2429 :       if (!useless_type_conversion_p (lhs_type, TREE_TYPE (r1)))
    5668                 :        2329 :         r1 = add_cast (lhs_type, r1);
    5669                 :        2429 :       if (TYPE_PRECISION (lhs_type) > limb_prec)
    5670                 :             :         {
    5671                 :          59 :           m_data_cnt = 0;
    5672                 :          59 :           m_first = false;
    5673                 :          59 :           tree r2 = handle_operand (rhs1, size_int (1));
    5674                 :          59 :           r2 = add_cast (lhs_type, r2);
    5675                 :          59 :           g = gimple_build_assign (make_ssa_name (lhs_type), LSHIFT_EXPR, r2,
    5676                 :             :                                    build_int_cst (unsigned_type_node,
    5677                 :             :                                                   limb_prec));
    5678                 :          59 :           insert_before (g);
    5679                 :          59 :           g = gimple_build_assign (make_ssa_name (lhs_type), BIT_IOR_EXPR, r1,
    5680                 :             :                                    gimple_assign_lhs (g));
    5681                 :          59 :           insert_before (g);
    5682                 :          59 :           r1 = gimple_assign_lhs (g);
    5683                 :             :         }
    5684                 :        2429 :       if (lhs_type != TREE_TYPE (lhs))
    5685                 :           9 :         g = gimple_build_assign (lhs, NOP_EXPR, r1);
    5686                 :             :       else
    5687                 :        2420 :         g = gimple_build_assign (lhs, r1);
    5688                 :        2429 :       gsi_replace (&m_gsi, g, true);
    5689                 :        2429 :       return;
    5690                 :             :     }
    5691                 :        6523 :   if (is_gimple_assign (stmt))
    5692                 :        6523 :     switch (gimple_assign_rhs_code (stmt))
    5693                 :             :       {
    5694                 :         417 :       case LSHIFT_EXPR:
    5695                 :         417 :       case RSHIFT_EXPR:
    5696                 :         417 :         lower_shift_stmt (NULL_TREE, stmt);
    5697                 :         417 :         return;
    5698                 :         123 :       case MULT_EXPR:
    5699                 :         123 :       case TRUNC_DIV_EXPR:
    5700                 :         123 :       case TRUNC_MOD_EXPR:
    5701                 :         123 :         lower_muldiv_stmt (NULL_TREE, stmt);
    5702                 :         123 :         return;
    5703                 :         250 :       case FIX_TRUNC_EXPR:
    5704                 :         250 :       case FLOAT_EXPR:
    5705                 :         250 :         lower_float_conv_stmt (NULL_TREE, stmt);
    5706                 :         250 :         return;
    5707                 :        5715 :       case REALPART_EXPR:
    5708                 :        5715 :       case IMAGPART_EXPR:
    5709                 :        5715 :         lower_cplxpart_stmt (NULL_TREE, stmt);
    5710                 :        5715 :         return;
    5711                 :          18 :       case COMPLEX_EXPR:
    5712                 :          18 :         lower_complexexpr_stmt (stmt);
    5713                 :          18 :         return;
    5714                 :             :       default:
    5715                 :             :         break;
    5716                 :             :       }
    5717                 :           0 :   gcc_unreachable ();
    5718                 :             : }
    5719                 :             : 
    5720                 :             : /* Helper for walk_non_aliased_vuses.  Determine if we arrived at
    5721                 :             :    the desired memory state.  */
    5722                 :             : 
    5723                 :             : void *
    5724                 :        2162 : vuse_eq (ao_ref *, tree vuse1, void *data)
    5725                 :             : {
    5726                 :        2162 :   tree vuse2 = (tree) data;
    5727                 :        2162 :   if (vuse1 == vuse2)
    5728                 :         812 :     return data;
    5729                 :             : 
    5730                 :             :   return NULL;
    5731                 :             : }
    5732                 :             : 
    5733                 :             : /* Return true if STMT uses a library function and needs to take
    5734                 :             :    address of its inputs.  We need to avoid bit-fields in those
    5735                 :             :    cases.  Similarly, we need to avoid overlap between destination
    5736                 :             :    and source limb arrays.  */
    5737                 :             : 
    5738                 :             : bool
    5739                 :       13813 : stmt_needs_operand_addr (gimple *stmt)
    5740                 :             : {
    5741                 :       13813 :   if (is_gimple_assign (stmt))
    5742                 :        9362 :     switch (gimple_assign_rhs_code (stmt))
    5743                 :             :       {
    5744                 :         458 :       case MULT_EXPR:
    5745                 :         458 :       case TRUNC_DIV_EXPR:
    5746                 :         458 :       case TRUNC_MOD_EXPR:
    5747                 :         458 :       case FLOAT_EXPR:
    5748                 :         458 :         return true;
    5749                 :             :       default:
    5750                 :             :         break;
    5751                 :             :       }
    5752                 :        4451 :   else if (gimple_call_internal_p (stmt, IFN_MUL_OVERFLOW)
    5753                 :        4451 :            || gimple_call_internal_p (stmt, IFN_UBSAN_CHECK_MUL))
    5754                 :             :     return true;
    5755                 :             :   return false;
    5756                 :             : }
    5757                 :             : 
    5758                 :             : /* Dominator walker used to discover which large/huge _BitInt
    5759                 :             :    loads could be sunk into all their uses.  */
    5760                 :             : 
    5761                 :         510 : class bitint_dom_walker : public dom_walker
    5762                 :             : {
    5763                 :             : public:
    5764                 :         255 :   bitint_dom_walker (bitmap names, bitmap loads)
    5765                 :         510 :     : dom_walker (CDI_DOMINATORS), m_names (names), m_loads (loads) {}
    5766                 :             : 
    5767                 :             :   edge before_dom_children (basic_block) final override;
    5768                 :             : 
    5769                 :             : private:
    5770                 :             :   bitmap m_names, m_loads;
    5771                 :             : };
    5772                 :             : 
    5773                 :             : edge
    5774                 :        4150 : bitint_dom_walker::before_dom_children (basic_block bb)
    5775                 :             : {
    5776                 :        4150 :   gphi *phi = get_virtual_phi (bb);
    5777                 :        4150 :   tree vop;
    5778                 :        4150 :   if (phi)
    5779                 :         781 :     vop = gimple_phi_result (phi);
    5780                 :        3369 :   else if (bb == ENTRY_BLOCK_PTR_FOR_FN (cfun))
    5781                 :             :     vop = NULL_TREE;
    5782                 :             :   else
    5783                 :        3114 :     vop = (tree) get_immediate_dominator (CDI_DOMINATORS, bb)->aux;
    5784                 :             : 
    5785                 :        4150 :   auto_vec<tree, 16> worklist;
    5786                 :        8300 :   for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
    5787                 :       18325 :        !gsi_end_p (gsi); gsi_next (&gsi))
    5788                 :             :     {
    5789                 :       14175 :       gimple *stmt = gsi_stmt (gsi);
    5790                 :       14175 :       if (is_gimple_debug (stmt))
    5791                 :        2690 :         continue;
    5792                 :             : 
    5793                 :       14070 :       if (!vop && gimple_vuse (stmt))
    5794                 :             :         vop = gimple_vuse (stmt);
    5795                 :             : 
    5796                 :       13813 :       tree cvop = vop;
    5797                 :       25973 :       if (gimple_vdef (stmt))
    5798                 :       13813 :         vop = gimple_vdef (stmt);
    5799                 :             : 
    5800                 :       13813 :       tree lhs = gimple_get_lhs (stmt);
    5801                 :       16141 :       if (lhs
    5802                 :       10001 :           && TREE_CODE (lhs) == SSA_NAME
    5803                 :        7876 :           && TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
    5804                 :        5540 :           && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large
    5805                 :       19284 :           && !bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs)))
    5806                 :             :         /* If lhs of stmt is large/huge _BitInt SSA_NAME not in m_names,
    5807                 :             :            it means it will be handled in a loop or straight line code
    5808                 :             :            at the location of its (ultimate) immediate use, so for
    5809                 :             :            vop checking purposes check these only at the ultimate
    5810                 :             :            immediate use.  */
    5811                 :        2328 :         continue;
    5812                 :             : 
    5813                 :       11485 :       ssa_op_iter oi;
    5814                 :       11485 :       use_operand_p use_p;
    5815                 :       19344 :       FOR_EACH_SSA_USE_OPERAND (use_p, stmt, oi, SSA_OP_USE)
    5816                 :             :         {
    5817                 :        7859 :           tree s = USE_FROM_PTR (use_p);
    5818                 :        7859 :           if (TREE_CODE (TREE_TYPE (s)) == BITINT_TYPE
    5819                 :        7859 :               && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large)
    5820                 :        3044 :             worklist.safe_push (s);
    5821                 :             :         }
    5822                 :             : 
    5823                 :       11485 :       bool needs_operand_addr = stmt_needs_operand_addr (stmt);
    5824                 :       28808 :       while (worklist.length () > 0)
    5825                 :             :         {
    5826                 :        5838 :           tree s = worklist.pop ();
    5827                 :             : 
    5828                 :        5838 :           if (!bitmap_bit_p (m_names, SSA_NAME_VERSION (s)))
    5829                 :             :             {
    5830                 :        2328 :               gimple *g = SSA_NAME_DEF_STMT (s);
    5831                 :        2328 :               needs_operand_addr |= stmt_needs_operand_addr (g);
    5832                 :        5347 :               FOR_EACH_SSA_USE_OPERAND (use_p, g, oi, SSA_OP_USE)
    5833                 :             :                 {
    5834                 :        3019 :                   tree s2 = USE_FROM_PTR (use_p);
    5835                 :        3019 :                   if (TREE_CODE (TREE_TYPE (s2)) == BITINT_TYPE
    5836                 :        3019 :                       && (bitint_precision_kind (TREE_TYPE (s2))
    5837                 :             :                           >= bitint_prec_large))
    5838                 :        2794 :                     worklist.safe_push (s2);
    5839                 :             :                 }
    5840                 :        2989 :               continue;
    5841                 :        2328 :             }
    5842                 :        3510 :           if (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s)
    5843                 :        3510 :               && gimple_assign_cast_p (SSA_NAME_DEF_STMT (s)))
    5844                 :             :             {
    5845                 :         213 :               tree rhs = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s));
    5846                 :         370 :               if (TREE_CODE (rhs) == SSA_NAME
    5847                 :         213 :                   && bitmap_bit_p (m_loads, SSA_NAME_VERSION (rhs)))
    5848                 :             :                 s = rhs;
    5849                 :             :               else
    5850                 :         157 :                 continue;
    5851                 :             :             }
    5852                 :        3297 :           else if (!bitmap_bit_p (m_loads, SSA_NAME_VERSION (s)))
    5853                 :         502 :             continue;
    5854                 :             : 
    5855                 :        2851 :           gimple *g = SSA_NAME_DEF_STMT (s);
    5856                 :        2851 :           tree rhs1 = gimple_assign_rhs1 (g);
    5857                 :        2851 :           if (needs_operand_addr
    5858                 :         202 :               && TREE_CODE (rhs1) == COMPONENT_REF
    5859                 :        2862 :               && DECL_BIT_FIELD_TYPE (TREE_OPERAND (rhs1, 1)))
    5860                 :             :             {
    5861                 :           4 :               tree fld = TREE_OPERAND (rhs1, 1);
    5862                 :             :               /* For little-endian, we can allow as inputs bit-fields
    5863                 :             :                  which start at a limb boundary.  */
    5864                 :           4 :               if (DECL_OFFSET_ALIGN (fld) >= TYPE_ALIGN (TREE_TYPE (rhs1))
    5865                 :           4 :                   && tree_fits_uhwi_p (DECL_FIELD_BIT_OFFSET (fld))
    5866                 :           4 :                   && (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld))
    5867                 :           4 :                       % limb_prec) == 0)
    5868                 :             :                 ;
    5869                 :             :               else
    5870                 :             :                 {
    5871                 :           2 :                   bitmap_clear_bit (m_loads, SSA_NAME_VERSION (s));
    5872                 :           2 :                   continue;
    5873                 :             :                 }
    5874                 :             :             }
    5875                 :             : 
    5876                 :        2849 :           ao_ref ref;
    5877                 :        2849 :           ao_ref_init (&ref, rhs1);
    5878                 :        2849 :           tree lvop = gimple_vuse (g);
    5879                 :        2849 :           unsigned limit = 64;
    5880                 :        2849 :           tree vuse = cvop;
    5881                 :        2849 :           if (vop != cvop
    5882                 :        1311 :               && is_gimple_assign (stmt)
    5883                 :        1309 :               && gimple_store_p (stmt)
    5884                 :        4158 :               && (needs_operand_addr
    5885                 :        1127 :                   || !operand_equal_p (lhs, gimple_assign_rhs1 (g), 0)))
    5886                 :             :             vuse = vop;
    5887                 :        2849 :           if (vuse != lvop
    5888                 :        2849 :               && walk_non_aliased_vuses (&ref, vuse, false, vuse_eq,
    5889                 :             :                                          NULL, NULL, limit, lvop) == NULL)
    5890                 :         519 :             bitmap_clear_bit (m_loads, SSA_NAME_VERSION (s));
    5891                 :             :         }
    5892                 :             :     }
    5893                 :             : 
    5894                 :        4150 :   bb->aux = (void *) vop;
    5895                 :        4150 :   return NULL;
    5896                 :        4150 : }
    5897                 :             : 
    5898                 :             : }
    5899                 :             : 
    5900                 :             : /* Replacement for normal processing of STMT in tree-ssa-coalesce.cc
    5901                 :             :    build_ssa_conflict_graph.
    5902                 :             :    The differences are:
    5903                 :             :    1) don't process assignments with large/huge _BitInt lhs not in NAMES
    5904                 :             :    2) for large/huge _BitInt multiplication/division/modulo process def
    5905                 :             :       only after processing uses rather than before to make uses conflict
    5906                 :             :       with the definition
    5907                 :             :    3) for large/huge _BitInt uses not in NAMES mark the uses of their
    5908                 :             :       SSA_NAME_DEF_STMT (recursively), because those uses will be sunk into
    5909                 :             :       the final statement.  */
    5910                 :             : 
    5911                 :             : void
    5912                 :       80037 : build_bitint_stmt_ssa_conflicts (gimple *stmt, live_track *live,
    5913                 :             :                                  ssa_conflicts *graph, bitmap names,
    5914                 :             :                                  void (*def) (live_track *, tree,
    5915                 :             :                                               ssa_conflicts *),
    5916                 :             :                                  void (*use) (live_track *, tree))
    5917                 :             : {
    5918                 :       80037 :   bool muldiv_p = false;
    5919                 :       80037 :   tree lhs = NULL_TREE;
    5920                 :       80037 :   if (is_gimple_assign (stmt))
    5921                 :             :     {
    5922                 :       43433 :       lhs = gimple_assign_lhs (stmt);
    5923                 :       43433 :       if (TREE_CODE (lhs) == SSA_NAME)
    5924                 :             :         {
    5925                 :       31228 :           tree type = TREE_TYPE (lhs);
    5926                 :       31228 :           if (TREE_CODE (type) == COMPLEX_TYPE)
    5927                 :          69 :             type = TREE_TYPE (type);
    5928                 :       31228 :           if (TREE_CODE (type) == BITINT_TYPE
    5929                 :       31228 :               && bitint_precision_kind (type) >= bitint_prec_large)
    5930                 :             :             {
    5931                 :       18878 :               if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs)))
    5932                 :        4483 :                 return;
    5933                 :       14395 :               switch (gimple_assign_rhs_code (stmt))
    5934                 :             :                 {
    5935                 :             :                 case MULT_EXPR:
    5936                 :             :                 case TRUNC_DIV_EXPR:
    5937                 :             :                 case TRUNC_MOD_EXPR:
    5938                 :       75554 :                   muldiv_p = true;
    5939                 :             :                 default:
    5940                 :             :                   break;
    5941                 :             :                 }
    5942                 :             :             }
    5943                 :             :         }
    5944                 :             :     }
    5945                 :             : 
    5946                 :       75554 :   ssa_op_iter iter;
    5947                 :       75554 :   tree var;
    5948                 :       75554 :   if (!muldiv_p)
    5949                 :             :     {
    5950                 :             :       /* For stmts with more than one SSA_NAME definition pretend all the
    5951                 :             :          SSA_NAME outputs but the first one are live at this point, so
    5952                 :             :          that conflicts are added in between all those even when they are
    5953                 :             :          actually not really live after the asm, because expansion might
    5954                 :             :          copy those into pseudos after the asm and if multiple outputs
    5955                 :             :          share the same partition, it might overwrite those that should
    5956                 :             :          be live.  E.g.
    5957                 :             :          asm volatile (".." : "=r" (a) : "=r" (b) : "0" (a), "1" (a));
    5958                 :             :          return a;
    5959                 :             :          See PR70593.  */
    5960                 :       75431 :       bool first = true;
    5961                 :      110850 :       FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF)
    5962                 :       35419 :         if (first)
    5963                 :             :           first = false;
    5964                 :             :         else
    5965                 :           0 :           use (live, var);
    5966                 :             : 
    5967                 :      110850 :       FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF)
    5968                 :       35419 :         def (live, var, graph);
    5969                 :             :     }
    5970                 :             : 
    5971                 :      151108 :   auto_vec<tree, 16> worklist;
    5972                 :      128322 :   FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE)
    5973                 :             :     {
    5974                 :       52768 :       tree type = TREE_TYPE (var);
    5975                 :       52768 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    5976                 :        6059 :         type = TREE_TYPE (type);
    5977                 :       52768 :       if (TREE_CODE (type) == BITINT_TYPE
    5978                 :       52768 :           && bitint_precision_kind (type) >= bitint_prec_large)
    5979                 :             :         {
    5980                 :       34323 :           if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
    5981                 :       29535 :             use (live, var);
    5982                 :             :           else
    5983                 :        4788 :             worklist.safe_push (var);
    5984                 :             :         }
    5985                 :             :     }
    5986                 :             : 
    5987                 :       83203 :   while (worklist.length () > 0)
    5988                 :             :     {
    5989                 :        7649 :       tree s = worklist.pop ();
    5990                 :       15913 :       FOR_EACH_SSA_TREE_OPERAND (var, SSA_NAME_DEF_STMT (s), iter, SSA_OP_USE)
    5991                 :             :         {
    5992                 :        8264 :           tree type = TREE_TYPE (var);
    5993                 :        8264 :           if (TREE_CODE (type) == COMPLEX_TYPE)
    5994                 :        1595 :             type = TREE_TYPE (type);
    5995                 :        8264 :           if (TREE_CODE (type) == BITINT_TYPE
    5996                 :        8264 :               && bitint_precision_kind (type) >= bitint_prec_large)
    5997                 :             :             {
    5998                 :        7634 :               if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
    5999                 :        4773 :                 use (live, var);
    6000                 :             :               else
    6001                 :        2861 :                 worklist.safe_push (var);
    6002                 :             :             }
    6003                 :             :         }
    6004                 :             :     }
    6005                 :             : 
    6006                 :       75554 :   if (muldiv_p)
    6007                 :         123 :     def (live, lhs, graph);
    6008                 :             : }
    6009                 :             : 
    6010                 :             : /* If STMT is .{ADD,SUB,MUL}_OVERFLOW with INTEGER_CST arguments,
    6011                 :             :    return the largest bitint_prec_kind of them, otherwise return
    6012                 :             :    bitint_prec_small.  */
    6013                 :             : 
    6014                 :             : static bitint_prec_kind
    6015                 :      210674 : arith_overflow_arg_kind (gimple *stmt)
    6016                 :             : {
    6017                 :      210674 :   bitint_prec_kind ret = bitint_prec_small;
    6018                 :      210674 :   if (is_gimple_call (stmt) && gimple_call_internal_p (stmt))
    6019                 :       87898 :     switch (gimple_call_internal_fn (stmt))
    6020                 :             :       {
    6021                 :             :       case IFN_ADD_OVERFLOW:
    6022                 :             :       case IFN_SUB_OVERFLOW:
    6023                 :             :       case IFN_MUL_OVERFLOW:
    6024                 :      224160 :         for (int i = 0; i < 2; ++i)
    6025                 :             :           {
    6026                 :      149440 :             tree a = gimple_call_arg (stmt, i);
    6027                 :      149440 :             if (TREE_CODE (a) == INTEGER_CST
    6028                 :      149440 :                 && TREE_CODE (TREE_TYPE (a)) == BITINT_TYPE)
    6029                 :             :               {
    6030                 :        5801 :                 bitint_prec_kind kind = bitint_precision_kind (TREE_TYPE (a));
    6031                 :        5801 :                 ret = MAX (ret, kind);
    6032                 :             :               }
    6033                 :             :           }
    6034                 :             :         break;
    6035                 :             :       default:
    6036                 :             :         break;
    6037                 :             :       }
    6038                 :      210674 :   return ret;
    6039                 :             : }
    6040                 :             : 
    6041                 :             : /* Entry point for _BitInt(N) operation lowering during optimization.  */
    6042                 :             : 
    6043                 :             : static unsigned int
    6044                 :     1419223 : gimple_lower_bitint (void)
    6045                 :             : {
    6046                 :     1419223 :   small_max_prec = mid_min_prec = large_min_prec = huge_min_prec = 0;
    6047                 :     1419223 :   limb_prec = 0;
    6048                 :             : 
    6049                 :     1419223 :   unsigned int i;
    6050                 :   114426280 :   for (i = 0; i < num_ssa_names; ++i)
    6051                 :             :     {
    6052                 :    55800868 :       tree s = ssa_name (i);
    6053                 :    55800868 :       if (s == NULL)
    6054                 :    10405007 :         continue;
    6055                 :    45395861 :       tree type = TREE_TYPE (s);
    6056                 :    45395861 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    6057                 :             :         {
    6058                 :      200302 :           if (arith_overflow_arg_kind (SSA_NAME_DEF_STMT (s))
    6059                 :             :               != bitint_prec_small)
    6060                 :             :             break;
    6061                 :      200288 :           type = TREE_TYPE (type);
    6062                 :             :         }
    6063                 :    45395847 :       if (TREE_CODE (type) == BITINT_TYPE
    6064                 :    45395847 :           && bitint_precision_kind (type) != bitint_prec_small)
    6065                 :             :         break;
    6066                 :             :       /* We need to also rewrite stores of large/huge _BitInt INTEGER_CSTs
    6067                 :             :          into memory.  Such functions could have no large/huge SSA_NAMEs.  */
    6068                 :    45388960 :       if (SSA_NAME_IS_VIRTUAL_OPERAND (s))
    6069                 :             :         {
    6070                 :    19873907 :           gimple *g = SSA_NAME_DEF_STMT (s);
    6071                 :    19873907 :           if (is_gimple_assign (g) && gimple_store_p (g))
    6072                 :             :             {
    6073                 :    10084931 :               tree t = gimple_assign_rhs1 (g);
    6074                 :    10084931 :               if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE
    6075                 :    10084931 :                   && (bitint_precision_kind (TREE_TYPE (t))
    6076                 :             :                       >= bitint_prec_large))
    6077                 :             :                 break;
    6078                 :             :             }
    6079                 :             :         }
    6080                 :             :       /* Similarly, e.g. with -frounding-math casts from _BitInt INTEGER_CSTs
    6081                 :             :          to floating point types need to be rewritten.  */
    6082                 :    25515053 :       else if (SCALAR_FLOAT_TYPE_P (type))
    6083                 :             :         {
    6084                 :     2278263 :           gimple *g = SSA_NAME_DEF_STMT (s);
    6085                 :     2278263 :           if (is_gimple_assign (g) && gimple_assign_rhs_code (g) == FLOAT_EXPR)
    6086                 :             :             {
    6087                 :      124630 :               tree t = gimple_assign_rhs1 (g);
    6088                 :      124630 :               if (TREE_CODE (t) == INTEGER_CST
    6089                 :          78 :                   && TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE
    6090                 :      124631 :                   && (bitint_precision_kind (TREE_TYPE (t))
    6091                 :             :                       != bitint_prec_small))
    6092                 :             :                 break;
    6093                 :             :             }
    6094                 :             :         }
    6095                 :             :     }
    6096                 :     2838446 :   if (i == num_ssa_names)
    6097                 :             :     return 0;
    6098                 :             : 
    6099                 :        6951 :   basic_block bb;
    6100                 :        6951 :   auto_vec<gimple *, 4> switch_statements;
    6101                 :       47213 :   FOR_EACH_BB_FN (bb, cfun)
    6102                 :             :     {
    6103                 :      120059 :       if (gswitch *swtch = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb)))
    6104                 :             :         {
    6105                 :          23 :           tree idx = gimple_switch_index (swtch);
    6106                 :          23 :           if (TREE_CODE (TREE_TYPE (idx)) != BITINT_TYPE
    6107                 :          23 :               || bitint_precision_kind (TREE_TYPE (idx)) < bitint_prec_large)
    6108                 :          12 :             continue;
    6109                 :             : 
    6110                 :          11 :           if (optimize)
    6111                 :           6 :             group_case_labels_stmt (swtch);
    6112                 :          11 :           if (gimple_switch_num_labels (swtch) == 1)
    6113                 :             :             {
    6114                 :           1 :               single_succ_edge (bb)->flags |= EDGE_FALLTHRU;
    6115                 :           1 :               gimple_stmt_iterator gsi = gsi_for_stmt (swtch);
    6116                 :           1 :               gsi_remove (&gsi, true);
    6117                 :             :             }
    6118                 :             :           else
    6119                 :          10 :             switch_statements.safe_push (swtch);
    6120                 :             :         }
    6121                 :             :     }
    6122                 :             : 
    6123                 :        6951 :   if (!switch_statements.is_empty ())
    6124                 :             :     {
    6125                 :          10 :       bool expanded = false;
    6126                 :          10 :       gimple *stmt;
    6127                 :          10 :       unsigned int j;
    6128                 :          10 :       i = 0;
    6129                 :          20 :       FOR_EACH_VEC_ELT (switch_statements, j, stmt)
    6130                 :             :         {
    6131                 :          10 :           gswitch *swtch = as_a<gswitch *> (stmt);
    6132                 :          10 :           tree_switch_conversion::switch_decision_tree dt (swtch);
    6133                 :          10 :           expanded |= dt.analyze_switch_statement ();
    6134                 :          10 :         }
    6135                 :             : 
    6136                 :          10 :       if (expanded)
    6137                 :             :         {
    6138                 :          10 :           free_dominance_info (CDI_DOMINATORS);
    6139                 :          10 :           free_dominance_info (CDI_POST_DOMINATORS);
    6140                 :          10 :           mark_virtual_operands_for_renaming (cfun);
    6141                 :          10 :           cleanup_tree_cfg (TODO_update_ssa);
    6142                 :             :         }
    6143                 :             :     }
    6144                 :             : 
    6145                 :        6951 :   struct bitint_large_huge large_huge;
    6146                 :        6951 :   bool has_large_huge_parm_result = false;
    6147                 :        6951 :   bool has_large_huge = false;
    6148                 :        6951 :   unsigned int ret = 0, first_large_huge = ~0U;
    6149                 :        6951 :   bool edge_insertions = false;
    6150                 :      240878 :   for (; i < num_ssa_names; ++i)
    6151                 :             :     {
    6152                 :      113488 :       tree s = ssa_name (i);
    6153                 :      113488 :       if (s == NULL)
    6154                 :        2535 :         continue;
    6155                 :      110953 :       tree type = TREE_TYPE (s);
    6156                 :      110953 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    6157                 :             :         {
    6158                 :        5231 :           if (arith_overflow_arg_kind (SSA_NAME_DEF_STMT (s))
    6159                 :             :               >= bitint_prec_large)
    6160                 :        1957 :             has_large_huge = true;
    6161                 :        5231 :           type = TREE_TYPE (type);
    6162                 :             :         }
    6163                 :      110953 :       if (TREE_CODE (type) == BITINT_TYPE
    6164                 :      110953 :           && bitint_precision_kind (type) >= bitint_prec_large)
    6165                 :             :         {
    6166                 :       33918 :           if (first_large_huge == ~0U)
    6167                 :        5441 :             first_large_huge = i;
    6168                 :       33918 :           gimple *stmt = SSA_NAME_DEF_STMT (s), *g;
    6169                 :       33918 :           gimple_stmt_iterator gsi;
    6170                 :       33918 :           tree_code rhs_code;
    6171                 :             :           /* Unoptimize certain constructs to simpler alternatives to
    6172                 :             :              avoid having to lower all of them.  */
    6173                 :       33918 :           if (is_gimple_assign (stmt) && gimple_bb (stmt))
    6174                 :       21009 :             switch (rhs_code = gimple_assign_rhs_code (stmt))
    6175                 :             :               {
    6176                 :             :               default:
    6177                 :             :                 break;
    6178                 :         296 :               case MULT_EXPR:
    6179                 :         296 :               case TRUNC_DIV_EXPR:
    6180                 :         296 :               case TRUNC_MOD_EXPR:
    6181                 :         296 :                 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s))
    6182                 :             :                   {
    6183                 :           2 :                     location_t loc = gimple_location (stmt);
    6184                 :           2 :                     gsi = gsi_for_stmt (stmt);
    6185                 :           2 :                     tree rhs1 = gimple_assign_rhs1 (stmt);
    6186                 :           2 :                     tree rhs2 = gimple_assign_rhs2 (stmt);
    6187                 :             :                     /* For multiplication and division with (ab)
    6188                 :             :                        lhs and one or both operands force the operands
    6189                 :             :                        into new SSA_NAMEs to avoid coalescing failures.  */
    6190                 :           2 :                     if (TREE_CODE (rhs1) == SSA_NAME
    6191                 :           2 :                         && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1))
    6192                 :             :                       {
    6193                 :           2 :                         first_large_huge = 0;
    6194                 :           2 :                         tree t = make_ssa_name (TREE_TYPE (rhs1));
    6195                 :           2 :                         g = gimple_build_assign (t, SSA_NAME, rhs1);
    6196                 :           2 :                         gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6197                 :           2 :                         gimple_set_location (g, loc);
    6198                 :           2 :                         gimple_assign_set_rhs1 (stmt, t);
    6199                 :           2 :                         if (rhs1 == rhs2)
    6200                 :             :                           {
    6201                 :           0 :                             gimple_assign_set_rhs2 (stmt, t);
    6202                 :           0 :                             rhs2 = t;
    6203                 :             :                           }
    6204                 :           2 :                         update_stmt (stmt);
    6205                 :             :                       }
    6206                 :           2 :                     if (TREE_CODE (rhs2) == SSA_NAME
    6207                 :           2 :                         && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs2))
    6208                 :             :                       {
    6209                 :           0 :                         first_large_huge = 0;
    6210                 :           0 :                         tree t = make_ssa_name (TREE_TYPE (rhs2));
    6211                 :           0 :                         g = gimple_build_assign (t, SSA_NAME, rhs2);
    6212                 :           0 :                         gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6213                 :           0 :                         gimple_set_location (g, loc);
    6214                 :           0 :                         gimple_assign_set_rhs2 (stmt, t);
    6215                 :           0 :                         update_stmt (stmt);
    6216                 :             :                       }
    6217                 :             :                   }
    6218                 :             :                 break;
    6219                 :           0 :               case LROTATE_EXPR:
    6220                 :           0 :               case RROTATE_EXPR:
    6221                 :           0 :                 {
    6222                 :           0 :                   first_large_huge = 0;
    6223                 :           0 :                   location_t loc = gimple_location (stmt);
    6224                 :           0 :                   gsi = gsi_for_stmt (stmt);
    6225                 :           0 :                   tree rhs1 = gimple_assign_rhs1 (stmt);
    6226                 :           0 :                   tree type = TREE_TYPE (rhs1);
    6227                 :           0 :                   tree n = gimple_assign_rhs2 (stmt), m;
    6228                 :           0 :                   tree p = build_int_cst (TREE_TYPE (n),
    6229                 :           0 :                                           TYPE_PRECISION (type));
    6230                 :           0 :                   if (TREE_CODE (n) == INTEGER_CST)
    6231                 :           0 :                     m = fold_build2 (MINUS_EXPR, TREE_TYPE (n), p, n);
    6232                 :             :                   else
    6233                 :             :                     {
    6234                 :           0 :                       m = make_ssa_name (TREE_TYPE (n));
    6235                 :           0 :                       g = gimple_build_assign (m, MINUS_EXPR, p, n);
    6236                 :           0 :                       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6237                 :           0 :                       gimple_set_location (g, loc);
    6238                 :             :                     }
    6239                 :           0 :                   if (!TYPE_UNSIGNED (type))
    6240                 :             :                     {
    6241                 :           0 :                       tree utype = build_bitint_type (TYPE_PRECISION (type),
    6242                 :             :                                                       1);
    6243                 :           0 :                       if (TREE_CODE (rhs1) == INTEGER_CST)
    6244                 :           0 :                         rhs1 = fold_convert (utype, rhs1);
    6245                 :             :                       else
    6246                 :             :                         {
    6247                 :           0 :                           tree t = make_ssa_name (type);
    6248                 :           0 :                           g = gimple_build_assign (t, NOP_EXPR, rhs1);
    6249                 :           0 :                           gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6250                 :           0 :                           gimple_set_location (g, loc);
    6251                 :             :                         }
    6252                 :             :                     }
    6253                 :           0 :                   g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)),
    6254                 :             :                                            rhs_code == LROTATE_EXPR
    6255                 :             :                                            ? LSHIFT_EXPR : RSHIFT_EXPR,
    6256                 :             :                                            rhs1, n);
    6257                 :           0 :                   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6258                 :           0 :                   gimple_set_location (g, loc);
    6259                 :           0 :                   tree op1 = gimple_assign_lhs (g);
    6260                 :           0 :                   g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)),
    6261                 :             :                                            rhs_code == LROTATE_EXPR
    6262                 :             :                                            ? RSHIFT_EXPR : LSHIFT_EXPR,
    6263                 :             :                                            rhs1, m);
    6264                 :           0 :                   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6265                 :           0 :                   gimple_set_location (g, loc);
    6266                 :           0 :                   tree op2 = gimple_assign_lhs (g);
    6267                 :           0 :                   tree lhs = gimple_assign_lhs (stmt);
    6268                 :           0 :                   if (!TYPE_UNSIGNED (type))
    6269                 :             :                     {
    6270                 :           0 :                       g = gimple_build_assign (make_ssa_name (TREE_TYPE (op1)),
    6271                 :             :                                                BIT_IOR_EXPR, op1, op2);
    6272                 :           0 :                       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6273                 :           0 :                       gimple_set_location (g, loc);
    6274                 :           0 :                       g = gimple_build_assign (lhs, NOP_EXPR,
    6275                 :             :                                                gimple_assign_lhs (g));
    6276                 :             :                     }
    6277                 :             :                   else
    6278                 :           0 :                     g = gimple_build_assign (lhs, BIT_IOR_EXPR, op1, op2);
    6279                 :           0 :                   gsi_replace (&gsi, g, true);
    6280                 :           0 :                   gimple_set_location (g, loc);
    6281                 :             :                 }
    6282                 :           0 :                 break;
    6283                 :          20 :               case ABS_EXPR:
    6284                 :          20 :               case ABSU_EXPR:
    6285                 :          20 :               case MIN_EXPR:
    6286                 :          20 :               case MAX_EXPR:
    6287                 :          20 :               case COND_EXPR:
    6288                 :          20 :                 first_large_huge = 0;
    6289                 :          20 :                 gsi = gsi_for_stmt (stmt);
    6290                 :          20 :                 tree lhs = gimple_assign_lhs (stmt);
    6291                 :          20 :                 tree rhs1 = gimple_assign_rhs1 (stmt), rhs2 = NULL_TREE;
    6292                 :          20 :                 location_t loc = gimple_location (stmt);
    6293                 :          20 :                 if (rhs_code == ABS_EXPR)
    6294                 :           4 :                   g = gimple_build_cond (LT_EXPR, rhs1,
    6295                 :           4 :                                          build_zero_cst (TREE_TYPE (rhs1)),
    6296                 :             :                                          NULL_TREE, NULL_TREE);
    6297                 :          16 :                 else if (rhs_code == ABSU_EXPR)
    6298                 :             :                   {
    6299                 :           8 :                     rhs2 = make_ssa_name (TREE_TYPE (lhs));
    6300                 :           8 :                     g = gimple_build_assign (rhs2, NOP_EXPR, rhs1);
    6301                 :           8 :                     gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6302                 :           8 :                     gimple_set_location (g, loc);
    6303                 :           8 :                     g = gimple_build_cond (LT_EXPR, rhs1,
    6304                 :           8 :                                            build_zero_cst (TREE_TYPE (rhs1)),
    6305                 :             :                                            NULL_TREE, NULL_TREE);
    6306                 :           8 :                     rhs1 = rhs2;
    6307                 :             :                   }
    6308                 :           8 :                 else if (rhs_code == MIN_EXPR || rhs_code == MAX_EXPR)
    6309                 :             :                   {
    6310                 :           8 :                     rhs2 = gimple_assign_rhs2 (stmt);
    6311                 :           8 :                     if (TREE_CODE (rhs1) == INTEGER_CST)
    6312                 :           0 :                       std::swap (rhs1, rhs2);
    6313                 :           8 :                     g = gimple_build_cond (LT_EXPR, rhs1, rhs2,
    6314                 :             :                                            NULL_TREE, NULL_TREE);
    6315                 :           8 :                     if (rhs_code == MAX_EXPR)
    6316                 :           4 :                       std::swap (rhs1, rhs2);
    6317                 :             :                   }
    6318                 :             :                 else
    6319                 :             :                   {
    6320                 :           0 :                     g = gimple_build_cond (NE_EXPR, rhs1,
    6321                 :           0 :                                            build_zero_cst (TREE_TYPE (rhs1)),
    6322                 :             :                                            NULL_TREE, NULL_TREE);
    6323                 :           0 :                     rhs1 = gimple_assign_rhs2 (stmt);
    6324                 :           0 :                     rhs2 = gimple_assign_rhs3 (stmt);
    6325                 :             :                   }
    6326                 :          20 :                 gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6327                 :          20 :                 gimple_set_location (g, loc);
    6328                 :          20 :                 edge e1 = split_block (gsi_bb (gsi), g);
    6329                 :          20 :                 edge e2 = split_block (e1->dest, (gimple *) NULL);
    6330                 :          20 :                 edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE);
    6331                 :          20 :                 e3->probability = profile_probability::even ();
    6332                 :          20 :                 e1->flags = EDGE_TRUE_VALUE;
    6333                 :          20 :                 e1->probability = e3->probability.invert ();
    6334                 :          20 :                 if (dom_info_available_p (CDI_DOMINATORS))
    6335                 :          12 :                   set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src);
    6336                 :          20 :                 if (rhs_code == ABS_EXPR || rhs_code == ABSU_EXPR)
    6337                 :             :                   {
    6338                 :          12 :                     gsi = gsi_after_labels (e1->dest);
    6339                 :          12 :                     g = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)),
    6340                 :             :                                              NEGATE_EXPR, rhs1);
    6341                 :          12 :                     gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6342                 :          12 :                     gimple_set_location (g, loc);
    6343                 :          12 :                     rhs2 = gimple_assign_lhs (g);
    6344                 :          12 :                     std::swap (rhs1, rhs2);
    6345                 :             :                   }
    6346                 :          20 :                 gsi = gsi_for_stmt (stmt);
    6347                 :          20 :                 gsi_remove (&gsi, true);
    6348                 :          20 :                 gphi *phi = create_phi_node (lhs, e2->dest);
    6349                 :          20 :                 add_phi_arg (phi, rhs1, e2, UNKNOWN_LOCATION);
    6350                 :          20 :                 add_phi_arg (phi, rhs2, e3, UNKNOWN_LOCATION);
    6351                 :          20 :                 break;
    6352                 :             :               }
    6353                 :             :         }
    6354                 :             :       /* We need to also rewrite stores of large/huge _BitInt INTEGER_CSTs
    6355                 :             :          into memory.  Such functions could have no large/huge SSA_NAMEs.  */
    6356                 :       77035 :       else if (SSA_NAME_IS_VIRTUAL_OPERAND (s))
    6357                 :             :         {
    6358                 :       49514 :           gimple *g = SSA_NAME_DEF_STMT (s);
    6359                 :       49514 :           if (is_gimple_assign (g) && gimple_store_p (g))
    6360                 :             :             {
    6361                 :       15702 :               tree t = gimple_assign_rhs1 (g);
    6362                 :       15702 :               if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE
    6363                 :       15702 :                   && (bitint_precision_kind (TREE_TYPE (t))
    6364                 :             :                       >= bitint_prec_large))
    6365                 :             :                 has_large_huge = true;
    6366                 :             :             }
    6367                 :             :         }
    6368                 :             :       /* Similarly, e.g. with -frounding-math casts from _BitInt INTEGER_CSTs
    6369                 :             :          to floating point types need to be rewritten.  */
    6370                 :       27521 :       else if (SCALAR_FLOAT_TYPE_P (type))
    6371                 :             :         {
    6372                 :         455 :           gimple *g = SSA_NAME_DEF_STMT (s);
    6373                 :         455 :           if (is_gimple_assign (g) && gimple_assign_rhs_code (g) == FLOAT_EXPR)
    6374                 :             :             {
    6375                 :         127 :               tree t = gimple_assign_rhs1 (g);
    6376                 :         127 :               if (TREE_CODE (t) == INTEGER_CST
    6377                 :           1 :                   && TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE
    6378                 :         128 :                   && (bitint_precision_kind (TREE_TYPE (t))
    6379                 :             :                       >= bitint_prec_large))
    6380                 :             :                 has_large_huge = true;
    6381                 :             :             }
    6382                 :             :         }
    6383                 :             :     }
    6384                 :      195098 :   for (i = first_large_huge; i < num_ssa_names; ++i)
    6385                 :             :     {
    6386                 :       90598 :       tree s = ssa_name (i);
    6387                 :       90598 :       if (s == NULL)
    6388                 :        2345 :         continue;
    6389                 :       88253 :       tree type = TREE_TYPE (s);
    6390                 :       88253 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    6391                 :        4062 :         type = TREE_TYPE (type);
    6392                 :       88253 :       if (TREE_CODE (type) == BITINT_TYPE
    6393                 :       88253 :           && bitint_precision_kind (type) >= bitint_prec_large)
    6394                 :             :         {
    6395                 :       33922 :           use_operand_p use_p;
    6396                 :       33922 :           gimple *use_stmt;
    6397                 :       33922 :           has_large_huge = true;
    6398                 :       35571 :           if (optimize
    6399                 :       49566 :               && optimizable_arith_overflow (SSA_NAME_DEF_STMT (s)))
    6400                 :        6042 :             continue;
    6401                 :             :           /* Ignore large/huge _BitInt SSA_NAMEs which have single use in
    6402                 :             :              the same bb and could be handled in the same loop with the
    6403                 :             :              immediate use.  */
    6404                 :       32273 :           if (optimize
    6405                 :       13995 :               && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s)
    6406                 :       13973 :               && single_imm_use (s, &use_p, &use_stmt)
    6407                 :       45801 :               && gimple_bb (SSA_NAME_DEF_STMT (s)) == gimple_bb (use_stmt))
    6408                 :             :             {
    6409                 :        9492 :               if (mergeable_op (SSA_NAME_DEF_STMT (s)))
    6410                 :             :                 {
    6411                 :        2005 :                   if (mergeable_op (use_stmt))
    6412                 :        1794 :                     continue;
    6413                 :         211 :                   tree_code cmp_code = comparison_op (use_stmt, NULL, NULL);
    6414                 :         211 :                   if (cmp_code == EQ_EXPR || cmp_code == NE_EXPR)
    6415                 :          26 :                     continue;
    6416                 :         185 :                   if (gimple_assign_cast_p (use_stmt))
    6417                 :             :                     {
    6418                 :          51 :                       tree lhs = gimple_assign_lhs (use_stmt);
    6419                 :         102 :                       if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    6420                 :             :                           /* Don't merge with VIEW_CONVERT_EXPRs to
    6421                 :             :                              huge INTEGER_TYPEs used sometimes in memcpy
    6422                 :             :                              expansion.  */
    6423                 :          89 :                           && (TREE_CODE (TREE_TYPE (lhs)) != INTEGER_TYPE
    6424                 :           1 :                               || (TYPE_PRECISION (TREE_TYPE (lhs))
    6425                 :           2 :                                   <= MAX_FIXED_MODE_SIZE)))
    6426                 :          38 :                         continue;
    6427                 :             :                     }
    6428                 :         134 :                   else if (gimple_store_p (use_stmt)
    6429                 :           0 :                            && is_gimple_assign (use_stmt)
    6430                 :           0 :                            && !gimple_has_volatile_ops (use_stmt)
    6431                 :         134 :                            && !stmt_ends_bb_p (use_stmt))
    6432                 :           0 :                     continue;
    6433                 :             :                 }
    6434                 :        7634 :               if (gimple_assign_cast_p (SSA_NAME_DEF_STMT (s)))
    6435                 :             :                 {
    6436                 :         729 :                   tree rhs1 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s));
    6437                 :         729 :                   if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR)
    6438                 :             :                     {
    6439                 :          18 :                       rhs1 = TREE_OPERAND (rhs1, 0);
    6440                 :          18 :                       if (!INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    6441                 :          14 :                           && !POINTER_TYPE_P (TREE_TYPE (rhs1))
    6442                 :          14 :                           && gimple_store_p (use_stmt))
    6443                 :           7 :                         continue;
    6444                 :             :                     }
    6445                 :        1444 :                   if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    6446                 :         642 :                       && ((is_gimple_assign (use_stmt)
    6447                 :         596 :                            && (gimple_assign_rhs_code (use_stmt)
    6448                 :             :                                != COMPLEX_EXPR))
    6449                 :          46 :                           || gimple_code (use_stmt) == GIMPLE_COND)
    6450                 :         632 :                       && (!gimple_store_p (use_stmt)
    6451                 :          75 :                           || (is_gimple_assign (use_stmt)
    6452                 :          75 :                               && !gimple_has_volatile_ops (use_stmt)
    6453                 :          75 :                               && !stmt_ends_bb_p (use_stmt)))
    6454                 :        1354 :                       && (TREE_CODE (rhs1) != SSA_NAME
    6455                 :         632 :                           || !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)))
    6456                 :             :                     {
    6457                 :         632 :                       if (is_gimple_assign (use_stmt))
    6458                 :         596 :                         switch (gimple_assign_rhs_code (use_stmt))
    6459                 :             :                           {
    6460                 :          44 :                           case TRUNC_DIV_EXPR:
    6461                 :          44 :                           case TRUNC_MOD_EXPR:
    6462                 :          44 :                           case FLOAT_EXPR:
    6463                 :             :                             /* For division, modulo and casts to floating
    6464                 :             :                                point, avoid representing unsigned operands
    6465                 :             :                                using negative prec if they were sign-extended
    6466                 :             :                                from narrower precision.  */
    6467                 :          44 :                             if (TYPE_UNSIGNED (TREE_TYPE (s))
    6468                 :          19 :                                 && !TYPE_UNSIGNED (TREE_TYPE (rhs1))
    6469                 :          46 :                                 && (TYPE_PRECISION (TREE_TYPE (s))
    6470                 :           2 :                                     > TYPE_PRECISION (TREE_TYPE (rhs1))))
    6471                 :           1 :                               goto force_name;
    6472                 :             :                             /* FALLTHRU */
    6473                 :          94 :                           case MULT_EXPR:
    6474                 :          94 :                             if (TREE_CODE (TREE_TYPE (rhs1)) != BITINT_TYPE
    6475                 :          94 :                                 || (bitint_precision_kind (TREE_TYPE (rhs1))
    6476                 :             :                                     < bitint_prec_large))
    6477                 :          31 :                               continue;
    6478                 :             :                             /* Uses which use handle_operand_addr can't
    6479                 :             :                                deal with nested casts.  */
    6480                 :          63 :                             if (TREE_CODE (rhs1) == SSA_NAME
    6481                 :          63 :                                 && gimple_assign_cast_p
    6482                 :          63 :                                      (SSA_NAME_DEF_STMT (rhs1))
    6483                 :          43 :                                 && has_single_use (rhs1)
    6484                 :         106 :                                 && (gimple_bb (SSA_NAME_DEF_STMT (rhs1))
    6485                 :          43 :                                     == gimple_bb (SSA_NAME_DEF_STMT (s))))
    6486                 :          43 :                               goto force_name;
    6487                 :             :                             break;
    6488                 :           0 :                           case VIEW_CONVERT_EXPR:
    6489                 :           0 :                             {
    6490                 :           0 :                               tree lhs = gimple_assign_lhs (use_stmt);
    6491                 :             :                               /* Don't merge with VIEW_CONVERT_EXPRs to
    6492                 :             :                                  non-integral types.  */
    6493                 :           0 :                               if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)))
    6494                 :           0 :                                 goto force_name;
    6495                 :             :                               /* Don't merge with VIEW_CONVERT_EXPRs to
    6496                 :             :                                  huge INTEGER_TYPEs used sometimes in memcpy
    6497                 :             :                                  expansion.  */
    6498                 :           0 :                               if (TREE_CODE (TREE_TYPE (lhs)) == INTEGER_TYPE
    6499                 :           0 :                                   && (TYPE_PRECISION (TREE_TYPE (lhs))
    6500                 :           0 :                                       > MAX_FIXED_MODE_SIZE))
    6501                 :           0 :                                 goto force_name;
    6502                 :             :                             }
    6503                 :             :                             break;
    6504                 :             :                           default:
    6505                 :             :                             break;
    6506                 :             :                         }
    6507                 :         557 :                       if (TREE_CODE (TREE_TYPE (rhs1)) != BITINT_TYPE
    6508                 :         557 :                           || (bitint_precision_kind (TREE_TYPE (rhs1))
    6509                 :             :                               < bitint_prec_large))
    6510                 :         219 :                         continue;
    6511                 :         338 :                       if ((TYPE_PRECISION (TREE_TYPE (rhs1))
    6512                 :         338 :                            >= TYPE_PRECISION (TREE_TYPE (s)))
    6513                 :         338 :                           && mergeable_op (use_stmt))
    6514                 :          59 :                         continue;
    6515                 :             :                       /* Prevent merging a widening non-mergeable cast
    6516                 :             :                          on result of some narrower mergeable op
    6517                 :             :                          together with later mergeable operations.  E.g.
    6518                 :             :                          result of _BitInt(223) addition shouldn't be
    6519                 :             :                          sign-extended to _BitInt(513) and have another
    6520                 :             :                          _BitInt(513) added to it, as handle_plus_minus
    6521                 :             :                          with its PHI node handling inside of handle_cast
    6522                 :             :                          will not work correctly.  An exception is if
    6523                 :             :                          use_stmt is a store, this is handled directly
    6524                 :             :                          in lower_mergeable_stmt.  */
    6525                 :         551 :                       if (TREE_CODE (rhs1) != SSA_NAME
    6526                 :         279 :                           || !has_single_use (rhs1)
    6527                 :         193 :                           || (gimple_bb (SSA_NAME_DEF_STMT (rhs1))
    6528                 :         193 :                               != gimple_bb (SSA_NAME_DEF_STMT (s)))
    6529                 :         153 :                           || !mergeable_op (SSA_NAME_DEF_STMT (rhs1))
    6530                 :         314 :                           || gimple_store_p (use_stmt))
    6531                 :         272 :                         continue;
    6532                 :           7 :                       if ((TYPE_PRECISION (TREE_TYPE (rhs1))
    6533                 :           7 :                            < TYPE_PRECISION (TREE_TYPE (s)))
    6534                 :           9 :                           && gimple_assign_cast_p (SSA_NAME_DEF_STMT (rhs1)))
    6535                 :             :                         {
    6536                 :             :                           /* Another exception is if the widening cast is
    6537                 :             :                              from mergeable same precision cast from something
    6538                 :             :                              not mergeable.  */
    6539                 :           0 :                           tree rhs2
    6540                 :           0 :                             = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (rhs1));
    6541                 :           0 :                           if (TREE_CODE (TREE_TYPE (rhs2)) == BITINT_TYPE
    6542                 :           0 :                               && (TYPE_PRECISION (TREE_TYPE (rhs1))
    6543                 :           0 :                                   == TYPE_PRECISION (TREE_TYPE (rhs2))))
    6544                 :             :                             {
    6545                 :           0 :                               if (TREE_CODE (rhs2) != SSA_NAME
    6546                 :           0 :                                   || !has_single_use (rhs2)
    6547                 :           0 :                                   || (gimple_bb (SSA_NAME_DEF_STMT (rhs2))
    6548                 :           0 :                                       != gimple_bb (SSA_NAME_DEF_STMT (s)))
    6549                 :           0 :                                   || !mergeable_op (SSA_NAME_DEF_STMT (rhs2)))
    6550                 :           0 :                                 continue;
    6551                 :             :                             }
    6552                 :             :                         }
    6553                 :             :                     }
    6554                 :             :                 }
    6555                 :        7002 :               if (is_gimple_assign (SSA_NAME_DEF_STMT (s)))
    6556                 :        4975 :                 switch (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (s)))
    6557                 :             :                   {
    6558                 :        1628 :                   case IMAGPART_EXPR:
    6559                 :        1628 :                     {
    6560                 :        1628 :                       tree rhs1 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s));
    6561                 :        1628 :                       rhs1 = TREE_OPERAND (rhs1, 0);
    6562                 :        1628 :                       if (TREE_CODE (rhs1) == SSA_NAME)
    6563                 :             :                         {
    6564                 :        1628 :                           gimple *g = SSA_NAME_DEF_STMT (rhs1);
    6565                 :        1628 :                           if (optimizable_arith_overflow (g))
    6566                 :        1625 :                             continue;
    6567                 :             :                         }
    6568                 :             :                     }
    6569                 :             :                     /* FALLTHRU */
    6570                 :         589 :                   case LSHIFT_EXPR:
    6571                 :         589 :                   case RSHIFT_EXPR:
    6572                 :         589 :                   case MULT_EXPR:
    6573                 :         589 :                   case TRUNC_DIV_EXPR:
    6574                 :         589 :                   case TRUNC_MOD_EXPR:
    6575                 :         589 :                   case FIX_TRUNC_EXPR:
    6576                 :         589 :                   case REALPART_EXPR:
    6577                 :         589 :                     if (gimple_store_p (use_stmt)
    6578                 :         315 :                         && is_gimple_assign (use_stmt)
    6579                 :         315 :                         && !gimple_has_volatile_ops (use_stmt)
    6580                 :         904 :                         && !stmt_ends_bb_p (use_stmt))
    6581                 :             :                       {
    6582                 :         315 :                         tree lhs = gimple_assign_lhs (use_stmt);
    6583                 :             :                         /* As multiply/division passes address of the lhs
    6584                 :             :                            to library function and that assumes it can extend
    6585                 :             :                            it to whole number of limbs, avoid merging those
    6586                 :             :                            with bit-field stores.  Don't allow it for
    6587                 :             :                            shifts etc. either, so that the bit-field store
    6588                 :             :                            handling doesn't have to be done everywhere.  */
    6589                 :         315 :                         if (TREE_CODE (lhs) == COMPONENT_REF
    6590                 :         315 :                             && DECL_BIT_FIELD_TYPE (TREE_OPERAND (lhs, 1)))
    6591                 :             :                           break;
    6592                 :         312 :                         continue;
    6593                 :         312 :                       }
    6594                 :             :                     break;
    6595                 :             :                   default:
    6596                 :             :                     break;
    6597                 :             :                   }
    6598                 :             :             }
    6599                 :             : 
    6600                 :             :           /* Also ignore uninitialized uses.  */
    6601                 :       27846 :           if (SSA_NAME_IS_DEFAULT_DEF (s)
    6602                 :       27846 :               && (!SSA_NAME_VAR (s) || VAR_P (SSA_NAME_VAR (s))))
    6603                 :          10 :             continue;
    6604                 :             : 
    6605                 :       27880 :         force_name:
    6606                 :       27880 :           if (!large_huge.m_names)
    6607                 :        5344 :             large_huge.m_names = BITMAP_ALLOC (NULL);
    6608                 :       27880 :           bitmap_set_bit (large_huge.m_names, SSA_NAME_VERSION (s));
    6609                 :       27880 :           if (has_single_use (s))
    6610                 :             :             {
    6611                 :       24465 :               if (!large_huge.m_single_use_names)
    6612                 :        5255 :                 large_huge.m_single_use_names = BITMAP_ALLOC (NULL);
    6613                 :       24465 :               bitmap_set_bit (large_huge.m_single_use_names,
    6614                 :       24465 :                               SSA_NAME_VERSION (s));
    6615                 :             :             }
    6616                 :       27880 :           if (SSA_NAME_VAR (s)
    6617                 :        6585 :               && ((TREE_CODE (SSA_NAME_VAR (s)) == PARM_DECL
    6618                 :        4814 :                    && SSA_NAME_IS_DEFAULT_DEF (s))
    6619                 :        1805 :                   || TREE_CODE (SSA_NAME_VAR (s)) == RESULT_DECL))
    6620                 :             :             has_large_huge_parm_result = true;
    6621                 :       27880 :           if (optimize
    6622                 :        9602 :               && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s)
    6623                 :        9580 :               && gimple_assign_load_p (SSA_NAME_DEF_STMT (s))
    6624                 :        5752 :               && !gimple_has_volatile_ops (SSA_NAME_DEF_STMT (s))
    6625                 :       30711 :               && !stmt_ends_bb_p (SSA_NAME_DEF_STMT (s)))
    6626                 :             :             {
    6627                 :        2831 :               use_operand_p use_p;
    6628                 :        2831 :               imm_use_iterator iter;
    6629                 :        2831 :               bool optimizable_load = true;
    6630                 :        5724 :               FOR_EACH_IMM_USE_FAST (use_p, iter, s)
    6631                 :             :                 {
    6632                 :        2988 :                   gimple *use_stmt = USE_STMT (use_p);
    6633                 :        2988 :                   if (is_gimple_debug (use_stmt))
    6634                 :           0 :                     continue;
    6635                 :        2988 :                   if (gimple_code (use_stmt) == GIMPLE_PHI
    6636                 :             :                       || is_gimple_call (use_stmt)
    6637                 :             :                       || gimple_code (use_stmt) == GIMPLE_ASM)
    6638                 :             :                     {
    6639                 :             :                       optimizable_load = false;
    6640                 :             :                       break;
    6641                 :             :                     }
    6642                 :             :                 }
    6643                 :             : 
    6644                 :        2831 :               ssa_op_iter oi;
    6645                 :        3871 :               FOR_EACH_SSA_USE_OPERAND (use_p, SSA_NAME_DEF_STMT (s),
    6646                 :             :                                         oi, SSA_OP_USE)
    6647                 :             :                 {
    6648                 :        1040 :                   tree s2 = USE_FROM_PTR (use_p);
    6649                 :        1040 :                   if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s2))
    6650                 :             :                     {
    6651                 :             :                       optimizable_load = false;
    6652                 :             :                       break;
    6653                 :             :                     }
    6654                 :             :                 }
    6655                 :             : 
    6656                 :        2831 :               if (optimizable_load && !stmt_ends_bb_p (SSA_NAME_DEF_STMT (s)))
    6657                 :             :                 {
    6658                 :        2736 :                   if (!large_huge.m_loads)
    6659                 :         255 :                     large_huge.m_loads = BITMAP_ALLOC (NULL);
    6660                 :        2736 :                   bitmap_set_bit (large_huge.m_loads, SSA_NAME_VERSION (s));
    6661                 :             :                 }
    6662                 :             :             }
    6663                 :             :         }
    6664                 :             :       /* We need to also rewrite stores of large/huge _BitInt INTEGER_CSTs
    6665                 :             :          into memory.  Such functions could have no large/huge SSA_NAMEs.  */
    6666                 :       54331 :       else if (SSA_NAME_IS_VIRTUAL_OPERAND (s))
    6667                 :             :         {
    6668                 :       38842 :           gimple *g = SSA_NAME_DEF_STMT (s);
    6669                 :       38842 :           if (is_gimple_assign (g) && gimple_store_p (g))
    6670                 :             :             {
    6671                 :       13064 :               tree t = gimple_assign_rhs1 (g);
    6672                 :       13064 :               if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE
    6673                 :       13064 :                   && bitint_precision_kind (TREE_TYPE (t)) >= bitint_prec_large)
    6674                 :             :                 has_large_huge = true;
    6675                 :             :             }
    6676                 :             :         }
    6677                 :             :     }
    6678                 :             : 
    6679                 :        6951 :   if (large_huge.m_names || has_large_huge)
    6680                 :             :     {
    6681                 :        5502 :       ret = TODO_update_ssa_only_virtuals | TODO_cleanup_cfg;
    6682                 :        5502 :       calculate_dominance_info (CDI_DOMINATORS);
    6683                 :        5502 :       if (optimize)
    6684                 :        2826 :         enable_ranger (cfun);
    6685                 :        5502 :       if (large_huge.m_loads)
    6686                 :             :         {
    6687                 :         255 :           basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun);
    6688                 :         255 :           entry->aux = NULL;
    6689                 :         255 :           bitint_dom_walker (large_huge.m_names,
    6690                 :         255 :                              large_huge.m_loads).walk (entry);
    6691                 :         255 :           bitmap_and_compl_into (large_huge.m_names, large_huge.m_loads);
    6692                 :         255 :           clear_aux_for_blocks ();
    6693                 :         255 :           BITMAP_FREE (large_huge.m_loads);
    6694                 :             :         }
    6695                 :        5502 :       large_huge.m_limb_type = build_nonstandard_integer_type (limb_prec, 1);
    6696                 :        5502 :       large_huge.m_limb_size
    6697                 :        5502 :         = tree_to_uhwi (TYPE_SIZE_UNIT (large_huge.m_limb_type));
    6698                 :             :     }
    6699                 :        6951 :   if (large_huge.m_names)
    6700                 :             :     {
    6701                 :        5344 :       large_huge.m_map
    6702                 :       10688 :         = init_var_map (num_ssa_names, NULL, large_huge.m_names);
    6703                 :        5344 :       coalesce_ssa_name (large_huge.m_map);
    6704                 :        5344 :       partition_view_normal (large_huge.m_map);
    6705                 :        5344 :       if (dump_file && (dump_flags & TDF_DETAILS))
    6706                 :             :         {
    6707                 :           0 :           fprintf (dump_file, "After Coalescing:\n");
    6708                 :           0 :           dump_var_map (dump_file, large_huge.m_map);
    6709                 :             :         }
    6710                 :        5344 :       large_huge.m_vars
    6711                 :        5344 :         = XCNEWVEC (tree, num_var_partitions (large_huge.m_map));
    6712                 :        5344 :       bitmap_iterator bi;
    6713                 :        5344 :       if (has_large_huge_parm_result)
    6714                 :       18333 :         EXECUTE_IF_SET_IN_BITMAP (large_huge.m_names, 0, i, bi)
    6715                 :             :           {
    6716                 :       14341 :             tree s = ssa_name (i);
    6717                 :       14341 :             if (SSA_NAME_VAR (s)
    6718                 :        5563 :                 && ((TREE_CODE (SSA_NAME_VAR (s)) == PARM_DECL
    6719                 :        4814 :                      && SSA_NAME_IS_DEFAULT_DEF (s))
    6720                 :         783 :                     || TREE_CODE (SSA_NAME_VAR (s)) == RESULT_DECL))
    6721                 :             :               {
    6722                 :        4780 :                 int p = var_to_partition (large_huge.m_map, s);
    6723                 :        4780 :                 if (large_huge.m_vars[p] == NULL_TREE)
    6724                 :             :                   {
    6725                 :        4780 :                     large_huge.m_vars[p] = SSA_NAME_VAR (s);
    6726                 :        4780 :                     mark_addressable (SSA_NAME_VAR (s));
    6727                 :             :                   }
    6728                 :             :               }
    6729                 :             :           }
    6730                 :        5344 :       tree atype = NULL_TREE;
    6731                 :        5344 :       if (dump_file && (dump_flags & TDF_DETAILS))
    6732                 :           0 :         fprintf (dump_file, "Mapping SSA_NAMEs to decls:\n");
    6733                 :       31009 :       EXECUTE_IF_SET_IN_BITMAP (large_huge.m_names, 0, i, bi)
    6734                 :             :         {
    6735                 :       25665 :           tree s = ssa_name (i);
    6736                 :       25665 :           int p = var_to_partition (large_huge.m_map, s);
    6737                 :       25665 :           if (large_huge.m_vars[p] == NULL_TREE)
    6738                 :             :             {
    6739                 :       18156 :               if (atype == NULL_TREE
    6740                 :       31722 :                   || !tree_int_cst_equal (TYPE_SIZE (atype),
    6741                 :       13566 :                                           TYPE_SIZE (TREE_TYPE (s))))
    6742                 :             :                 {
    6743                 :        7430 :                   unsigned HOST_WIDE_INT nelts
    6744                 :        7430 :                     = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (s))) / limb_prec;
    6745                 :        7430 :                   atype = build_array_type_nelts (large_huge.m_limb_type,
    6746                 :             :                                                   nelts);
    6747                 :             :                 }
    6748                 :       18156 :               large_huge.m_vars[p] = create_tmp_var (atype, "bitint");
    6749                 :       18156 :               mark_addressable (large_huge.m_vars[p]);
    6750                 :             :             }
    6751                 :       25665 :           if (dump_file && (dump_flags & TDF_DETAILS))
    6752                 :             :             {
    6753                 :           0 :               print_generic_expr (dump_file, s, TDF_SLIM);
    6754                 :           0 :               fprintf (dump_file, " -> ");
    6755                 :           0 :               print_generic_expr (dump_file, large_huge.m_vars[p], TDF_SLIM);
    6756                 :           0 :               fprintf (dump_file, "\n");
    6757                 :             :             }
    6758                 :             :         }
    6759                 :             :     }
    6760                 :             : 
    6761                 :       47487 :   FOR_EACH_BB_REVERSE_FN (bb, cfun)
    6762                 :             :     {
    6763                 :       40536 :       gimple_stmt_iterator prev;
    6764                 :      195116 :       for (gimple_stmt_iterator gsi = gsi_last_bb (bb); !gsi_end_p (gsi);
    6765                 :      114044 :            gsi = prev)
    6766                 :             :         {
    6767                 :      114044 :           prev = gsi;
    6768                 :      114044 :           gsi_prev (&prev);
    6769                 :      114044 :           ssa_op_iter iter;
    6770                 :      114044 :           gimple *stmt = gsi_stmt (gsi);
    6771                 :      114044 :           if (is_gimple_debug (stmt))
    6772                 :       73096 :             continue;
    6773                 :      109300 :           bitint_prec_kind kind = bitint_prec_small;
    6774                 :      109300 :           tree t;
    6775                 :      328563 :           FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, SSA_OP_ALL_OPERANDS)
    6776                 :      219263 :             if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE)
    6777                 :             :               {
    6778                 :       75183 :                 bitint_prec_kind this_kind
    6779                 :       75183 :                   = bitint_precision_kind (TREE_TYPE (t));
    6780                 :       75183 :                 kind = MAX (kind, this_kind);
    6781                 :             :               }
    6782                 :      109300 :           if (is_gimple_assign (stmt) && gimple_store_p (stmt))
    6783                 :             :             {
    6784                 :       15721 :               t = gimple_assign_rhs1 (stmt);
    6785                 :       15721 :               if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE)
    6786                 :             :                 {
    6787                 :       13598 :                   bitint_prec_kind this_kind
    6788                 :       13598 :                     = bitint_precision_kind (TREE_TYPE (t));
    6789                 :       13598 :                   kind = MAX (kind, this_kind);
    6790                 :             :                 }
    6791                 :             :             }
    6792                 :      109300 :           if (is_gimple_assign (stmt)
    6793                 :      109300 :               && gimple_assign_rhs_code (stmt) == FLOAT_EXPR)
    6794                 :             :             {
    6795                 :         127 :               t = gimple_assign_rhs1 (stmt);
    6796                 :         127 :               if (TREE_CODE (TREE_TYPE (t)) == BITINT_TYPE
    6797                 :         127 :                   && TREE_CODE (t) == INTEGER_CST)
    6798                 :             :                 {
    6799                 :           1 :                   bitint_prec_kind this_kind
    6800                 :           1 :                     = bitint_precision_kind (TREE_TYPE (t));
    6801                 :           1 :                   kind = MAX (kind, this_kind);
    6802                 :             :                 }
    6803                 :             :             }
    6804                 :      109300 :           if (is_gimple_call (stmt))
    6805                 :             :             {
    6806                 :       25081 :               t = gimple_call_lhs (stmt);
    6807                 :       25081 :               if (t && TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE)
    6808                 :             :                 {
    6809                 :        5141 :                   bitint_prec_kind this_kind = arith_overflow_arg_kind (stmt);
    6810                 :        5141 :                   kind = MAX (kind, this_kind);
    6811                 :        5141 :                   if (TREE_CODE (TREE_TYPE (TREE_TYPE (t))) == BITINT_TYPE)
    6812                 :             :                     {
    6813                 :        5036 :                       this_kind
    6814                 :        5036 :                         = bitint_precision_kind (TREE_TYPE (TREE_TYPE (t)));
    6815                 :        5036 :                       kind = MAX (kind, this_kind);
    6816                 :             :                     }
    6817                 :             :                 }
    6818                 :             :             }
    6819                 :      109300 :           if (kind == bitint_prec_small)
    6820                 :       42384 :             continue;
    6821                 :       66916 :           switch (gimple_code (stmt))
    6822                 :             :             {
    6823                 :       10815 :             case GIMPLE_CALL:
    6824                 :             :               /* For now.  We'll need to handle some internal functions and
    6825                 :             :                  perhaps some builtins.  */
    6826                 :       10815 :               if (kind == bitint_prec_middle)
    6827                 :        2268 :                 continue;
    6828                 :             :               break;
    6829                 :           4 :             case GIMPLE_ASM:
    6830                 :           4 :               if (kind == bitint_prec_middle)
    6831                 :           1 :                 continue;
    6832                 :             :               break;
    6833                 :        1113 :             case GIMPLE_RETURN:
    6834                 :        1113 :               continue;
    6835                 :       46689 :             case GIMPLE_ASSIGN:
    6836                 :       46689 :               if (gimple_clobber_p (stmt))
    6837                 :        3504 :                 continue;
    6838                 :       43185 :               if (kind >= bitint_prec_large)
    6839                 :             :                 break;
    6840                 :        8726 :               if (gimple_assign_single_p (stmt))
    6841                 :             :                 /* No need to lower copies, loads or stores.  */
    6842                 :        5832 :                 continue;
    6843                 :        2894 :               if (gimple_assign_cast_p (stmt))
    6844                 :             :                 {
    6845                 :        2354 :                   tree lhs = gimple_assign_lhs (stmt);
    6846                 :        2354 :                   tree rhs = gimple_assign_rhs1 (stmt);
    6847                 :        4708 :                   if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    6848                 :        2354 :                       && INTEGRAL_TYPE_P (TREE_TYPE (rhs))
    6849                 :        4704 :                       && (TYPE_PRECISION (TREE_TYPE (lhs))
    6850                 :        2350 :                           == TYPE_PRECISION (TREE_TYPE (rhs))))
    6851                 :             :                     /* No need to lower casts to same precision.  */
    6852                 :          28 :                     continue;
    6853                 :             :                 }
    6854                 :             :               break;
    6855                 :             :             default:
    6856                 :             :               break;
    6857                 :        1113 :             }
    6858                 :             : 
    6859                 :       11161 :           if (kind == bitint_prec_middle)
    6860                 :             :             {
    6861                 :        4975 :               tree type = NULL_TREE;
    6862                 :             :               /* Middle _BitInt(N) is rewritten to casts to INTEGER_TYPEs
    6863                 :             :                  with the same precision and back.  */
    6864                 :        4975 :               unsigned int nops = gimple_num_ops (stmt);
    6865                 :       16727 :               for (unsigned int i = is_gimple_assign (stmt) ? 1 : 0;
    6866                 :       16727 :                    i < nops; ++i)
    6867                 :       11752 :                 if (tree op = gimple_op (stmt, i))
    6868                 :             :                   {
    6869                 :        7542 :                     tree nop = maybe_cast_middle_bitint (&gsi, op, type);
    6870                 :        7542 :                     if (nop != op)
    6871                 :        6682 :                       gimple_set_op (stmt, i, nop);
    6872                 :         860 :                     else if (COMPARISON_CLASS_P (op))
    6873                 :             :                       {
    6874                 :           0 :                         TREE_OPERAND (op, 0)
    6875                 :           0 :                           = maybe_cast_middle_bitint (&gsi,
    6876                 :           0 :                                                       TREE_OPERAND (op, 0),
    6877                 :             :                                                       type);
    6878                 :           0 :                         TREE_OPERAND (op, 1)
    6879                 :           0 :                           = maybe_cast_middle_bitint (&gsi,
    6880                 :           0 :                                                       TREE_OPERAND (op, 1),
    6881                 :             :                                                       type);
    6882                 :             :                       }
    6883                 :         860 :                     else if (TREE_CODE (op) == CASE_LABEL_EXPR)
    6884                 :             :                       {
    6885                 :          24 :                         CASE_LOW (op)
    6886                 :          24 :                           = maybe_cast_middle_bitint (&gsi, CASE_LOW (op),
    6887                 :             :                                                       type);
    6888                 :          48 :                         CASE_HIGH (op)
    6889                 :          48 :                           = maybe_cast_middle_bitint (&gsi, CASE_HIGH (op),
    6890                 :             :                                                       type);
    6891                 :             :                       }
    6892                 :             :                   }
    6893                 :        4975 :               if (tree lhs = gimple_get_lhs (stmt))
    6894                 :        2866 :                 if (TREE_CODE (TREE_TYPE (lhs)) == BITINT_TYPE
    6895                 :        2866 :                     && (bitint_precision_kind (TREE_TYPE (lhs))
    6896                 :             :                         == bitint_prec_middle))
    6897                 :             :                   {
    6898                 :        1335 :                     int prec = TYPE_PRECISION (TREE_TYPE (lhs));
    6899                 :        1335 :                     int uns = TYPE_UNSIGNED (TREE_TYPE (lhs));
    6900                 :        1335 :                     type = build_nonstandard_integer_type (prec, uns);
    6901                 :        1335 :                     tree lhs2 = make_ssa_name (type);
    6902                 :        1335 :                     gimple_set_lhs (stmt, lhs2);
    6903                 :        1335 :                     gimple *g = gimple_build_assign (lhs, NOP_EXPR, lhs2);
    6904                 :        1335 :                     if (stmt_ends_bb_p (stmt))
    6905                 :             :                       {
    6906                 :           2 :                         edge e = find_fallthru_edge (gsi_bb (gsi)->succs);
    6907                 :           2 :                         gsi_insert_on_edge_immediate (e, g);
    6908                 :             :                       }
    6909                 :             :                     else
    6910                 :        1333 :                       gsi_insert_after (&gsi, g, GSI_SAME_STMT);
    6911                 :             :                   }
    6912                 :        4975 :               update_stmt (stmt);
    6913                 :        4975 :               continue;
    6914                 :        4975 :             }
    6915                 :             : 
    6916                 :       49195 :           if (tree lhs = gimple_get_lhs (stmt))
    6917                 :       42881 :             if (TREE_CODE (lhs) == SSA_NAME)
    6918                 :             :               {
    6919                 :       34363 :                 tree type = TREE_TYPE (lhs);
    6920                 :       34363 :                 if (TREE_CODE (type) == COMPLEX_TYPE)
    6921                 :        4031 :                   type = TREE_TYPE (type);
    6922                 :       42610 :                 if (TREE_CODE (type) == BITINT_TYPE
    6923                 :       29142 :                     && bitint_precision_kind (type) >= bitint_prec_large
    6924                 :       63322 :                     && (large_huge.m_names == NULL
    6925                 :       28818 :                         || !bitmap_bit_p (large_huge.m_names,
    6926                 :       28818 :                                           SSA_NAME_VERSION (lhs))))
    6927                 :        8247 :                   continue;
    6928                 :             :               }
    6929                 :             : 
    6930                 :       40948 :           large_huge.lower_stmt (stmt);
    6931                 :             :         }
    6932                 :             : 
    6933                 :       40536 :       tree atype = NULL_TREE;
    6934                 :       48989 :       for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
    6935                 :        8453 :            gsi_next (&gsi))
    6936                 :             :         {
    6937                 :        8453 :           gphi *phi = gsi.phi ();
    6938                 :        8453 :           tree lhs = gimple_phi_result (phi);
    6939                 :        8453 :           if (TREE_CODE (TREE_TYPE (lhs)) != BITINT_TYPE
    6940                 :        8453 :               || bitint_precision_kind (TREE_TYPE (lhs)) < bitint_prec_large)
    6941                 :        8316 :             continue;
    6942                 :         137 :           int p1 = var_to_partition (large_huge.m_map, lhs);
    6943                 :         137 :           gcc_assert (large_huge.m_vars[p1] != NULL_TREE);
    6944                 :             :           tree v1 = large_huge.m_vars[p1];
    6945                 :         525 :           for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i)
    6946                 :             :             {
    6947                 :         388 :               tree arg = gimple_phi_arg_def (phi, i);
    6948                 :         388 :               edge e = gimple_phi_arg_edge (phi, i);
    6949                 :         388 :               gimple *g;
    6950                 :         388 :               switch (TREE_CODE (arg))
    6951                 :             :                 {
    6952                 :          61 :                 case INTEGER_CST:
    6953                 :          61 :                   if (integer_zerop (arg) && VAR_P (v1))
    6954                 :             :                     {
    6955                 :          44 :                       tree zero = build_zero_cst (TREE_TYPE (v1));
    6956                 :          44 :                       g = gimple_build_assign (v1, zero);
    6957                 :          44 :                       gsi_insert_on_edge (e, g);
    6958                 :          44 :                       edge_insertions = true;
    6959                 :         122 :                       break;
    6960                 :             :                     }
    6961                 :          17 :                   int ext;
    6962                 :          17 :                   unsigned int min_prec, prec, rem;
    6963                 :          17 :                   tree c;
    6964                 :          17 :                   prec = TYPE_PRECISION (TREE_TYPE (arg));
    6965                 :          17 :                   rem = prec % (2 * limb_prec);
    6966                 :          17 :                   min_prec = bitint_min_cst_precision (arg, ext);
    6967                 :          17 :                   if (min_prec > prec - rem - 2 * limb_prec
    6968                 :           7 :                       && min_prec > (unsigned) limb_prec)
    6969                 :             :                     /* Constant which has enough significant bits that it
    6970                 :             :                        isn't worth trying to save .rodata space by extending
    6971                 :             :                        from smaller number.  */
    6972                 :             :                     min_prec = prec;
    6973                 :             :                   else
    6974                 :          13 :                     min_prec = CEIL (min_prec, limb_prec) * limb_prec;
    6975                 :          17 :                   if (min_prec == 0)
    6976                 :             :                     c = NULL_TREE;
    6977                 :          14 :                   else if (min_prec == prec)
    6978                 :           4 :                     c = tree_output_constant_def (arg);
    6979                 :          10 :                   else if (min_prec == (unsigned) limb_prec)
    6980                 :           7 :                     c = fold_convert (large_huge.m_limb_type, arg);
    6981                 :             :                   else
    6982                 :             :                     {
    6983                 :           3 :                       tree ctype = build_bitint_type (min_prec, 1);
    6984                 :           3 :                       c = tree_output_constant_def (fold_convert (ctype, arg));
    6985                 :             :                     }
    6986                 :          14 :                   if (c)
    6987                 :             :                     {
    6988                 :          14 :                       if (VAR_P (v1) && min_prec == prec)
    6989                 :             :                         {
    6990                 :           4 :                           tree v2 = build1 (VIEW_CONVERT_EXPR,
    6991                 :           4 :                                             TREE_TYPE (v1), c);
    6992                 :           4 :                           g = gimple_build_assign (v1, v2);
    6993                 :           4 :                           gsi_insert_on_edge (e, g);
    6994                 :           4 :                           edge_insertions = true;
    6995                 :           4 :                           break;
    6996                 :             :                         }
    6997                 :          10 :                       if (TREE_CODE (TREE_TYPE (c)) == INTEGER_TYPE)
    6998                 :           7 :                         g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR,
    6999                 :           7 :                                                          TREE_TYPE (c), v1),
    7000                 :             :                                                  c);
    7001                 :             :                       else
    7002                 :             :                         {
    7003                 :           3 :                           unsigned HOST_WIDE_INT nelts
    7004                 :           3 :                             = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (c)))
    7005                 :           3 :                               / limb_prec;
    7006                 :           3 :                           tree vtype
    7007                 :           3 :                             = build_array_type_nelts (large_huge.m_limb_type,
    7008                 :             :                                                       nelts);
    7009                 :           3 :                           g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR,
    7010                 :             :                                                            vtype, v1),
    7011                 :             :                                                    build1 (VIEW_CONVERT_EXPR,
    7012                 :             :                                                            vtype, c));
    7013                 :             :                         }
    7014                 :          10 :                       gsi_insert_on_edge (e, g);
    7015                 :             :                     }
    7016                 :          13 :                   if (ext == 0)
    7017                 :             :                     {
    7018                 :           8 :                       unsigned HOST_WIDE_INT nelts
    7019                 :           8 :                         = (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (v1)))
    7020                 :           8 :                            - min_prec) / limb_prec;
    7021                 :           8 :                       tree vtype
    7022                 :           8 :                         = build_array_type_nelts (large_huge.m_limb_type,
    7023                 :             :                                                   nelts);
    7024                 :           8 :                       tree ptype = build_pointer_type (TREE_TYPE (v1));
    7025                 :           8 :                       tree off;
    7026                 :           8 :                       if (c)
    7027                 :           7 :                         off = fold_convert (ptype,
    7028                 :             :                                             TYPE_SIZE_UNIT (TREE_TYPE (c)));
    7029                 :             :                       else
    7030                 :           1 :                         off = build_zero_cst (ptype);
    7031                 :           8 :                       tree vd = build2 (MEM_REF, vtype,
    7032                 :             :                                         build_fold_addr_expr (v1), off);
    7033                 :           8 :                       g = gimple_build_assign (vd, build_zero_cst (vtype));
    7034                 :             :                     }
    7035                 :             :                   else
    7036                 :             :                     {
    7037                 :           5 :                       tree vd = v1;
    7038                 :           5 :                       if (c)
    7039                 :             :                         {
    7040                 :           3 :                           tree ptype = build_pointer_type (TREE_TYPE (v1));
    7041                 :           3 :                           tree off
    7042                 :           3 :                             = fold_convert (ptype,
    7043                 :             :                                             TYPE_SIZE_UNIT (TREE_TYPE (c)));
    7044                 :           3 :                           vd = build2 (MEM_REF, large_huge.m_limb_type,
    7045                 :             :                                        build_fold_addr_expr (v1), off);
    7046                 :             :                         }
    7047                 :           5 :                       vd = build_fold_addr_expr (vd);
    7048                 :           5 :                       unsigned HOST_WIDE_INT nbytes
    7049                 :           5 :                         = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (v1)));
    7050                 :           5 :                       if (c)
    7051                 :           3 :                         nbytes
    7052                 :           3 :                           -= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (c)));
    7053                 :           5 :                       tree fn = builtin_decl_implicit (BUILT_IN_MEMSET);
    7054                 :           5 :                       g = gimple_build_call (fn, 3, vd,
    7055                 :             :                                              integer_minus_one_node,
    7056                 :             :                                              build_int_cst (sizetype,
    7057                 :             :                                                             nbytes));
    7058                 :             :                     }
    7059                 :          13 :                   gsi_insert_on_edge (e, g);
    7060                 :          13 :                   edge_insertions = true;
    7061                 :          13 :                   break;
    7062                 :           0 :                 default:
    7063                 :           0 :                   gcc_unreachable ();
    7064                 :         327 :                 case SSA_NAME:
    7065                 :         327 :                   if (gimple_code (SSA_NAME_DEF_STMT (arg)) == GIMPLE_NOP)
    7066                 :             :                     {
    7067                 :          10 :                       if (large_huge.m_names == NULL
    7068                 :          18 :                           || !bitmap_bit_p (large_huge.m_names,
    7069                 :           9 :                                             SSA_NAME_VERSION (arg)))
    7070                 :         310 :                         continue;
    7071                 :             :                     }
    7072                 :         326 :                   int p2 = var_to_partition (large_huge.m_map, arg);
    7073                 :         326 :                   if (p1 == p2)
    7074                 :         309 :                     continue;
    7075                 :          17 :                   gcc_assert (large_huge.m_vars[p2] != NULL_TREE);
    7076                 :          17 :                   tree v2 = large_huge.m_vars[p2];
    7077                 :          17 :                   if (VAR_P (v1) && VAR_P (v2))
    7078                 :          17 :                     g = gimple_build_assign (v1, v2);
    7079                 :           0 :                   else if (VAR_P (v1))
    7080                 :           0 :                     g = gimple_build_assign (v1, build1 (VIEW_CONVERT_EXPR,
    7081                 :           0 :                                                          TREE_TYPE (v1), v2));
    7082                 :           0 :                   else if (VAR_P (v2))
    7083                 :           0 :                     g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR,
    7084                 :           0 :                                                      TREE_TYPE (v2), v1), v2);
    7085                 :             :                   else
    7086                 :             :                     {
    7087                 :           0 :                       if (atype == NULL_TREE
    7088                 :           0 :                           || !tree_int_cst_equal (TYPE_SIZE (atype),
    7089                 :           0 :                                                   TYPE_SIZE (TREE_TYPE (lhs))))
    7090                 :             :                         {
    7091                 :           0 :                           unsigned HOST_WIDE_INT nelts
    7092                 :           0 :                             = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs)))
    7093                 :           0 :                               / limb_prec;
    7094                 :           0 :                           atype
    7095                 :           0 :                             = build_array_type_nelts (large_huge.m_limb_type,
    7096                 :             :                                                       nelts);
    7097                 :             :                         }
    7098                 :           0 :                       g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR,
    7099                 :             :                                                        atype, v1),
    7100                 :             :                                                build1 (VIEW_CONVERT_EXPR,
    7101                 :             :                                                        atype, v2));
    7102                 :             :                     }
    7103                 :          17 :                   gsi_insert_on_edge (e, g);
    7104                 :          17 :                   edge_insertions = true;
    7105                 :          17 :                   break;
    7106                 :             :                 }
    7107                 :             :             }
    7108                 :             :         }
    7109                 :             :     }
    7110                 :             : 
    7111                 :        6951 :   if (large_huge.m_names || has_large_huge)
    7112                 :             :     {
    7113                 :        5502 :       gimple *nop = NULL;
    7114                 :      722062 :       for (i = 0; i < num_ssa_names; ++i)
    7115                 :             :         {
    7116                 :      355529 :           tree s = ssa_name (i);
    7117                 :      355529 :           if (s == NULL_TREE)
    7118                 :       14552 :             continue;
    7119                 :      340977 :           tree type = TREE_TYPE (s);
    7120                 :      340977 :           if (TREE_CODE (type) == COMPLEX_TYPE)
    7121                 :       16602 :             type = TREE_TYPE (type);
    7122                 :      340977 :           if (TREE_CODE (type) == BITINT_TYPE
    7123                 :      340977 :               && bitint_precision_kind (type) >= bitint_prec_large)
    7124                 :             :             {
    7125                 :       38578 :               if (large_huge.m_preserved
    7126                 :       43044 :                   && bitmap_bit_p (large_huge.m_preserved,
    7127                 :        6794 :                                    SSA_NAME_VERSION (s)))
    7128                 :        2328 :                 continue;
    7129                 :       33922 :               gimple *g = SSA_NAME_DEF_STMT (s);
    7130                 :       33922 :               if (gimple_code (g) == GIMPLE_NOP)
    7131                 :             :                 {
    7132                 :        8998 :                   if (SSA_NAME_VAR (s))
    7133                 :        4796 :                     set_ssa_default_def (cfun, SSA_NAME_VAR (s), NULL_TREE);
    7134                 :        8998 :                   release_ssa_name (s);
    7135                 :        8998 :                   continue;
    7136                 :             :                 }
    7137                 :       24924 :               if (gimple_bb (g) == NULL)
    7138                 :             :                 {
    7139                 :           2 :                   release_ssa_name (s);
    7140                 :           2 :                   continue;
    7141                 :             :                 }
    7142                 :       24922 :               if (gimple_code (g) != GIMPLE_ASM)
    7143                 :             :                 {
    7144                 :       24921 :                   gimple_stmt_iterator gsi = gsi_for_stmt (g);
    7145                 :       24921 :                   bool save_vta = flag_var_tracking_assignments;
    7146                 :       24921 :                   flag_var_tracking_assignments = false;
    7147                 :       24921 :                   gsi_remove (&gsi, true);
    7148                 :       24921 :                   flag_var_tracking_assignments = save_vta;
    7149                 :             :                 }
    7150                 :       24922 :               if (nop == NULL)
    7151                 :        4623 :                 nop = gimple_build_nop ();
    7152                 :       24922 :               SSA_NAME_DEF_STMT (s) = nop;
    7153                 :       24922 :               release_ssa_name (s);
    7154                 :             :             }
    7155                 :             :         }
    7156                 :        5502 :       if (optimize)
    7157                 :        2826 :         disable_ranger (cfun);
    7158                 :             :     }
    7159                 :             : 
    7160                 :        6951 :   if (edge_insertions)
    7161                 :          20 :     gsi_commit_edge_inserts ();
    7162                 :             : 
    7163                 :             :   /* Fix up arguments of ECF_RETURNS_TWICE calls.  Those were temporarily
    7164                 :             :      inserted before the call, but that is invalid IL, so move them to the
    7165                 :             :      right place and add corresponding PHIs.  */
    7166                 :        6951 :   if (!large_huge.m_returns_twice_calls.is_empty ())
    7167                 :             :     {
    7168                 :           9 :       auto_vec<gimple *, 16> arg_stmts;
    7169                 :          29 :       while (!large_huge.m_returns_twice_calls.is_empty ())
    7170                 :             :         {
    7171                 :          11 :           gimple *stmt = large_huge.m_returns_twice_calls.pop ();
    7172                 :          11 :           gimple_stmt_iterator gsi = gsi_after_labels (gimple_bb (stmt));
    7173                 :          36 :           while (gsi_stmt (gsi) != stmt)
    7174                 :             :             {
    7175                 :          25 :               if (is_gimple_debug (gsi_stmt (gsi)))
    7176                 :           2 :                 gsi_next (&gsi);
    7177                 :             :               else
    7178                 :             :                 {
    7179                 :          23 :                   arg_stmts.safe_push (gsi_stmt (gsi));
    7180                 :          23 :                   gsi_remove (&gsi, false);
    7181                 :             :                 }
    7182                 :             :             }
    7183                 :          11 :           gimple *g;
    7184                 :          11 :           basic_block bb = NULL;
    7185                 :          11 :           edge e = NULL, ead = NULL;
    7186                 :          34 :           FOR_EACH_VEC_ELT (arg_stmts, i, g)
    7187                 :             :             {
    7188                 :          23 :               gsi_safe_insert_before (&gsi, g);
    7189                 :          23 :               if (i == 0)
    7190                 :             :                 {
    7191                 :          11 :                   bb = gimple_bb (stmt);
    7192                 :          11 :                   gcc_checking_assert (EDGE_COUNT (bb->preds) == 2);
    7193                 :          11 :                   e = EDGE_PRED (bb, 0);
    7194                 :          11 :                   ead = EDGE_PRED (bb, 1);
    7195                 :          11 :                   if ((ead->flags & EDGE_ABNORMAL) == 0)
    7196                 :           0 :                     std::swap (e, ead);
    7197                 :          11 :                   gcc_checking_assert ((e->flags & EDGE_ABNORMAL) == 0
    7198                 :             :                                        && (ead->flags & EDGE_ABNORMAL));
    7199                 :             :                 }
    7200                 :          23 :               tree lhs = gimple_assign_lhs (g);
    7201                 :          23 :               tree arg = lhs;
    7202                 :          23 :               gphi *phi = create_phi_node (copy_ssa_name (arg), bb);
    7203                 :          23 :               add_phi_arg (phi, arg, e, UNKNOWN_LOCATION);
    7204                 :          23 :               tree var = create_tmp_reg (TREE_TYPE (arg));
    7205                 :          23 :               suppress_warning (var, OPT_Wuninitialized);
    7206                 :          23 :               arg = get_or_create_ssa_default_def (cfun, var);
    7207                 :          23 :               SSA_NAME_OCCURS_IN_ABNORMAL_PHI (arg) = 1;
    7208                 :          23 :               add_phi_arg (phi, arg, ead, UNKNOWN_LOCATION);
    7209                 :          23 :               arg = gimple_phi_result (phi);
    7210                 :          23 :               SSA_NAME_OCCURS_IN_ABNORMAL_PHI (arg) = 1;
    7211                 :          23 :               imm_use_iterator iter;
    7212                 :          23 :               gimple *use_stmt;
    7213                 :          69 :               FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
    7214                 :             :                 {
    7215                 :          46 :                   if (use_stmt == phi)
    7216                 :          23 :                     continue;
    7217                 :          23 :                   gcc_checking_assert (use_stmt == stmt);
    7218                 :          23 :                   use_operand_p use_p;
    7219                 :          69 :                   FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
    7220                 :          23 :                     SET_USE (use_p, arg);
    7221                 :          23 :                 }
    7222                 :             :             }
    7223                 :          11 :           update_stmt (stmt);
    7224                 :          11 :           arg_stmts.truncate (0);
    7225                 :             :         }
    7226                 :           9 :     }
    7227                 :             : 
    7228                 :        6951 :   return ret;
    7229                 :        6951 : }
    7230                 :             : 
    7231                 :             : namespace {
    7232                 :             : 
    7233                 :             : const pass_data pass_data_lower_bitint =
    7234                 :             : {
    7235                 :             :   GIMPLE_PASS, /* type */
    7236                 :             :   "bitintlower", /* name */
    7237                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    7238                 :             :   TV_NONE, /* tv_id */
    7239                 :             :   PROP_ssa, /* properties_required */
    7240                 :             :   PROP_gimple_lbitint, /* properties_provided */
    7241                 :             :   0, /* properties_destroyed */
    7242                 :             :   0, /* todo_flags_start */
    7243                 :             :   0, /* todo_flags_finish */
    7244                 :             : };
    7245                 :             : 
    7246                 :             : class pass_lower_bitint : public gimple_opt_pass
    7247                 :             : {
    7248                 :             : public:
    7249                 :      570378 :   pass_lower_bitint (gcc::context *ctxt)
    7250                 :     1140756 :     : gimple_opt_pass (pass_data_lower_bitint, ctxt)
    7251                 :             :   {}
    7252                 :             : 
    7253                 :             :   /* opt_pass methods: */
    7254                 :      285189 :   opt_pass * clone () final override { return new pass_lower_bitint (m_ctxt); }
    7255                 :      979599 :   unsigned int execute (function *) final override
    7256                 :             :   {
    7257                 :      979599 :     return gimple_lower_bitint ();
    7258                 :             :   }
    7259                 :             : 
    7260                 :             : }; // class pass_lower_bitint
    7261                 :             : 
    7262                 :             : } // anon namespace
    7263                 :             : 
    7264                 :             : gimple_opt_pass *
    7265                 :      285189 : make_pass_lower_bitint (gcc::context *ctxt)
    7266                 :             : {
    7267                 :      285189 :   return new pass_lower_bitint (ctxt);
    7268                 :             : }
    7269                 :             : 
    7270                 :             : 
    7271                 :             : namespace {
    7272                 :             : 
    7273                 :             : const pass_data pass_data_lower_bitint_O0 =
    7274                 :             : {
    7275                 :             :   GIMPLE_PASS, /* type */
    7276                 :             :   "bitintlower0", /* name */
    7277                 :             :   OPTGROUP_NONE, /* optinfo_flags */
    7278                 :             :   TV_NONE, /* tv_id */
    7279                 :             :   PROP_cfg, /* properties_required */
    7280                 :             :   PROP_gimple_lbitint, /* properties_provided */
    7281                 :             :   0, /* properties_destroyed */
    7282                 :             :   0, /* todo_flags_start */
    7283                 :             :   0, /* todo_flags_finish */
    7284                 :             : };
    7285                 :             : 
    7286                 :             : class pass_lower_bitint_O0 : public gimple_opt_pass
    7287                 :             : {
    7288                 :             : public:
    7289                 :      285189 :   pass_lower_bitint_O0 (gcc::context *ctxt)
    7290                 :      570378 :     : gimple_opt_pass (pass_data_lower_bitint_O0, ctxt)
    7291                 :             :   {}
    7292                 :             : 
    7293                 :             :   /* opt_pass methods: */
    7294                 :     1419128 :   bool gate (function *fun) final override
    7295                 :             :     {
    7296                 :             :       /* With errors, normal optimization passes are not run.  If we don't
    7297                 :             :          lower bitint operations at all, rtl expansion will abort.  */
    7298                 :     1419128 :       return !(fun->curr_properties & PROP_gimple_lbitint);
    7299                 :             :     }
    7300                 :             : 
    7301                 :      439624 :   unsigned int execute (function *) final override
    7302                 :             :   {
    7303                 :      439624 :     return gimple_lower_bitint ();
    7304                 :             :   }
    7305                 :             : 
    7306                 :             : }; // class pass_lower_bitint_O0
    7307                 :             : 
    7308                 :             : } // anon namespace
    7309                 :             : 
    7310                 :             : gimple_opt_pass *
    7311                 :      285189 : make_pass_lower_bitint_O0 (gcc::context *ctxt)
    7312                 :             : {
    7313                 :      285189 :   return new pass_lower_bitint_O0 (ctxt);
    7314                 :             : }
        

Generated by: LCOV version 2.1-beta

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.