LCOV - code coverage report
Current view: top level - gcc - gimple-lower-bitint.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 87.3 % 5855 5113
Test Date: 2026-12-05 16:10:02 Functions: 100.0 % 63 63
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Lower _BitInt(N) operations to scalar operations.
       2              :    Copyright (C) 2023-2026 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              : #include "attribs.h"
      60              : #include "asan.h"
      61              : #include "tree-outof-ssa.h"
      62              : 
      63              : /* Split BITINT_TYPE precisions in 4 categories.  Small _BitInt, where
      64              :    target hook says it is a single limb, middle _BitInt which per ABI
      65              :    does not, but there is some INTEGER_TYPE in which arithmetics can be
      66              :    performed (operations on such _BitInt are lowered to casts to that
      67              :    arithmetic type and cast back; e.g. on x86_64 limb is DImode, but
      68              :    target supports TImode, so _BitInt(65) to _BitInt(128) are middle
      69              :    ones), large _BitInt which should by straight line code and
      70              :    finally huge _BitInt which should be handled by loops over the limbs.  */
      71              : 
      72              : enum bitint_prec_kind {
      73              :   bitint_prec_small,
      74              :   bitint_prec_middle,
      75              :   bitint_prec_large,
      76              :   bitint_prec_huge
      77              : };
      78              : 
      79              : /* Caches to speed up bitint_precision_kind.  */
      80              : 
      81              : static int small_max_prec, mid_min_prec, large_min_prec, huge_min_prec;
      82              : static int limb_prec, abi_limb_prec;
      83              : static bool bitint_big_endian;
      84              : static enum bitint_ext bitint_extended;
      85              : 
      86              : /* Categorize _BitInt(PREC) as small, middle, large or huge.  */
      87              : 
      88              : static bitint_prec_kind
      89       535717 : bitint_precision_kind (int prec)
      90              : {
      91       535717 :   if (prec <= small_max_prec)
      92              :     return bitint_prec_small;
      93       513292 :   if (huge_min_prec && prec >= huge_min_prec)
      94              :     return bitint_prec_huge;
      95       281877 :   if (large_min_prec && prec >= large_min_prec)
      96              :     return bitint_prec_large;
      97        57700 :   if (mid_min_prec && prec >= mid_min_prec)
      98              :     return bitint_prec_middle;
      99              : 
     100        10881 :   struct bitint_info info;
     101        10881 :   bool ok = targetm.c.bitint_type_info (prec, &info);
     102        10881 :   gcc_assert (ok);
     103        10881 :   scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode);
     104        10881 :   if (prec <= GET_MODE_PRECISION (limb_mode))
     105              :     {
     106         2995 :       small_max_prec = prec;
     107         2995 :       return bitint_prec_small;
     108              :     }
     109         7886 :   bitint_big_endian = info.big_endian;
     110         7886 :   bitint_extended = info.extended;
     111         7886 :   if (info.limb_mode == info.abi_limb_mode && bitint_extended == bitint_ext_full)
     112            0 :     bitint_extended = bitint_ext_partial;
     113         7886 :   if (!large_min_prec
     114        15667 :       && GET_MODE_PRECISION (limb_mode) <= MAX_FIXED_MODE_SIZE)
     115        15562 :     large_min_prec = MAX_FIXED_MODE_SIZE + 1;
     116         7886 :   if (!limb_prec)
     117         7781 :     limb_prec = GET_MODE_PRECISION (limb_mode);
     118         7886 :   if (!abi_limb_prec)
     119         7781 :     abi_limb_prec
     120         7781 :       = GET_MODE_PRECISION (as_a <scalar_int_mode> (info.abi_limb_mode));
     121              :   /* For bitint_ext_full with different limb_mode from abi_limb_mode we
     122              :      currently only support only abi_limb_mode twice the precision of
     123              :      limb_mode, and don't support big endian in that case either.  */
     124         7886 :   gcc_assert (bitint_extended != bitint_ext_full
     125              :               || (abi_limb_prec == 2 * limb_prec
     126              :                   && !bitint_big_endian));
     127         7886 :   if (!huge_min_prec)
     128              :     {
     129        15562 :       if (4 * limb_prec >= MAX_FIXED_MODE_SIZE)
     130         7781 :         huge_min_prec = 4 * limb_prec;
     131              :       else
     132            0 :         huge_min_prec = MAX_FIXED_MODE_SIZE + 1;
     133              :     }
     134        15772 :   if (prec <= MAX_FIXED_MODE_SIZE)
     135              :     {
     136         1660 :       if (!mid_min_prec || prec < mid_min_prec)
     137         1660 :         mid_min_prec = prec;
     138              :       return bitint_prec_middle;
     139              :     }
     140         6226 :   if (huge_min_prec && prec >= huge_min_prec)
     141         2651 :     return bitint_prec_huge;
     142              :   return bitint_prec_large;
     143              : }
     144              : 
     145              : /* Same for a TYPE.  */
     146              : 
     147              : static bitint_prec_kind
     148       530251 : bitint_precision_kind (tree type)
     149              : {
     150       530251 :   return bitint_precision_kind (TYPE_PRECISION (type));
     151              : }
     152              : 
     153              : /* Return minimum precision needed to describe INTEGER_CST
     154              :    CST.  All bits above that precision up to precision of
     155              :    TREE_TYPE (CST) are cleared if EXT is set to 0, or set
     156              :    if EXT is set to -1.  */
     157              : 
     158              : static unsigned
     159         6177 : bitint_min_cst_precision (tree cst, int &ext)
     160              : {
     161         6177 :   ext = tree_int_cst_sgn (cst) < 0 ? -1 : 0;
     162         6177 :   wide_int w = wi::to_wide (cst);
     163         6177 :   unsigned min_prec = wi::min_precision (w, TYPE_SIGN (TREE_TYPE (cst)));
     164              :   /* For signed values, we don't need to count the sign bit,
     165              :      we'll use constant 0 or -1 for the upper bits.  */
     166         6177 :   if (!TYPE_UNSIGNED (TREE_TYPE (cst)))
     167         3401 :     --min_prec;
     168              :   else
     169              :     {
     170              :       /* For unsigned values, also try signed min_precision
     171              :          in case the constant has lots of most significant bits set.  */
     172         2776 :       unsigned min_prec2 = wi::min_precision (w, SIGNED) - 1;
     173         2776 :       if (min_prec2 < min_prec)
     174              :         {
     175         1053 :           ext = -1;
     176         1053 :           return min_prec2;
     177              :         }
     178              :     }
     179              :   return min_prec;
     180         6177 : }
     181              : 
     182              : namespace {
     183              : 
     184              : /* If OP is middle _BitInt, cast it to corresponding INTEGER_TYPE
     185              :    cached in TYPE and return it.  */
     186              : 
     187              : tree
     188         8141 : maybe_cast_middle_bitint (gimple_stmt_iterator *gsi, tree op, tree &type)
     189              : {
     190         8141 :   if (op == NULL_TREE
     191         8028 :       || !BITINT_TYPE_P (TREE_TYPE (op))
     192        15212 :       || bitint_precision_kind (TREE_TYPE (op)) != bitint_prec_middle)
     193              :     return op;
     194              : 
     195         7053 :   int prec = TYPE_PRECISION (TREE_TYPE (op));
     196         7053 :   int uns = TYPE_UNSIGNED (TREE_TYPE (op));
     197         7053 :   if (type == NULL_TREE
     198         2639 :       || TYPE_PRECISION (type) != prec
     199         9692 :       || TYPE_UNSIGNED (type) != uns)
     200         4414 :     type = build_nonstandard_integer_type (prec, uns);
     201              : 
     202         7053 :   if (TREE_CODE (op) != SSA_NAME)
     203              :     {
     204         2458 :       tree nop = fold_convert (type, op);
     205         2458 :       if (is_gimple_val (nop))
     206              :         return nop;
     207              :     }
     208              : 
     209         4595 :   tree nop = make_ssa_name (type);
     210         4595 :   gimple *g = gimple_build_assign (nop, NOP_EXPR, op);
     211         4595 :   gsi_insert_before (gsi, g, GSI_SAME_STMT);
     212         4595 :   return nop;
     213              : }
     214              : 
     215              : /* Return true if STMT can be handled in a loop from least to most
     216              :    significant limb together with its dependencies.  */
     217              : 
     218              : bool
     219        52228 : mergeable_op (gimple *stmt)
     220              : {
     221        52228 :   gassign *stmt_a = dyn_cast<gassign *> (stmt);
     222        42144 :   if (!stmt_a)
     223              :     return false;
     224        69617 :   switch (gimple_assign_rhs_code (stmt_a))
     225              :     {
     226              :     case PLUS_EXPR:
     227              :     case MINUS_EXPR:
     228              :     case NEGATE_EXPR:
     229              :     case BIT_AND_EXPR:
     230              :     case BIT_IOR_EXPR:
     231              :     case BIT_XOR_EXPR:
     232              :     case BIT_NOT_EXPR:
     233              :     case SSA_NAME:
     234              :     case INTEGER_CST:
     235              :     case BIT_FIELD_REF:
     236              :       return true;
     237          545 :     case LSHIFT_EXPR:
     238          545 :       {
     239          545 :         tree cnt = gimple_assign_rhs2 (stmt_a);
     240          545 :         if (tree_fits_uhwi_p (cnt)
     241          251 :             && tree_to_uhwi (cnt) < (unsigned HOST_WIDE_INT) limb_prec)
     242              :           return true;
     243              :       }
     244              :       break;
     245         7044 :     CASE_CONVERT:
     246         7044 :     case VIEW_CONVERT_EXPR:
     247         7044 :       {
     248         7044 :         tree lhs_type = TREE_TYPE (gimple_assign_lhs (stmt_a));
     249         7044 :         tree rhs_type = TREE_TYPE (gimple_assign_rhs1 (stmt_a));
     250         7044 :         if (TREE_CODE (gimple_assign_rhs1 (stmt_a)) == SSA_NAME
     251         7000 :             && BITINT_TYPE_P (lhs_type)
     252         4419 :             && BITINT_TYPE_P (rhs_type)
     253         3818 :             && bitint_precision_kind (lhs_type) >= bitint_prec_large
     254         3780 :             && bitint_precision_kind (rhs_type) >= bitint_prec_large
     255        10542 :             && (CEIL (TYPE_PRECISION (lhs_type), limb_prec)
     256         3498 :                 == CEIL (TYPE_PRECISION (rhs_type), limb_prec)))
     257              :           {
     258         2326 :             if (TYPE_PRECISION (rhs_type) >= TYPE_PRECISION (lhs_type))
     259              :               return true;
     260          210 :             if ((unsigned) TYPE_PRECISION (lhs_type) % (2 * limb_prec) != 0)
     261              :               return true;
     262           25 :             if (bitint_precision_kind (lhs_type) == bitint_prec_large)
     263              :               return true;
     264              :           }
     265              :         break;
     266              :       }
     267              :     default:
     268              :       break;
     269              :     }
     270              :   return false;
     271              : }
     272              : 
     273              : /* Return non-zero if stmt is .{ADD,SUB,MUL}_OVERFLOW call with
     274              :    _Complex large/huge _BitInt lhs which has at most two immediate uses,
     275              :    at most one use in REALPART_EXPR stmt in the same bb and exactly one
     276              :    IMAGPART_EXPR use in the same bb with a single use which casts it to
     277              :    non-BITINT_TYPE integral type.  If there is a REALPART_EXPR use,
     278              :    return 2.  Such cases (most common uses of those builtins) can be
     279              :    optimized by marking their lhs and lhs of IMAGPART_EXPR and maybe lhs
     280              :    of REALPART_EXPR as not needed to be backed up by a stack variable.
     281              :    For .UBSAN_CHECK_{ADD,SUB,MUL} return 3.  */
     282              : 
     283              : int
     284        24023 : optimizable_arith_overflow (gimple *stmt)
     285              : {
     286        24023 :   bool is_ubsan = false;
     287        24023 :   if (!is_gimple_call (stmt) || !gimple_call_internal_p (stmt))
     288              :     return false;
     289         5306 :   switch (gimple_call_internal_fn (stmt))
     290              :     {
     291              :     case IFN_ADD_OVERFLOW:
     292              :     case IFN_SUB_OVERFLOW:
     293              :     case IFN_MUL_OVERFLOW:
     294              :       break;
     295           63 :     case IFN_UBSAN_CHECK_ADD:
     296           63 :     case IFN_UBSAN_CHECK_SUB:
     297           63 :     case IFN_UBSAN_CHECK_MUL:
     298           63 :       is_ubsan = true;
     299           63 :       break;
     300              :     default:
     301              :       return 0;
     302              :     }
     303         5210 :   tree lhs = gimple_call_lhs (stmt);
     304         5210 :   if (!lhs)
     305              :     return 0;
     306         5210 :   if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
     307              :     return 0;
     308         5195 :   tree type = is_ubsan ? TREE_TYPE (lhs) : TREE_TYPE (TREE_TYPE (lhs));
     309            0 :   if (!BITINT_TYPE_P (type)
     310         5195 :       || bitint_precision_kind (type) < bitint_prec_large)
     311              :     return 0;
     312              : 
     313         5195 :   if (is_ubsan)
     314              :     {
     315           48 :       use_operand_p use_p;
     316           48 :       gimple *use_stmt;
     317           48 :       if (!single_imm_use (lhs, &use_p, &use_stmt)
     318           48 :           || gimple_bb (use_stmt) != gimple_bb (stmt)
     319           48 :           || !gimple_store_p (use_stmt)
     320           48 :           || !is_gimple_assign (use_stmt)
     321           48 :           || gimple_has_volatile_ops (use_stmt)
     322           96 :           || stmt_ends_bb_p (use_stmt))
     323            0 :         return 0;
     324              :       return 3;
     325              :     }
     326              : 
     327         5147 :   imm_use_iterator ui;
     328         5147 :   use_operand_p use_p;
     329         5147 :   int seen = 0;
     330         5147 :   gimple *realpart = NULL, *cast = NULL;
     331        14740 :   FOR_EACH_IMM_USE_FAST (use_p, ui, lhs)
     332              :     {
     333         9807 :       gimple *g = USE_STMT (use_p);
     334         9807 :       if (is_gimple_debug (g))
     335            0 :         continue;
     336        10021 :       gassign *use_g = dyn_cast<gassign *> (g);
     337         9807 :       if (!use_g || gimple_bb (g) != gimple_bb (stmt))
     338              :         return 0;
     339        19614 :       if (gimple_assign_rhs_code (use_g) == REALPART_EXPR)
     340              :         {
     341         4660 :           if ((seen & 1) != 0)
     342              :             return 0;
     343         4660 :           seen |= 1;
     344         4660 :           realpart = use_g;
     345              :         }
     346         5147 :       else if (gimple_assign_rhs_code (use_g) == IMAGPART_EXPR)
     347              :         {
     348         5147 :           if ((seen & 2) != 0)
     349          214 :             return 0;
     350         5147 :           seen |= 2;
     351              : 
     352         5147 :           use_operand_p use2_p;
     353         5147 :           gimple *use_stmt;
     354         5147 :           tree lhs2 = gimple_assign_lhs (use_g);
     355         5147 :           if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs2))
     356              :             return 0;
     357         5147 :           if (!single_imm_use (lhs2, &use2_p, &use_stmt)
     358         5147 :               || gimple_bb (use_stmt) != gimple_bb (stmt)
     359        10294 :               || !gimple_assign_cast_p (use_stmt))
     360              :             return 0;
     361              : 
     362         4937 :           lhs2 = gimple_assign_lhs (use_stmt);
     363         9874 :           if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs2))
     364         9874 :               || BITINT_TYPE_P (TREE_TYPE (lhs2)))
     365              :             return 0;
     366         4933 :           cast = use_stmt;
     367              :         }
     368              :       else
     369              :         return 0;
     370          214 :     }
     371         4933 :   if ((seen & 2) == 0)
     372              :     return 0;
     373         4933 :   if (seen == 3)
     374              :     {
     375              :       /* Punt if the cast stmt appears before realpart stmt, because
     376              :          if both appear, the lowering wants to emit all the code
     377              :          at the location of realpart stmt.  */
     378         4660 :       gimple_stmt_iterator gsi = gsi_for_stmt (realpart);
     379         4660 :       unsigned int cnt = 0;
     380         4663 :       do
     381              :         {
     382         4663 :           gsi_prev_nondebug (&gsi);
     383         4663 :           if (gsi_end_p (gsi) || gsi_stmt (gsi) == cast)
     384              :             return 0;
     385         4660 :           if (gsi_stmt (gsi) == stmt)
     386              :             return 2;
     387              :           /* If realpart is too far from stmt, punt as well.
     388              :              Usually it will appear right after it.  */
     389            3 :           if (++cnt == 32)
     390              :             return 0;
     391              :         }
     392              :       while (1);
     393              :     }
     394              :   return 1;
     395              : }
     396              : 
     397              : /* If STMT is some kind of comparison (GIMPLE_COND, comparison assignment)
     398              :    comparing large/huge _BitInt types, return the comparison code and if
     399              :    non-NULL fill in the comparison operands to *POP1 and *POP2.  */
     400              : 
     401              : tree_code
     402        37622 : comparison_op (gimple *stmt, tree *pop1, tree *pop2)
     403              : {
     404        37622 :   tree op1 = NULL_TREE, op2 = NULL_TREE;
     405        37622 :   tree_code code = ERROR_MARK;
     406        37622 :   if (gimple_code (stmt) == GIMPLE_COND)
     407              :     {
     408         7037 :       code = gimple_cond_code (stmt);
     409         7037 :       op1 = gimple_cond_lhs (stmt);
     410         7037 :       op2 = gimple_cond_rhs (stmt);
     411              :     }
     412        30585 :   else if (auto assign = dyn_cast<gassign *> (stmt))
     413              :     {
     414        30545 :       code = gimple_assign_rhs_code (assign);
     415        30545 :       op1 = gimple_assign_rhs1 (assign);
     416        30545 :       if (TREE_CODE_CLASS (code) == tcc_comparison
     417        30545 :           || TREE_CODE_CLASS (code) == tcc_binary)
     418         2825 :         op2 = gimple_assign_rhs2 (assign);
     419              :     }
     420        37622 :   if (TREE_CODE_CLASS (code) != tcc_comparison)
     421              :     return ERROR_MARK;
     422         7824 :   tree type = TREE_TYPE (op1);
     423           10 :   if (!BITINT_TYPE_P (type)
     424         7834 :       || bitint_precision_kind (type) < bitint_prec_large)
     425              :     return ERROR_MARK;
     426         7824 :   if (pop1)
     427              :     {
     428         7759 :       *pop1 = op1;
     429         7759 :       *pop2 = op2;
     430              :     }
     431              :   return code;
     432              : }
     433              : 
     434              : /* Class used during large/huge _BitInt lowering containing all the
     435              :    state for the methods.  */
     436              : 
     437              : struct bitint_large_huge
     438              : {
     439         7779 :   bitint_large_huge ()
     440         7779 :     : m_names (NULL), m_loads (NULL), m_preserved (NULL),
     441         7779 :       m_single_use_names (NULL), m_map (NULL), m_vars (NULL),
     442         7779 :       m_limb_type (NULL_TREE), m_data (vNULL),
     443         7779 :       m_returns_twice_calls (vNULL) {}
     444              : 
     445              :   ~bitint_large_huge ();
     446              : 
     447              :   void insert_before (gimple *);
     448              :   tree limb_access_type (tree, tree);
     449              :   tree limb_access (tree, tree, tree, bool, bool = false);
     450              :   tree build_bit_field_ref (tree, tree, unsigned HOST_WIDE_INT,
     451              :                             unsigned HOST_WIDE_INT);
     452              :   void if_then (gimple *, profile_probability, edge &, edge &);
     453              :   void if_then_else (gimple *, profile_probability, edge &, edge &);
     454              :   void if_then_if_then_else (gimple *g, gimple *,
     455              :                              profile_probability, profile_probability,
     456              :                              edge &, edge &, edge &);
     457              :   tree handle_operand (tree, tree);
     458              :   tree prepare_data_in_out (tree, tree, tree *, tree = NULL_TREE);
     459              :   tree add_cast (tree, tree);
     460              :   tree handle_plus_minus (tree_code, tree, tree, tree);
     461              :   tree handle_lshift (tree, tree, tree);
     462              :   tree handle_cast (tree, tree, tree);
     463              :   tree handle_bit_field_ref (tree, tree);
     464              :   tree handle_load (gimple *, tree);
     465              :   tree handle_stmt (gimple *, tree);
     466              :   tree handle_operand_addr (tree, gimple *, int *, int *);
     467              :   tree create_loop (tree, tree *);
     468              :   tree lower_mergeable_stmt (gimple *, tree_code &, tree, tree);
     469              :   tree lower_comparison_stmt (gimple *, tree_code &, tree, tree);
     470              :   void lower_shift_stmt (tree, gimple *);
     471              :   void lower_muldiv_stmt (tree, gimple *);
     472              :   void lower_float_conv_stmt (tree, gimple *);
     473              :   tree arith_overflow_extract_bits (unsigned int, unsigned int, tree,
     474              :                                     unsigned int, bool);
     475              :   void finish_arith_overflow (tree, tree, tree, tree, tree, tree, gimple *,
     476              :                               unsigned, tree_code);
     477              :   void lower_addsub_overflow (tree, gimple *);
     478              :   void lower_mul_overflow (tree, gimple *);
     479              :   void lower_cplxpart_stmt (tree, gimple *);
     480              :   void lower_complexexpr_stmt (gimple *);
     481              :   void lower_bit_query (gimple *);
     482              :   void lower_bswap_bitreverse (tree, gimple *);
     483              :   void lower_clmul (tree, gimple *);
     484              :   void lower_call (tree, gimple *);
     485              :   void lower_asm (gimple *);
     486              :   void lower_stmt (gimple *);
     487              : 
     488              :   /* Bitmap of large/huge _BitInt SSA_NAMEs except those can be
     489              :      merged with their uses.  */
     490              :   bitmap m_names;
     491              :   /* Subset of those for lhs of load statements.  These will be
     492              :      cleared in m_names if the loads will be mergeable with all
     493              :      their uses.  */
     494              :   bitmap m_loads;
     495              :   /* Bitmap of large/huge _BitInt SSA_NAMEs that should survive
     496              :      to later passes (arguments or return values of calls).  */
     497              :   bitmap m_preserved;
     498              :   /* Subset of m_names which have a single use.  As the lowering
     499              :      can replace various original statements with their lowered
     500              :      form even before it is done iterating over all basic blocks,
     501              :      testing has_single_use for the purpose of emitting clobbers
     502              :      doesn't work properly.  */
     503              :   bitmap m_single_use_names;
     504              :   /* Used for coalescing/partitioning of large/huge _BitInt SSA_NAMEs
     505              :      set in m_names.  */
     506              :   var_map m_map;
     507              :   /* Mapping of the partitions to corresponding decls.  */
     508              :   tree *m_vars;
     509              :   /* Unsigned integer type with limb precision.  */
     510              :   tree m_limb_type;
     511              :   /* Its TYPE_SIZE_UNIT.  */
     512              :   unsigned HOST_WIDE_INT m_limb_size;
     513              :   /* Location of a gimple stmt which is being currently lowered.  */
     514              :   location_t m_loc;
     515              :   /* Current stmt iterator where code is being lowered currently.  */
     516              :   gimple_stmt_iterator m_gsi;
     517              :   /* Statement after which any clobbers should be added if non-NULL.  */
     518              :   gimple *m_after_stmt;
     519              :   /* Set when creating loops to the loop header bb and its preheader.  */
     520              :   basic_block m_bb, m_preheader_bb;
     521              :   /* Stmt iterator after which initialization statements should be emitted.  */
     522              :   gimple_stmt_iterator m_init_gsi;
     523              :   /* Decl into which a mergeable statement stores result.  */
     524              :   tree m_lhs;
     525              :   /* handle_operand/handle_stmt can be invoked in various ways.
     526              : 
     527              :      lower_mergeable_stmt for large _BitInt calls those with constant
     528              :      idx only, expanding to straight line code, for huge _BitInt
     529              :      emits a loop from least significant limb upwards, where each loop
     530              :      iteration handles 2 limbs, plus there can be up to one full limb
     531              :      and one partial limb processed after the loop, where handle_operand
     532              :      and/or handle_stmt are called with constant idx.  m_upwards_2limb
     533              :      is set for this case, false otherwise.  m_upwards is true if it
     534              :      is either large or huge _BitInt handled by lower_mergeable_stmt,
     535              :      i.e. indexes always increase.
     536              : 
     537              :      Another way is used by lower_comparison_stmt, which walks limbs
     538              :      from most significant to least significant, partial limb if any
     539              :      processed first with constant idx and then loop processing a single
     540              :      limb per iteration with non-constant idx.
     541              : 
     542              :      Another way is used in lower_shift_stmt, where for LSHIFT_EXPR
     543              :      destination limbs are processed from most significant to least
     544              :      significant or for RSHIFT_EXPR the other way around, in loops or
     545              :      straight line code, but idx usually is non-constant (so from
     546              :      handle_operand/handle_stmt POV random access).  The LSHIFT_EXPR
     547              :      handling there can access even partial limbs using non-constant
     548              :      idx (then m_var_msb should be true, for all the other cases
     549              :      including lower_mergeable_stmt/lower_comparison_stmt that is
     550              :      not the case and so m_var_msb should be false.
     551              : 
     552              :      m_first should be set the first time handle_operand/handle_stmt
     553              :      is called and clear when it is called for some other limb with
     554              :      the same argument.  If the lowering of an operand (e.g. INTEGER_CST)
     555              :      or statement (e.g. +/-/<< with < limb_prec constant) needs some
     556              :      state between the different calls, when m_first is true it should
     557              :      push some trees to m_data vector and also make sure m_data_cnt is
     558              :      incremented by how many trees were pushed, and when m_first is
     559              :      false, it can use the m_data[m_data_cnt] etc. data or update them,
     560              :      just needs to bump m_data_cnt by the same amount as when it was
     561              :      called with m_first set.  The toplevel calls to
     562              :      handle_operand/handle_stmt should set m_data_cnt to 0 and truncate
     563              :      m_data vector when setting m_first to true.
     564              : 
     565              :      m_cast_conditional and m_bitfld_load are used when handling a
     566              :      bit-field load inside of a widening cast.  handle_cast sometimes
     567              :      needs to do runtime comparisons and handle_operand only conditionally
     568              :      or even in two separate conditional blocks for one idx (once with
     569              :      constant index after comparing the runtime one for equality with the
     570              :      constant).  In these cases, m_cast_conditional is set to true and
     571              :      the bit-field load then communicates its m_data_cnt to handle_cast
     572              :      using m_bitfld_load.  */
     573              :   bool m_first;
     574              :   bool m_var_msb;
     575              :   unsigned m_upwards_2limb;
     576              :   bool m_upwards;
     577              :   bool m_cast_conditional;
     578              :   unsigned m_bitfld_load;
     579              :   vec<tree> m_data;
     580              :   unsigned int m_data_cnt;
     581              :   vec<gimple *> m_returns_twice_calls;
     582              : };
     583              : 
     584         7779 : bitint_large_huge::~bitint_large_huge ()
     585              : {
     586         7779 :   BITMAP_FREE (m_names);
     587         7779 :   BITMAP_FREE (m_loads);
     588         7779 :   BITMAP_FREE (m_preserved);
     589         7779 :   BITMAP_FREE (m_single_use_names);
     590         7779 :   if (m_map)
     591         6068 :     delete_var_map (m_map);
     592         7779 :   XDELETEVEC (m_vars);
     593         7779 :   m_data.release ();
     594         7779 :   m_returns_twice_calls.release ();
     595         7779 : }
     596              : 
     597              : /* Insert gimple statement G before current location
     598              :    and set its gimple_location.  */
     599              : 
     600              : void
     601       389614 : bitint_large_huge::insert_before (gimple *g)
     602              : {
     603       389614 :   gimple_set_location (g, m_loc);
     604       389614 :   gsi_insert_before (&m_gsi, g, GSI_SAME_STMT);
     605       389614 : }
     606              : 
     607              : /* Return type for accessing limb IDX of BITINT_TYPE TYPE.
     608              :    This is normally m_limb_type, except for a partial most
     609              :    significant limb if any.  */
     610              : 
     611              : tree
     612       134646 : bitint_large_huge::limb_access_type (tree type, tree idx)
     613              : {
     614       134646 :   if (type == NULL_TREE)
     615         5956 :     return m_limb_type;
     616       128690 :   unsigned HOST_WIDE_INT i = tree_to_uhwi (idx);
     617       128690 :   unsigned int prec = TYPE_PRECISION (type);
     618       128690 :   gcc_assert (i * limb_prec < prec
     619              :               || (bitint_extended == bitint_ext_full
     620              :                   && abi_limb_prec > limb_prec
     621              :                   && i * limb_prec
     622              :                      < CEIL (prec, abi_limb_prec) * abi_limb_prec));
     623       257380 :   if (bitint_big_endian
     624       128690 :       ? (i != 0 || (prec % limb_prec) == 0)
     625       128690 :       : (i + 1) * limb_prec <= prec)
     626        82561 :     return m_limb_type;
     627              :   else
     628        92258 :     return build_nonstandard_integer_type (prec % limb_prec,
     629        46129 :                                            TYPE_UNSIGNED (type));
     630              : }
     631              : 
     632              : /* Return a tree how to access limb IDX of VAR corresponding to BITINT_TYPE
     633              :    TYPE.  If WRITE_P is true, it will be a store, otherwise a read.  */
     634              : 
     635              : tree
     636       164980 : bitint_large_huge::limb_access (tree type, tree var, tree idx, bool write_p,
     637              :                                 bool abi_load_p)
     638              : {
     639       164980 :   tree atype = (tree_fits_uhwi_p (idx)
     640       164980 :                 ? limb_access_type (type, idx) : m_limb_type);
     641              : 
     642       164980 :   tree ltype = (bitint_extended && abi_load_p) ? atype : m_limb_type;
     643              : 
     644       164980 :   addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (var));
     645       164980 :   tree ret;
     646       164980 :   if (DECL_P (var) && tree_fits_uhwi_p (idx))
     647              :     {
     648        98994 :       if (as != TYPE_ADDR_SPACE (ltype))
     649            0 :         ltype = build_qualified_type (ltype,
     650            0 :                                       TYPE_QUALS (ltype).with_as (as));
     651        98994 :       tree ptype = build_pointer_type (strip_array_types (TREE_TYPE (var)));
     652        98994 :       unsigned HOST_WIDE_INT off = tree_to_uhwi (idx) * m_limb_size;
     653        98994 :       if (bitint_big_endian)
     654            0 :         off += m_limb_size - tree_to_uhwi (TYPE_SIZE_UNIT (ltype));
     655        98994 :       ret = build2 (MEM_REF, ltype,
     656              :                     build_fold_addr_expr (var),
     657        98994 :                     build_int_cst (ptype, off));
     658        98994 :       TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (var);
     659        98994 :       TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (var);
     660        98994 :     }
     661        65986 :   else if (TREE_CODE (var) == MEM_REF && tree_fits_uhwi_p (idx))
     662              :     {
     663         4316 :       if (as != TYPE_ADDR_SPACE (ltype))
     664            0 :         ltype = build_qualified_type (ltype,
     665            0 :                                       TYPE_QUALS (ltype).with_as (as));
     666         4316 :       unsigned HOST_WIDE_INT off = tree_to_uhwi (idx) * m_limb_size;
     667         4316 :       if (bitint_big_endian)
     668            0 :         off += m_limb_size - tree_to_uhwi (TYPE_SIZE_UNIT (ltype));
     669         4316 :       ret
     670         8632 :         = build2 (MEM_REF, ltype, unshare_expr (TREE_OPERAND (var, 0)),
     671         8632 :                   size_binop (PLUS_EXPR, TREE_OPERAND (var, 1),
     672              :                               build_int_cst (TREE_TYPE (TREE_OPERAND (var, 1)),
     673              :                                              off)));
     674         4316 :       TREE_THIS_VOLATILE (ret) = TREE_THIS_VOLATILE (var);
     675         4316 :       TREE_SIDE_EFFECTS (ret) = TREE_SIDE_EFFECTS (var);
     676         4316 :       TREE_THIS_NOTRAP (ret) = TREE_THIS_NOTRAP (var);
     677         4316 :     }
     678              :   else
     679              :     {
     680        61670 :       ltype = m_limb_type;
     681        61670 :       if (as != TYPE_ADDR_SPACE (ltype))
     682           17 :         ltype = build_qualified_type (ltype,
     683           17 :                                       TYPE_QUALS (ltype).with_as (as));
     684        61670 :       var = unshare_expr (var);
     685        61670 :       if (TREE_CODE (TREE_TYPE (var)) != ARRAY_TYPE
     686        93599 :           || !useless_type_conversion_p (m_limb_type,
     687        31929 :                                          TREE_TYPE (TREE_TYPE (var))))
     688              :         {
     689        30758 :           unsigned HOST_WIDE_INT nelts
     690        30758 :             = CEIL (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (var))), limb_prec);
     691        30758 :           tree atype = build_array_type_nelts (ltype, nelts);
     692        30758 :           var = build1 (VIEW_CONVERT_EXPR, atype, var);
     693              :         }
     694        61670 :       ret = build4 (ARRAY_REF, ltype, var, idx, NULL_TREE, NULL_TREE);
     695              :     }
     696       164980 :   if (!write_p && !useless_type_conversion_p (atype, ltype))
     697              :     {
     698        20552 :       gassign *g = gimple_build_assign (make_ssa_name (m_limb_type), ret);
     699        20552 :       insert_before (g);
     700        20552 :       ret = gimple_assign_lhs (g);
     701        20552 :       ret = build1 (NOP_EXPR, atype, ret);
     702              :     }
     703       164980 :   return ret;
     704              : }
     705              : 
     706              : /* Build a BIT_FIELD_REF to access BITSIZE bits with FTYPE type at
     707              :    offset BITPOS inside of OBJ.  */
     708              : 
     709              : tree
     710          293 : bitint_large_huge::build_bit_field_ref (tree ftype, tree obj,
     711              :                                         unsigned HOST_WIDE_INT bitsize,
     712              :                                         unsigned HOST_WIDE_INT bitpos)
     713              : {
     714          586 :   if (INTEGRAL_TYPE_P (TREE_TYPE (obj))
     715          308 :       && !type_has_mode_precision_p (TREE_TYPE (obj)))
     716              :     {
     717           15 :       unsigned HOST_WIDE_INT nelts
     718           15 :         = CEIL (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (obj))), limb_prec);
     719           15 :       tree ltype = m_limb_type;
     720           15 :       addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (obj));
     721           15 :       if (as != TYPE_ADDR_SPACE (ltype))
     722            0 :         ltype = build_qualified_type (ltype,
     723            0 :                                       TYPE_QUALS (ltype).with_as (as));
     724           15 :       tree atype = build_array_type_nelts (ltype, nelts);
     725           15 :       obj = build1 (VIEW_CONVERT_EXPR, atype, obj);
     726              :     }
     727          293 :   return build3 (BIT_FIELD_REF, ftype, obj, bitsize_int (bitsize),
     728          293 :                  bitsize_int (bitpos));
     729              : }
     730              : 
     731              : /* Emit a half diamond,
     732              :    if (COND)
     733              :      |\
     734              :      | \
     735              :      |  \
     736              :      | new_bb1
     737              :      |  /
     738              :      | /
     739              :      |/
     740              :    or if (COND) new_bb1;
     741              :    PROB is the probability that the condition is true.
     742              :    Updates m_gsi to start of new_bb1.
     743              :    Sets EDGE_TRUE to edge from new_bb1 to successor and
     744              :    EDGE_FALSE to the EDGE_FALSE_VALUE edge from if (COND) bb.  */
     745              : 
     746              : void
     747         4687 : bitint_large_huge::if_then (gimple *cond, profile_probability prob,
     748              :                             edge &edge_true, edge &edge_false)
     749              : {
     750         4687 :   insert_before (cond);
     751         4687 :   edge e1 = split_block (gsi_bb (m_gsi), cond);
     752         4687 :   edge e2 = split_block (e1->dest, (gimple *) NULL);
     753         4687 :   edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE);
     754         4687 :   e1->flags = EDGE_TRUE_VALUE;
     755         4687 :   e1->probability = prob;
     756         4687 :   e3->probability = prob.invert ();
     757         4687 :   set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src);
     758         4687 :   edge_true = e2;
     759         4687 :   edge_false = e3;
     760         4687 :   m_gsi = gsi_after_labels (e1->dest);
     761         4687 : }
     762              : 
     763              : /* Emit a full diamond,
     764              :        if (COND)
     765              :          /\
     766              :         /  \
     767              :        /    \
     768              :    new_bb1 new_bb2
     769              :        \    /
     770              :         \  /
     771              :          \/
     772              :    or if (COND) new_bb2; else new_bb1;
     773              :    PROB is the probability that the condition is true.
     774              :    Updates m_gsi to start of new_bb2.
     775              :    Sets EDGE_TRUE to edge from new_bb1 to successor and
     776              :    EDGE_FALSE to the EDGE_FALSE_VALUE edge from if (COND) bb.  */
     777              : 
     778              : void
     779          119 : bitint_large_huge::if_then_else (gimple *cond, profile_probability prob,
     780              :                                  edge &edge_true, edge &edge_false)
     781              : {
     782          119 :   insert_before (cond);
     783          119 :   edge e1 = split_block (gsi_bb (m_gsi), cond);
     784          119 :   edge e2 = split_block (e1->dest, (gimple *) NULL);
     785          119 :   basic_block bb = create_empty_bb (e1->dest);
     786          119 :   add_bb_to_loop (bb, e1->dest->loop_father);
     787          119 :   edge e3 = make_edge (e1->src, bb, EDGE_TRUE_VALUE);
     788          119 :   e1->flags = EDGE_FALSE_VALUE;
     789          119 :   e3->probability = prob;
     790          119 :   e1->probability = prob.invert ();
     791          119 :   bb->count = e1->src->count.apply_probability (prob);
     792          119 :   set_immediate_dominator (CDI_DOMINATORS, bb, e1->src);
     793          119 :   set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src);
     794          119 :   edge_true = make_single_succ_edge (bb, e2->dest, EDGE_FALLTHRU);
     795          119 :   edge_false = e2;
     796          119 :   m_gsi = gsi_after_labels (bb);
     797          119 : }
     798              : 
     799              : /* Emit a half diamond with full diamond in it
     800              :    if (COND1)
     801              :      |\
     802              :      | \
     803              :      |  \
     804              :      | if (COND2)
     805              :      |    /  \
     806              :      |   /    \
     807              :      |new_bb1 new_bb2
     808              :      |   |    /
     809              :      \   |   /
     810              :       \  |  /
     811              :        \ | /
     812              :         \|/
     813              :    or if (COND1) { if (COND2) new_bb2; else new_bb1; }
     814              :    PROB1 is the probability that the condition 1 is true.
     815              :    PROB2 is the probability that the condition 2 is true.
     816              :    Updates m_gsi to start of new_bb1.
     817              :    Sets EDGE_TRUE_TRUE to edge from new_bb2 to successor,
     818              :    EDGE_TRUE_FALSE to edge from new_bb1 to successor and
     819              :    EDGE_FALSE to the EDGE_FALSE_VALUE edge from if (COND1) bb.
     820              :    If COND2 is NULL, this is equivalent to
     821              :    if_then (COND1, PROB1, EDGE_TRUE_FALSE, EDGE_FALSE);
     822              :    EDGE_TRUE_TRUE = NULL;  */
     823              : 
     824              : void
     825         2098 : bitint_large_huge::if_then_if_then_else (gimple *cond1, gimple *cond2,
     826              :                                          profile_probability prob1,
     827              :                                          profile_probability prob2,
     828              :                                          edge &edge_true_true,
     829              :                                          edge &edge_true_false,
     830              :                                          edge &edge_false)
     831              : {
     832         2098 :   edge e2, e3, e4 = NULL;
     833         2098 :   if_then (cond1, prob1, e2, e3);
     834         2098 :   if (cond2 == NULL)
     835              :     {
     836         1257 :       edge_true_true = NULL;
     837         1257 :       edge_true_false = e2;
     838         1257 :       edge_false = e3;
     839         1257 :       return;
     840              :     }
     841          841 :   insert_before (cond2);
     842          841 :   e2 = split_block (gsi_bb (m_gsi), cond2);
     843          841 :   basic_block bb = create_empty_bb (e2->dest);
     844          841 :   add_bb_to_loop (bb, e2->dest->loop_father);
     845          841 :   e4 = make_edge (e2->src, bb, EDGE_TRUE_VALUE);
     846          841 :   set_immediate_dominator (CDI_DOMINATORS, bb, e2->src);
     847          841 :   e4->probability = prob2;
     848          841 :   e2->flags = EDGE_FALSE_VALUE;
     849          841 :   e2->probability = prob2.invert ();
     850          841 :   bb->count = e2->src->count.apply_probability (prob2);
     851          841 :   e4 = make_single_succ_edge (bb, e3->dest, EDGE_FALLTHRU);
     852          841 :   e2 = find_edge (e2->dest, e3->dest);
     853          841 :   edge_true_true = e4;
     854          841 :   edge_true_false = e2;
     855          841 :   edge_false = e3;
     856          841 :   m_gsi = gsi_after_labels (e2->src);
     857              : }
     858              : 
     859              : /* Emit code to access limb IDX from OP.  */
     860              : 
     861              : tree
     862       119675 : bitint_large_huge::handle_operand (tree op, tree idx)
     863              : {
     864       119675 :   switch (TREE_CODE (op))
     865              :     {
     866        83608 :     case SSA_NAME:
     867        83608 :       if (m_names == NULL
     868        83608 :           || !bitmap_bit_p (m_names, SSA_NAME_VERSION (op)))
     869              :         {
     870        15561 :           if (SSA_NAME_IS_DEFAULT_DEF (op))
     871              :             {
     872           47 :               if (m_first)
     873              :                 {
     874           16 :                   tree v = create_tmp_reg (m_limb_type);
     875           16 :                   if (SSA_NAME_VAR (op) && VAR_P (SSA_NAME_VAR (op)))
     876              :                     {
     877           16 :                       DECL_NAME (v) = DECL_NAME (SSA_NAME_VAR (op));
     878           16 :                       DECL_SOURCE_LOCATION (v)
     879           16 :                         = DECL_SOURCE_LOCATION (SSA_NAME_VAR (op));
     880              :                     }
     881           16 :                   v = get_or_create_ssa_default_def (cfun, v);
     882           16 :                   m_data.safe_push (v);
     883              :                 }
     884           47 :               tree ret = m_data[m_data_cnt];
     885           47 :               m_data_cnt++;
     886           47 :               if (tree_fits_uhwi_p (idx))
     887              :                 {
     888           45 :                   tree type = limb_access_type (TREE_TYPE (op), idx);
     889           45 :                   ret = add_cast (type, ret);
     890              :                 }
     891              :               return ret;
     892              :             }
     893        15514 :           location_t loc_save = m_loc;
     894        15514 :           m_loc = gimple_location (SSA_NAME_DEF_STMT (op));
     895        15514 :           tree ret = handle_stmt (SSA_NAME_DEF_STMT (op), idx);
     896        15514 :           m_loc = loc_save;
     897        15514 :           return ret;
     898              :         }
     899        68047 :       int p;
     900        68047 :       gimple *g;
     901        68047 :       tree t;
     902        68047 :       p = var_to_partition (m_map, op);
     903        68047 :       gcc_assert (m_vars[p] != NULL_TREE);
     904        68047 :       t = limb_access (TREE_TYPE (op), m_vars[p], idx, false);
     905        68047 :       g = gimple_build_assign (make_ssa_name (TREE_TYPE (t)), t);
     906        68047 :       insert_before (g);
     907        68047 :       t = gimple_assign_lhs (g);
     908        68047 :       if (m_first
     909        24617 :           && m_single_use_names
     910        23602 :           && m_vars[p] != m_lhs
     911        23281 :           && m_after_stmt
     912        77782 :           && bitmap_bit_p (m_single_use_names, SSA_NAME_VERSION (op)))
     913              :         {
     914         8968 :           tree clobber = build_clobber (TREE_TYPE (m_vars[p]),
     915              :                                         CLOBBER_STORAGE_END);
     916         8968 :           g = gimple_build_assign (m_vars[p], clobber);
     917         8968 :           gimple_stmt_iterator gsi = gsi_for_stmt (m_after_stmt);
     918         8968 :           gsi_insert_after (&gsi, g, GSI_SAME_STMT);
     919              :         }
     920              :       return t;
     921        36067 :     case INTEGER_CST:
     922        36067 :       if (tree_fits_uhwi_p (idx))
     923              :         {
     924        24478 :           tree c, type = limb_access_type (TREE_TYPE (op), idx);
     925        24478 :           unsigned HOST_WIDE_INT i = tree_to_uhwi (idx);
     926        24478 :           if (m_first)
     927              :             {
     928         6291 :               m_data.safe_push (NULL_TREE);
     929         6291 :               m_data.safe_push (NULL_TREE);
     930              :             }
     931        24478 :           if (bitint_big_endian)
     932            0 :             i = CEIL (TYPE_PRECISION (TREE_TYPE (op)), limb_prec) - 1 - i;
     933        24478 :           if (limb_prec != HOST_BITS_PER_WIDE_INT)
     934              :             {
     935            0 :               wide_int w = wi::rshift (wi::to_wide (op), i * limb_prec,
     936            0 :                                        TYPE_SIGN (TREE_TYPE (op)));
     937            0 :               c = wide_int_to_tree (type,
     938            0 :                                     wide_int::from (w, TYPE_PRECISION (type),
     939              :                                                     UNSIGNED));
     940            0 :             }
     941        24478 :           else if (i >= TREE_INT_CST_EXT_NUNITS (op))
     942         7978 :             c = build_int_cst (type,
     943        14264 :                                tree_int_cst_sgn (op) < 0 ? -1 : 0);
     944              :           else
     945        16500 :             c = build_int_cst (type, TREE_INT_CST_ELT (op, i));
     946        24478 :           m_data_cnt += 2;
     947        24478 :           return c;
     948              :         }
     949        11589 :       if (m_first
     950        11589 :           || (m_data[m_data_cnt] == NULL_TREE
     951          159 :               && m_data[m_data_cnt + 1] == NULL_TREE))
     952              :         {
     953         5840 :           unsigned int prec = TYPE_PRECISION (TREE_TYPE (op));
     954         5840 :           unsigned int rem = prec % ((m_upwards_2limb ? 2 : 1) * limb_prec);
     955         5840 :           int ext;
     956         5840 :           unsigned min_prec = bitint_min_cst_precision (op, ext);
     957         5840 :           if (m_first)
     958              :             {
     959         5681 :               m_data.safe_push (NULL_TREE);
     960         5681 :               m_data.safe_push (NULL_TREE);
     961              :             }
     962         5840 :           if (integer_zerop (op))
     963              :             {
     964          958 :               tree c = build_zero_cst (m_limb_type);
     965          958 :               m_data[m_data_cnt] = c;
     966          958 :               m_data[m_data_cnt + 1] = c;
     967              :             }
     968         4882 :           else if (integer_all_onesp (op))
     969              :             {
     970          708 :               tree c = build_all_ones_cst (m_limb_type);
     971          708 :               m_data[m_data_cnt] = c;
     972          708 :               m_data[m_data_cnt + 1] = c;
     973              :             }
     974         4174 :           else if (m_upwards_2limb && min_prec <= (unsigned) limb_prec)
     975              :             {
     976              :               /* Single limb constant.  Use a phi with that limb from
     977              :                  the preheader edge and 0 or -1 constant from the other edge
     978              :                  and for the second limb in the loop.  */
     979         1143 :               tree out;
     980         1143 :               gcc_assert (m_first);
     981         1143 :               m_data.pop ();
     982         1143 :               m_data.pop ();
     983         1143 :               prepare_data_in_out (fold_convert (m_limb_type, op), idx, &out,
     984         1143 :                                    build_int_cst (m_limb_type, ext));
     985         1143 :             }
     986         3031 :           else if (min_prec > prec - rem - 2 * limb_prec)
     987              :             {
     988              :               /* Constant which has enough significant bits that it isn't
     989              :                  worth trying to save .rodata space by extending from smaller
     990              :                  number.  */
     991         2482 :               tree type;
     992         2482 :               if (m_var_msb)
     993           25 :                 type = TREE_TYPE (op);
     994              :               else
     995              :                 /* If we have a guarantee the most significant partial limb
     996              :                    (if any) will be only accessed through handle_operand
     997              :                    with INTEGER_CST idx, we don't need to include the partial
     998              :                    limb in .rodata.  */
     999         2457 :                 type = build_bitint_type (prec - rem, 1);
    1000         2482 :               tree c = tree_output_constant_def (fold_convert (type, op));
    1001         2482 :               m_data[m_data_cnt] = c;
    1002         2482 :               m_data[m_data_cnt + 1] = NULL_TREE;
    1003              :             }
    1004          549 :           else if (m_upwards_2limb)
    1005              :             {
    1006              :               /* Constant with smaller number of bits.  Trade conditional
    1007              :                  code for .rodata space by extending from smaller number.  */
    1008          472 :               min_prec = CEIL (min_prec, 2 * limb_prec) * (2 * limb_prec);
    1009          472 :               tree type = build_bitint_type (min_prec, 1);
    1010          472 :               tree c = tree_output_constant_def (fold_convert (type, op));
    1011          472 :               tree ridx = idx;
    1012          472 :               if (bitint_big_endian)
    1013              :                 {
    1014            0 :                   ridx = make_ssa_name (sizetype);
    1015            0 :                   g = gimple_build_assign (ridx, PLUS_EXPR, idx,
    1016            0 :                                            size_int (min_prec / limb_prec
    1017              :                                                      - ((HOST_WIDE_INT)
    1018              :                                                         CEIL (prec,
    1019              :                                                               limb_prec))));
    1020            0 :                   insert_before (g);
    1021              :                 }
    1022          472 :               tree ridx2 = make_ssa_name (sizetype);
    1023          472 :               g = gimple_build_assign (ridx2, PLUS_EXPR, ridx,
    1024              :                                        bitint_big_endian
    1025            0 :                                        ? size_int (-1) : size_one_node);
    1026          472 :               insert_before (g);
    1027          472 :               if (bitint_big_endian)
    1028            0 :                 g = gimple_build_cond (GE_EXPR, idx,
    1029            0 :                                        size_int (CEIL (prec, limb_prec)
    1030              :                                                  - min_prec / limb_prec),
    1031              :                                        NULL_TREE, NULL_TREE);
    1032              :               else
    1033          472 :                 g = gimple_build_cond (LT_EXPR, idx,
    1034          472 :                                        size_int (min_prec / limb_prec),
    1035              :                                        NULL_TREE, NULL_TREE);
    1036          472 :               edge edge_true, edge_false;
    1037          944 :               if_then (g, (min_prec >= (prec - rem) / 2
    1038          340 :                            ? profile_probability::likely ()
    1039          132 :                            : profile_probability::unlikely ()),
    1040              :                        edge_true, edge_false);
    1041          472 :               tree c1 = limb_access (TREE_TYPE (op), c, ridx, false);
    1042          472 :               gassign *a
    1043          472 :                 = gimple_build_assign (make_ssa_name (TREE_TYPE (c1)), c1);
    1044          472 :               insert_before (a);
    1045          472 :               c1 = gimple_assign_lhs (a);
    1046          472 :               tree c2 = limb_access (TREE_TYPE (op), c, ridx2, false);
    1047          472 :               a = gimple_build_assign (make_ssa_name (TREE_TYPE (c2)), c2);
    1048          472 :               insert_before (a);
    1049          472 :               c2 = gimple_assign_lhs (a);
    1050          472 :               tree c3 = build_int_cst (m_limb_type, ext);
    1051          472 :               m_gsi = gsi_after_labels (edge_true->dest);
    1052          472 :               m_data[m_data_cnt] = make_ssa_name (m_limb_type);
    1053          472 :               m_data[m_data_cnt + 1] = make_ssa_name (m_limb_type);
    1054          472 :               gphi *phi = create_phi_node (m_data[m_data_cnt],
    1055              :                                            edge_true->dest);
    1056          472 :               add_phi_arg (phi, c1, edge_true, UNKNOWN_LOCATION);
    1057          472 :               add_phi_arg (phi, c3, edge_false, UNKNOWN_LOCATION);
    1058          472 :               phi = create_phi_node (m_data[m_data_cnt + 1], edge_true->dest);
    1059          472 :               add_phi_arg (phi, c2, edge_true, UNKNOWN_LOCATION);
    1060          472 :               add_phi_arg (phi, c3, edge_false, UNKNOWN_LOCATION);
    1061              :             }
    1062              :           else
    1063              :             {
    1064              :               /* Constant with smaller number of bits.  Trade conditional
    1065              :                  code for .rodata space by extending from smaller number.
    1066              :                  Version for loops with random access to the limbs or
    1067              :                  downwards loops.  */
    1068           77 :               min_prec = CEIL (min_prec, limb_prec) * limb_prec;
    1069           77 :               tree c;
    1070           77 :               if (min_prec <= (unsigned) limb_prec)
    1071           23 :                 c = fold_convert (m_limb_type, op);
    1072              :               else
    1073              :                 {
    1074           54 :                   tree type = build_bitint_type (min_prec, 1);
    1075           54 :                   c = tree_output_constant_def (fold_convert (type, op));
    1076              :                 }
    1077           77 :               m_data[m_data_cnt] = c;
    1078           77 :               m_data[m_data_cnt + 1] = integer_type_node;
    1079              :             }
    1080         5840 :           t = m_data[m_data_cnt];
    1081              :         }
    1082              :       else
    1083         5749 :         t = m_data[m_data_cnt + 1];
    1084        11589 :       if (m_data[m_data_cnt + 1] == NULL_TREE)
    1085              :         {
    1086         4908 :           tree ridx = idx;
    1087         4908 :           unsigned int prec = TYPE_PRECISION (TREE_TYPE (op));
    1088         4908 :           tree c = m_data[m_data_cnt];
    1089         4908 :           unsigned int min_prec = TYPE_PRECISION (TREE_TYPE (c));
    1090         4908 :           if (bitint_big_endian
    1091            0 :               && CEIL (min_prec, limb_prec) != CEIL (prec, limb_prec))
    1092              :             {
    1093            0 :               ridx = make_ssa_name (sizetype);
    1094            0 :               g = gimple_build_assign (ridx, PLUS_EXPR, idx,
    1095            0 :                                        size_int (CEIL (min_prec, limb_prec)
    1096              :                                                  - ((HOST_WIDE_INT)
    1097              :                                                     CEIL (prec, limb_prec))));
    1098            0 :               insert_before (g);
    1099              :             }
    1100         4908 :           t = limb_access (TREE_TYPE (op), c, ridx, false);
    1101         4908 :           gassign *a = gimple_build_assign (make_ssa_name (TREE_TYPE (t)), t);
    1102         4908 :           insert_before (a);
    1103         4908 :           t = gimple_assign_lhs (a);
    1104              :         }
    1105         6681 :       else if (m_data[m_data_cnt + 1] == integer_type_node)
    1106              :         {
    1107          119 :           unsigned int prec = TYPE_PRECISION (TREE_TYPE (op));
    1108          119 :           unsigned rem = prec % ((m_upwards_2limb ? 2 : 1) * limb_prec);
    1109          119 :           int ext = wi::neg_p (wi::to_wide (op)) ? -1 : 0;
    1110          119 :           tree c = m_data[m_data_cnt];
    1111          119 :           unsigned min_prec = TYPE_PRECISION (TREE_TYPE (c));
    1112          119 :           if (bitint_big_endian)
    1113            0 :             g = gimple_build_cond (GE_EXPR, idx,
    1114            0 :                                    size_int (CEIL (prec, limb_prec)
    1115              :                                              - min_prec / limb_prec),
    1116              :                                    NULL_TREE, NULL_TREE);
    1117              :           else
    1118          119 :             g = gimple_build_cond (LT_EXPR, idx,
    1119          119 :                                    size_int (min_prec / limb_prec),
    1120              :                                    NULL_TREE, NULL_TREE);
    1121          119 :           edge edge_true, edge_false;
    1122          238 :           if_then (g, (min_prec >= (prec - rem) / 2
    1123           29 :                        ? profile_probability::likely ()
    1124           90 :                        : profile_probability::unlikely ()),
    1125              :                    edge_true, edge_false);
    1126          119 :           if (min_prec > (unsigned) limb_prec)
    1127              :             {
    1128           70 :               tree ridx = idx;
    1129           70 :               if (bitint_big_endian)
    1130              :                 {
    1131            0 :                   ridx = make_ssa_name (sizetype);
    1132            0 :                   g = gimple_build_assign (ridx, PLUS_EXPR, idx,
    1133            0 :                                            size_int (min_prec / limb_prec
    1134              :                                                      - ((HOST_WIDE_INT)
    1135              :                                                         CEIL (prec,
    1136              :                                                               limb_prec))));
    1137            0 :                   insert_before (g);
    1138              :                 }
    1139           70 :               c = limb_access (TREE_TYPE (op), c, ridx, false);
    1140           70 :               gassign *a
    1141           70 :                 = gimple_build_assign (make_ssa_name (TREE_TYPE (c)), c);
    1142           70 :               insert_before (a);
    1143           70 :               c = gimple_assign_lhs (a);
    1144              :             }
    1145          119 :           tree c2 = build_int_cst (m_limb_type, ext);
    1146          119 :           m_gsi = gsi_after_labels (edge_true->dest);
    1147          119 :           t = make_ssa_name (m_limb_type);
    1148          119 :           gphi *phi = create_phi_node (t, edge_true->dest);
    1149          119 :           add_phi_arg (phi, c, edge_true, UNKNOWN_LOCATION);
    1150          119 :           add_phi_arg (phi, c2, edge_false, UNKNOWN_LOCATION);
    1151              :         }
    1152        11589 :       m_data_cnt += 2;
    1153        11589 :       return t;
    1154            0 :     default:
    1155            0 :       gcc_unreachable ();
    1156              :     }
    1157              : }
    1158              : 
    1159              : /* Helper method, add a PHI node with VAL from preheader edge if
    1160              :    inside of a loop and m_first.  Keep state in a pair of m_data
    1161              :    elements.  If VAL_OUT is non-NULL, use that as PHI argument from
    1162              :    the latch edge, otherwise create a new SSA_NAME for it and let
    1163              :    caller initialize it.  */
    1164              : 
    1165              : tree
    1166        17343 : bitint_large_huge::prepare_data_in_out (tree val, tree idx, tree *data_out,
    1167              :                                         tree val_out)
    1168              : {
    1169        17343 :   if (!m_first)
    1170              :     {
    1171        10200 :       *data_out = tree_fits_uhwi_p (idx) ? NULL_TREE : m_data[m_data_cnt + 1];
    1172        10200 :       return m_data[m_data_cnt];
    1173              :     }
    1174              : 
    1175         7143 :   *data_out = NULL_TREE;
    1176         7143 :   if (tree_fits_uhwi_p (idx))
    1177              :     {
    1178         2050 :       m_data.safe_push (val);
    1179         2050 :       m_data.safe_push (NULL_TREE);
    1180         2050 :       return val;
    1181              :     }
    1182              : 
    1183         5093 :   tree in = make_ssa_name (TREE_TYPE (val));
    1184         5093 :   gphi *phi = create_phi_node (in, m_bb);
    1185         5093 :   edge e1 = find_edge (m_preheader_bb, m_bb);
    1186         5093 :   edge e2 = EDGE_PRED (m_bb, 0);
    1187         5093 :   if (e1 == e2)
    1188         5093 :     e2 = EDGE_PRED (m_bb, 1);
    1189         5093 :   add_phi_arg (phi, val, e1, UNKNOWN_LOCATION);
    1190         5093 :   tree out = val_out ? val_out : make_ssa_name (TREE_TYPE (val));
    1191         5093 :   add_phi_arg (phi, out, e2, UNKNOWN_LOCATION);
    1192         5093 :   m_data.safe_push (in);
    1193         5093 :   m_data.safe_push (out);
    1194         5093 :   return in;
    1195              : }
    1196              : 
    1197              : /* Return VAL cast to TYPE.  If VAL is INTEGER_CST, just
    1198              :    convert it without emitting any code, otherwise emit
    1199              :    the conversion statement before the current location.  */
    1200              : 
    1201              : tree
    1202        40898 : bitint_large_huge::add_cast (tree type, tree val)
    1203              : {
    1204        40898 :   if (TREE_CODE (val) == INTEGER_CST)
    1205         4732 :     return fold_convert (type, val);
    1206              : 
    1207        36166 :   tree lhs = make_ssa_name (type);
    1208        36166 :   gimple *g = gimple_build_assign (lhs, NOP_EXPR, val);
    1209        36166 :   insert_before (g);
    1210        36166 :   return lhs;
    1211              : }
    1212              : 
    1213              : /* Helper of handle_stmt method, handle PLUS_EXPR or MINUS_EXPR.  */
    1214              : 
    1215              : tree
    1216        14410 : bitint_large_huge::handle_plus_minus (tree_code code, tree rhs1, tree rhs2,
    1217              :                                       tree idx)
    1218              : {
    1219        14410 :   tree lhs, data_out, ctype;
    1220        14410 :   tree rhs1_type = TREE_TYPE (rhs1);
    1221        14410 :   gimple *g;
    1222        14410 :   tree data_in = prepare_data_in_out (build_zero_cst (m_limb_type), idx,
    1223              :                                       &data_out);
    1224              : 
    1225        20213 :   if (optab_handler (code == PLUS_EXPR ? uaddc5_optab : usubc5_optab,
    1226        14410 :                      TYPE_MODE (m_limb_type)) != CODE_FOR_nothing)
    1227              :     {
    1228        14410 :       ctype = build_complex_type (m_limb_type);
    1229        14410 :       if (!types_compatible_p (rhs1_type, m_limb_type))
    1230              :         {
    1231         1415 :           if (!TYPE_UNSIGNED (rhs1_type))
    1232              :             {
    1233          395 :               tree type = unsigned_type_for (rhs1_type);
    1234          395 :               rhs1 = add_cast (type, rhs1);
    1235          395 :               rhs2 = add_cast (type, rhs2);
    1236              :             }
    1237         1415 :           rhs1 = add_cast (m_limb_type, rhs1);
    1238         1415 :           rhs2 = add_cast (m_limb_type, rhs2);
    1239              :         }
    1240        14410 :       lhs = make_ssa_name (ctype);
    1241        20213 :       g = gimple_build_call_internal (code == PLUS_EXPR
    1242              :                                       ? IFN_UADDC : IFN_USUBC,
    1243              :                                       3, rhs1, rhs2, data_in);
    1244        14410 :       gimple_call_set_lhs (g, lhs);
    1245        14410 :       insert_before (g);
    1246        14410 :       if (data_out == NULL_TREE)
    1247        11881 :         data_out = make_ssa_name (m_limb_type);
    1248        14410 :       g = gimple_build_assign (data_out, IMAGPART_EXPR,
    1249              :                                build1 (IMAGPART_EXPR, m_limb_type, lhs));
    1250        14410 :       insert_before (g);
    1251              :     }
    1252            0 :   else if (types_compatible_p (rhs1_type, m_limb_type))
    1253              :     {
    1254            0 :       ctype = build_complex_type (m_limb_type);
    1255            0 :       lhs = make_ssa_name (ctype);
    1256            0 :       g = gimple_build_call_internal (code == PLUS_EXPR
    1257              :                                       ? IFN_ADD_OVERFLOW : IFN_SUB_OVERFLOW,
    1258              :                                       2, rhs1, rhs2);
    1259            0 :       gimple_call_set_lhs (g, lhs);
    1260            0 :       insert_before (g);
    1261            0 :       if (data_out == NULL_TREE)
    1262            0 :         data_out = make_ssa_name (m_limb_type);
    1263            0 :       if (!integer_zerop (data_in))
    1264              :         {
    1265            0 :           rhs1 = make_ssa_name (m_limb_type);
    1266            0 :           g = gimple_build_assign (rhs1, REALPART_EXPR,
    1267              :                                    build1 (REALPART_EXPR, m_limb_type, lhs));
    1268            0 :           insert_before (g);
    1269            0 :           rhs2 = make_ssa_name (m_limb_type);
    1270            0 :           g = gimple_build_assign (rhs2, IMAGPART_EXPR,
    1271              :                                    build1 (IMAGPART_EXPR, m_limb_type, lhs));
    1272            0 :           insert_before (g);
    1273            0 :           lhs = make_ssa_name (ctype);
    1274            0 :           g = gimple_build_call_internal (code == PLUS_EXPR
    1275              :                                           ? IFN_ADD_OVERFLOW
    1276              :                                           : IFN_SUB_OVERFLOW,
    1277              :                                           2, rhs1, data_in);
    1278            0 :           gimple_call_set_lhs (g, lhs);
    1279            0 :           insert_before (g);
    1280            0 :           data_in = make_ssa_name (m_limb_type);
    1281            0 :           g = gimple_build_assign (data_in, IMAGPART_EXPR,
    1282              :                                    build1 (IMAGPART_EXPR, m_limb_type, lhs));
    1283            0 :           insert_before (g);
    1284            0 :           g = gimple_build_assign (data_out, PLUS_EXPR, rhs2, data_in);
    1285            0 :           insert_before (g);
    1286              :         }
    1287              :       else
    1288              :         {
    1289            0 :           g = gimple_build_assign (data_out, IMAGPART_EXPR,
    1290              :                                    build1 (IMAGPART_EXPR, m_limb_type, lhs));
    1291            0 :           insert_before (g);
    1292              :         }
    1293              :     }
    1294              :   else
    1295              :     {
    1296              :       /* Always perform the two additions or subtractions in
    1297              :          unsigned type, avoid introducing a temporary UB.  While
    1298              :          the end result of the 2 additions or 2 subtractions in
    1299              :          a valid program should not overflow, temporarily it can.
    1300              :          See PR126503.  */
    1301            0 :       tree utype = unsigned_type_for (rhs1_type);
    1302            0 :       tree in = add_cast (utype, data_in);
    1303            0 :       lhs = make_ssa_name (utype);
    1304            0 :       if (utype != rhs1_type)
    1305              :         {
    1306            0 :           rhs1 = add_cast (utype, rhs1);
    1307            0 :           rhs2 = add_cast (utype, rhs2);
    1308              :         }
    1309            0 :       g = gimple_build_assign (lhs, code, rhs1, rhs2);
    1310            0 :       insert_before (g);
    1311            0 :       rhs1 = make_ssa_name (utype);
    1312            0 :       g = gimple_build_assign (rhs1, code, lhs, in);
    1313            0 :       insert_before (g);
    1314            0 :       m_data[m_data_cnt] = NULL_TREE;
    1315            0 :       m_data_cnt += 2;
    1316            0 :       return utype != rhs1_type ? add_cast (rhs1_type, rhs1) : rhs1;
    1317              :     }
    1318        14410 :   rhs1 = make_ssa_name (m_limb_type);
    1319        14410 :   g = gimple_build_assign (rhs1, REALPART_EXPR,
    1320              :                            build1 (REALPART_EXPR, m_limb_type, lhs));
    1321        14410 :   insert_before (g);
    1322        14410 :   if (!types_compatible_p (rhs1_type, m_limb_type))
    1323         1415 :     rhs1 = add_cast (rhs1_type, rhs1);
    1324        14410 :   m_data[m_data_cnt] = data_out;
    1325        14410 :   m_data_cnt += 2;
    1326        14410 :   return rhs1;
    1327              : }
    1328              : 
    1329              : /* Helper function for handle_stmt method, handle LSHIFT_EXPR by
    1330              :    count in [0, limb_prec - 1] range.  */
    1331              : 
    1332              : tree
    1333          224 : bitint_large_huge::handle_lshift (tree rhs1, tree rhs2, tree idx)
    1334              : {
    1335          224 :   unsigned HOST_WIDE_INT cnt = tree_to_uhwi (rhs2);
    1336          224 :   gcc_checking_assert (cnt < (unsigned) limb_prec);
    1337          224 :   if (cnt == 0)
    1338              :     return rhs1;
    1339              : 
    1340          224 :   tree lhs, data_out, rhs1_type = TREE_TYPE (rhs1);
    1341          224 :   gimple *g;
    1342          224 :   tree data_in = prepare_data_in_out (build_zero_cst (m_limb_type), idx,
    1343              :                                       &data_out);
    1344              : 
    1345          224 :   if (!integer_zerop (data_in))
    1346              :     {
    1347          206 :       lhs = make_ssa_name (m_limb_type);
    1348          206 :       g = gimple_build_assign (lhs, RSHIFT_EXPR, data_in,
    1349              :                                build_int_cst (unsigned_type_node,
    1350          206 :                                               limb_prec - cnt));
    1351          206 :       insert_before (g);
    1352          206 :       if (!types_compatible_p (rhs1_type, m_limb_type))
    1353           53 :         lhs = add_cast (rhs1_type, lhs);
    1354              :       data_in = lhs;
    1355              :     }
    1356          224 :   if (types_compatible_p (rhs1_type, m_limb_type))
    1357              :     {
    1358          171 :       if (data_out == NULL_TREE)
    1359          111 :         data_out = make_ssa_name (m_limb_type);
    1360          171 :       g = gimple_build_assign (data_out, rhs1);
    1361          171 :       insert_before (g);
    1362              :     }
    1363          224 :   if (cnt < (unsigned) TYPE_PRECISION (rhs1_type))
    1364              :     {
    1365          207 :       lhs = make_ssa_name (rhs1_type);
    1366          207 :       g = gimple_build_assign (lhs, LSHIFT_EXPR, rhs1, rhs2);
    1367          207 :       insert_before (g);
    1368          207 :       if (!integer_zerop (data_in))
    1369              :         {
    1370          189 :           rhs1 = lhs;
    1371          189 :           lhs = make_ssa_name (rhs1_type);
    1372          189 :           g = gimple_build_assign (lhs, BIT_IOR_EXPR, rhs1, data_in);
    1373          189 :           insert_before (g);
    1374              :         }
    1375              :     }
    1376              :   else
    1377              :     lhs = data_in;
    1378          224 :   m_data[m_data_cnt] = data_out;
    1379          224 :   m_data_cnt += 2;
    1380          224 :   return lhs;
    1381              : }
    1382              : 
    1383              : /* Helper function for handle_stmt method, handle an integral
    1384              :    to integral conversion.  */
    1385              : 
    1386              : tree
    1387         7664 : bitint_large_huge::handle_cast (tree lhs_type, tree rhs1, tree idx)
    1388              : {
    1389         7664 :   tree rhs_type = TREE_TYPE (rhs1);
    1390         7664 :   gimple *g;
    1391         7664 :   if ((TREE_CODE (rhs1) == SSA_NAME || TREE_CODE (rhs1) == INTEGER_CST)
    1392         7664 :       && BITINT_TYPE_P (lhs_type)
    1393         7664 :       && BITINT_TYPE_P (rhs_type)
    1394         6603 :       && bitint_precision_kind (lhs_type) >= bitint_prec_large
    1395        14267 :       && bitint_precision_kind (rhs_type) >= bitint_prec_large)
    1396              :     {
    1397         5952 :       if (TYPE_PRECISION (rhs_type) >= TYPE_PRECISION (lhs_type)
    1398              :           /* If lhs has bigger precision than rhs, we can use
    1399              :              the simple case only if there is a guarantee that
    1400              :              the most significant limb is handled in straight
    1401              :              line code.  If m_var_msb (on left shifts) or
    1402              :              if m_upwards_2limb * limb_prec is equal to
    1403              :              lhs precision or if not m_upwards_2limb and lhs_type
    1404              :              has precision which is multiple of limb_prec that is
    1405              :              not the case.  */
    1406         5952 :           || (!m_var_msb
    1407         1533 :               && (CEIL (TYPE_PRECISION (lhs_type), limb_prec)
    1408         1533 :                   == CEIL (TYPE_PRECISION (rhs_type), limb_prec))
    1409          379 :               && ((!m_upwards_2limb
    1410          191 :                    && (TYPE_PRECISION (lhs_type) % limb_prec != 0))
    1411          276 :                   || (m_upwards_2limb
    1412          376 :                       && (m_upwards_2limb * limb_prec
    1413          188 :                           < TYPE_PRECISION (lhs_type))))))
    1414              :         {
    1415         4684 :           tree ridx = idx;
    1416         4684 :           if (bitint_big_endian
    1417         4684 :               && (CEIL (TYPE_PRECISION (lhs_type), limb_prec)
    1418            0 :                   != CEIL (TYPE_PRECISION (rhs_type), limb_prec)))
    1419              :             {
    1420            0 :               HOST_WIDE_INT diff = CEIL (TYPE_PRECISION (rhs_type), limb_prec);
    1421            0 :               diff -= CEIL (TYPE_PRECISION (lhs_type), limb_prec);
    1422            0 :               if (tree_fits_uhwi_p (idx))
    1423            0 :                 ridx = size_int (tree_to_uhwi (idx) + diff);
    1424              :               else
    1425              :                 {
    1426            0 :                   tree t = make_ssa_name (sizetype);
    1427            0 :                   g = gimple_build_assign (t, PLUS_EXPR, idx, size_int (diff));
    1428            0 :                   insert_before (g);
    1429            0 :                   ridx = t;
    1430              :                 }
    1431              :             }
    1432         4684 :           rhs1 = handle_operand (rhs1, ridx);
    1433         4684 :           if (tree_fits_uhwi_p (idx))
    1434              :             {
    1435         2402 :               tree type = limb_access_type (lhs_type, idx);
    1436         2402 :               if (!types_compatible_p (type, TREE_TYPE (rhs1)))
    1437         1254 :                 rhs1 = add_cast (type, rhs1);
    1438              :             }
    1439              :           return rhs1;
    1440              :         }
    1441         1268 :       tree t;
    1442              :       /* Indexes lower than this don't need any special processing.  */
    1443         1268 :       unsigned low = ((unsigned) TYPE_PRECISION (rhs_type)
    1444         1268 :                       - !TYPE_UNSIGNED (rhs_type)) / limb_prec;
    1445              :       /* Indexes >= than this always contain an extension.  */
    1446         1268 :       unsigned high = CEIL ((unsigned) TYPE_PRECISION (rhs_type), limb_prec);
    1447         1268 :       unsigned lcnt = CEIL ((unsigned) TYPE_PRECISION (lhs_type), limb_prec);
    1448         1268 :       unsigned lowe = bitint_big_endian ? lcnt - 1 - low : low;
    1449         1268 :       bool save_first = m_first;
    1450         1268 :       if (m_first)
    1451              :         {
    1452          417 :           m_data.safe_push (NULL_TREE);
    1453          417 :           m_data.safe_push (NULL_TREE);
    1454          417 :           m_data.safe_push (NULL_TREE);
    1455          417 :           if (TYPE_UNSIGNED (rhs_type))
    1456              :             /* No need to keep state between iterations.  */
    1457              :             ;
    1458          195 :           else if (m_upwards && !m_upwards_2limb)
    1459              :             /* We need to keep state between iterations, but
    1460              :                not within any loop, everything is straight line
    1461              :                code with only increasing indexes.  */
    1462              :             ;
    1463          153 :           else if (!m_upwards_2limb)
    1464              :             {
    1465            3 :               unsigned save_data_cnt = m_data_cnt;
    1466            3 :               gimple_stmt_iterator save_gsi = m_gsi;
    1467            3 :               m_gsi = m_init_gsi;
    1468            3 :               if (gsi_end_p (m_gsi))
    1469            0 :                 m_gsi = gsi_after_labels (gsi_bb (m_gsi));
    1470              :               else
    1471            3 :                 gsi_next (&m_gsi);
    1472            3 :               m_data_cnt = save_data_cnt + 3;
    1473            3 :               t = handle_operand (rhs1, size_int (bitint_big_endian
    1474              :                                                   ? high - 1 - low : low));
    1475            3 :               m_first = false;
    1476            3 :               m_data[save_data_cnt + 2]
    1477            3 :                 = build_int_cst (integer_type_node, m_data_cnt);
    1478            3 :               m_data_cnt = save_data_cnt;
    1479            3 :               t = add_cast (signed_type_for (m_limb_type), t);
    1480            3 :               tree lpm1 = build_int_cst (unsigned_type_node, limb_prec - 1);
    1481            3 :               tree n = make_ssa_name (TREE_TYPE (t));
    1482            3 :               g = gimple_build_assign (n, RSHIFT_EXPR, t, lpm1);
    1483            3 :               insert_before (g);
    1484            3 :               m_data[save_data_cnt + 1] = add_cast (m_limb_type, n);
    1485            3 :               m_init_gsi = m_gsi;
    1486            3 :               if (gsi_end_p (m_init_gsi))
    1487            0 :                 m_init_gsi = gsi_last_bb (gsi_bb (m_init_gsi));
    1488              :               else
    1489            3 :                 gsi_prev (&m_init_gsi);
    1490            3 :               m_gsi = save_gsi;
    1491              :             }
    1492          150 :           else if (m_upwards_2limb * limb_prec < TYPE_PRECISION (rhs_type))
    1493              :             /* We need to keep state between iterations, but
    1494              :                fortunately not within the loop, only afterwards.  */
    1495              :             ;
    1496              :           else
    1497              :             {
    1498          146 :               tree out;
    1499          146 :               m_data.truncate (m_data_cnt);
    1500          146 :               prepare_data_in_out (build_zero_cst (m_limb_type), idx, &out);
    1501          146 :               m_data.safe_push (NULL_TREE);
    1502              :             }
    1503              :         }
    1504              : 
    1505         1268 :       unsigned save_data_cnt = m_data_cnt;
    1506         1268 :       m_data_cnt += 3;
    1507         1268 :       if (!tree_fits_uhwi_p (idx))
    1508              :         {
    1509          688 :           if (m_upwards_2limb
    1510          668 :               && low >= m_upwards_2limb - m_first)
    1511              :             {
    1512          158 :               if (bitint_big_endian
    1513          158 :                   && (CEIL (TYPE_PRECISION (lhs_type), limb_prec)
    1514            0 :                       != CEIL (TYPE_PRECISION (rhs_type), limb_prec)))
    1515              :                 {
    1516            0 :                   HOST_WIDE_INT diff
    1517            0 :                     = CEIL (TYPE_PRECISION (rhs_type), limb_prec);
    1518            0 :                   diff -= CEIL (TYPE_PRECISION (lhs_type), limb_prec);
    1519            0 :                   tree t = make_ssa_name (sizetype);
    1520            0 :                   g = gimple_build_assign (t, PLUS_EXPR, idx, size_int (diff));
    1521            0 :                   insert_before (g);
    1522            0 :                   idx = t;
    1523              :                 }
    1524          158 :               rhs1 = handle_operand (rhs1, idx);
    1525          158 :               if (m_first)
    1526          131 :                 m_data[save_data_cnt + 2]
    1527          262 :                   = build_int_cst (integer_type_node, m_data_cnt);
    1528          158 :               m_first = save_first;
    1529          158 :               return rhs1;
    1530              :             }
    1531         1326 :           bool single_comparison
    1532          530 :             = low == high || (m_upwards_2limb && (low & 1) == m_first);
    1533          266 :           tree idxc = idx;
    1534          266 :           if (!single_comparison
    1535          266 :               && m_upwards_2limb
    1536          246 :               && !m_first
    1537          112 :               && low + 1 == m_upwards_2limb)
    1538              :             /* In this case we know that idx <= low always,
    1539              :                so effectively we just needs a single comparison,
    1540              :                idx < low or idx == low, but we'd need to emit different
    1541              :                code for the 2 branches than single_comparison normally
    1542              :                emits.  So, instead of special-casing that, emit a
    1543              :                low <= low comparison which cfg cleanup will clean up
    1544              :                at the end of the pass.  */
    1545           89 :             idxc = size_int (lowe);
    1546          530 :           if (bitint_big_endian)
    1547            0 :             g = gimple_build_cond (single_comparison ? GT_EXPR : GE_EXPR,
    1548            0 :                                    idxc, size_int (lowe),
    1549              :                                    NULL_TREE, NULL_TREE);
    1550              :           else
    1551          796 :             g = gimple_build_cond (single_comparison ? LT_EXPR : LE_EXPR,
    1552          530 :                                    idxc, size_int (low), NULL_TREE, NULL_TREE);
    1553          530 :           edge edge_true_true, edge_true_false, edge_false;
    1554          796 :           if_then_if_then_else (g, (single_comparison ? NULL
    1555          266 :                                     : gimple_build_cond (EQ_EXPR, idx,
    1556          266 :                                                          size_int (lowe),
    1557              :                                                          NULL_TREE,
    1558              :                                                          NULL_TREE)),
    1559              :                                 profile_probability::likely (),
    1560              :                                 profile_probability::unlikely (),
    1561              :                                 edge_true_true, edge_true_false, edge_false);
    1562          530 :           bool save_cast_conditional = m_cast_conditional;
    1563          530 :           m_cast_conditional = true;
    1564          530 :           m_bitfld_load = 0;
    1565          530 :           tree t1 = idx, t2 = NULL_TREE;
    1566          530 :           if (bitint_big_endian
    1567          530 :               && (CEIL (TYPE_PRECISION (lhs_type), limb_prec)
    1568            0 :                   != CEIL (TYPE_PRECISION (rhs_type), limb_prec)))
    1569              :             {
    1570            0 :               HOST_WIDE_INT diff = CEIL (TYPE_PRECISION (rhs_type), limb_prec);
    1571            0 :               diff -= CEIL (TYPE_PRECISION (lhs_type), limb_prec);
    1572            0 :               t1 = make_ssa_name (sizetype);
    1573            0 :               g = gimple_build_assign (t1, PLUS_EXPR, idx, size_int (diff));
    1574            0 :               insert_before (g);
    1575              :             }
    1576          530 :           t1 = handle_operand (rhs1, t1);
    1577          530 :           if (m_first)
    1578          208 :             m_data[save_data_cnt + 2]
    1579          416 :               = build_int_cst (integer_type_node, m_data_cnt);
    1580          530 :           tree ext = NULL_TREE;
    1581          530 :           tree bitfld = NULL_TREE;
    1582          530 :           if (!single_comparison)
    1583              :             {
    1584          266 :               m_gsi = gsi_after_labels (edge_true_true->src);
    1585          266 :               m_first = false;
    1586          266 :               m_data_cnt = save_data_cnt + 3;
    1587          266 :               if (m_bitfld_load)
    1588              :                 {
    1589            4 :                   bitfld = m_data[m_bitfld_load];
    1590            4 :                   m_data[m_bitfld_load] = m_data[m_bitfld_load + 2];
    1591            4 :                   m_bitfld_load = 0;
    1592              :                 }
    1593          266 :               t2 = handle_operand (rhs1, size_int (bitint_big_endian
    1594              :                                                    ? high - 1 - low : low));
    1595          266 :               if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (t2)))
    1596          221 :                 t2 = add_cast (m_limb_type, t2);
    1597          266 :               if (!TYPE_UNSIGNED (rhs_type) && m_upwards_2limb)
    1598              :                 {
    1599          146 :                   ext = add_cast (signed_type_for (m_limb_type), t2);
    1600          292 :                   tree lpm1 = build_int_cst (unsigned_type_node,
    1601          146 :                                              limb_prec - 1);
    1602          146 :                   tree n = make_ssa_name (TREE_TYPE (ext));
    1603          146 :                   g = gimple_build_assign (n, RSHIFT_EXPR, ext, lpm1);
    1604          146 :                   insert_before (g);
    1605          146 :                   ext = add_cast (m_limb_type, n);
    1606              :                 }
    1607              :             }
    1608          530 :           tree t3;
    1609          530 :           if (TYPE_UNSIGNED (rhs_type))
    1610          278 :             t3 = build_zero_cst (m_limb_type);
    1611          252 :           else if (m_upwards_2limb && (save_first || ext != NULL_TREE))
    1612          168 :             t3 = m_data[save_data_cnt];
    1613              :           else
    1614           84 :             t3 = m_data[save_data_cnt + 1];
    1615          530 :           m_gsi = gsi_after_labels (edge_true_false->dest);
    1616          530 :           t = make_ssa_name (m_limb_type);
    1617          530 :           gphi *phi = create_phi_node (t, edge_true_false->dest);
    1618          530 :           add_phi_arg (phi, t1, edge_true_false, UNKNOWN_LOCATION);
    1619          530 :           add_phi_arg (phi, t3, edge_false, UNKNOWN_LOCATION);
    1620          530 :           if (edge_true_true)
    1621          266 :             add_phi_arg (phi, t2, edge_true_true, UNKNOWN_LOCATION);
    1622          530 :           if (ext)
    1623              :             {
    1624          146 :               tree t4 = make_ssa_name (m_limb_type);
    1625          146 :               phi = create_phi_node (t4, edge_true_false->dest);
    1626          146 :               add_phi_arg (phi, build_zero_cst (m_limb_type), edge_true_false,
    1627              :                            UNKNOWN_LOCATION);
    1628          146 :               add_phi_arg (phi, m_data[save_data_cnt], edge_false,
    1629              :                            UNKNOWN_LOCATION);
    1630          146 :               add_phi_arg (phi, ext, edge_true_true, UNKNOWN_LOCATION);
    1631          146 :               if (!save_cast_conditional)
    1632              :                 {
    1633          136 :                   g = gimple_build_assign (m_data[save_data_cnt + 1], t4);
    1634          136 :                   insert_before (g);
    1635              :                 }
    1636              :               else
    1637           10 :                 for (basic_block bb = gsi_bb (m_gsi);;)
    1638              :                   {
    1639           10 :                     edge e1 = single_succ_edge (bb);
    1640           10 :                     edge e2 = find_edge (e1->dest, m_bb), e3;
    1641           10 :                     tree t5 = (e2 ? m_data[save_data_cnt + 1]
    1642           10 :                                : make_ssa_name (m_limb_type));
    1643           10 :                     phi = create_phi_node (t5, e1->dest);
    1644           10 :                     edge_iterator ei;
    1645           30 :                     FOR_EACH_EDGE (e3, ei, e1->dest->preds)
    1646           30 :                       add_phi_arg (phi, (e3 == e1 ? t4
    1647           10 :                                          : build_zero_cst (m_limb_type)),
    1648              :                                    e3, UNKNOWN_LOCATION);
    1649           10 :                     if (e2)
    1650              :                       break;
    1651            0 :                     t4 = t5;
    1652            0 :                     bb = e1->dest;
    1653            0 :                   }
    1654              :             }
    1655          530 :           if (m_bitfld_load)
    1656              :             {
    1657            8 :               tree t4;
    1658            8 :               if (!save_first && !save_cast_conditional)
    1659            2 :                 t4 = m_data[m_bitfld_load + 1];
    1660              :               else
    1661            6 :                 t4 = make_ssa_name (m_limb_type);
    1662            8 :               phi = create_phi_node (t4, edge_true_false->dest);
    1663           12 :               add_phi_arg (phi,
    1664            4 :                            edge_true_true ? bitfld : m_data[m_bitfld_load],
    1665              :                            edge_true_false, UNKNOWN_LOCATION);
    1666            8 :               add_phi_arg (phi, m_data[m_bitfld_load + 2],
    1667              :                            edge_false, UNKNOWN_LOCATION);
    1668            8 :               if (edge_true_true)
    1669            4 :                 add_phi_arg (phi, m_data[m_bitfld_load], edge_true_true,
    1670              :                              UNKNOWN_LOCATION);
    1671            8 :               if (save_cast_conditional)
    1672            4 :                 for (basic_block bb = gsi_bb (m_gsi);;)
    1673              :                   {
    1674            4 :                     edge e1 = single_succ_edge (bb);
    1675            4 :                     edge e2 = find_edge (e1->dest, m_bb), e3;
    1676            4 :                     tree t5 = ((e2 && !save_first) ? m_data[m_bitfld_load + 1]
    1677            4 :                                : make_ssa_name (m_limb_type));
    1678            4 :                     phi = create_phi_node (t5, e1->dest);
    1679            4 :                     edge_iterator ei;
    1680           14 :                     FOR_EACH_EDGE (e3, ei, e1->dest->preds)
    1681           16 :                       add_phi_arg (phi, (e3 == e1 ? t4
    1682            6 :                                          : build_zero_cst (m_limb_type)),
    1683              :                                    e3, UNKNOWN_LOCATION);
    1684            4 :                     t4 = t5;
    1685            4 :                     if (e2)
    1686              :                       break;
    1687            0 :                     bb = e1->dest;
    1688            0 :                   }
    1689            8 :               m_data[m_bitfld_load] = t4;
    1690            8 :               m_data[m_bitfld_load + 2] = t4;
    1691            8 :               m_bitfld_load = 0;
    1692              :             }
    1693          530 :           m_cast_conditional = save_cast_conditional;
    1694          530 :           m_first = save_first;
    1695          530 :           return t;
    1696              :         }
    1697              :       else
    1698              :         {
    1699          580 :           unsigned tidx = tree_to_uhwi (idx);
    1700          580 :           if (bitint_big_endian)
    1701            0 :             tidx = lcnt - 1 - tidx;
    1702          580 :           if (tidx < low)
    1703              :             {
    1704          158 :               t = handle_operand (rhs1, (bitint_big_endian
    1705            0 :                                          ? size_int (high - 1 - tidx) : idx));
    1706          158 :               if (m_first)
    1707           74 :                 m_data[save_data_cnt + 2]
    1708          148 :                   = build_int_cst (integer_type_node, m_data_cnt);
    1709              :             }
    1710          422 :           else if (tidx < high)
    1711              :             {
    1712           71 :               t = handle_operand (rhs1, size_int (bitint_big_endian
    1713              :                                                   ? high - 1 - low : low));
    1714           71 :               if (m_first)
    1715            1 :                 m_data[save_data_cnt + 2]
    1716            2 :                   = build_int_cst (integer_type_node, m_data_cnt);
    1717           71 :               if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (t)))
    1718           63 :                 t = add_cast (m_limb_type, t);
    1719           71 :               tree ext = NULL_TREE;
    1720           71 :               if (!TYPE_UNSIGNED (rhs_type) && m_upwards)
    1721              :                 {
    1722           46 :                   ext = add_cast (signed_type_for (m_limb_type), t);
    1723           92 :                   tree lpm1 = build_int_cst (unsigned_type_node,
    1724           46 :                                              limb_prec - 1);
    1725           46 :                   tree n = make_ssa_name (TREE_TYPE (ext));
    1726           46 :                   g = gimple_build_assign (n, RSHIFT_EXPR, ext, lpm1);
    1727           46 :                   insert_before (g);
    1728           46 :                   ext = add_cast (m_limb_type, n);
    1729           46 :                   m_data[save_data_cnt + 1] = ext;
    1730              :                 }
    1731              :             }
    1732              :           else
    1733              :             {
    1734          351 :               if (TYPE_UNSIGNED (rhs_type) && m_first)
    1735              :                 {
    1736            0 :                   handle_operand (rhs1, (bitint_big_endian
    1737            0 :                                          ? size_int (high - 1)
    1738              :                                          : size_zero_node));
    1739            0 :                   m_data[save_data_cnt + 2]
    1740            0 :                     = build_int_cst (integer_type_node, m_data_cnt);
    1741              :                 }
    1742              :               else
    1743          351 :                 m_data_cnt = tree_to_uhwi (m_data[save_data_cnt + 2]);
    1744          351 :               if (TYPE_UNSIGNED (rhs_type))
    1745          184 :                 t = build_zero_cst (m_limb_type);
    1746          167 :               else if (m_bb
    1747           16 :                        && m_data[save_data_cnt]
    1748          180 :                        && ((tidx & 1) == 0 || tidx != low + 1))
    1749              :                 t = m_data[save_data_cnt];
    1750              :               else
    1751          161 :                 t = m_data[save_data_cnt + 1];
    1752              :             }
    1753          580 :           tree type = limb_access_type (lhs_type, idx);
    1754          580 :           if (!useless_type_conversion_p (type, m_limb_type))
    1755          292 :             t = add_cast (type, t);
    1756          580 :           m_first = save_first;
    1757          580 :           return t;
    1758              :         }
    1759              :     }
    1760            0 :   else if (BITINT_TYPE_P (lhs_type)
    1761         1712 :            && bitint_precision_kind (lhs_type) >= bitint_prec_large
    1762         3424 :            && INTEGRAL_TYPE_P (rhs_type))
    1763              :     {
    1764              :       /* Add support for 3 or more limbs filled in from normal integral
    1765              :          type if this assert fails.  If no target chooses limb mode smaller
    1766              :          than half of largest supported normal integral type, this will not
    1767              :          be needed.  */
    1768         1712 :       gcc_assert (TYPE_PRECISION (rhs_type) <= 2 * limb_prec);
    1769         1712 :       tree r1 = NULL_TREE, r2 = NULL_TREE, rext = NULL_TREE;
    1770         1712 :       if (m_first)
    1771              :         {
    1772          621 :           gimple_stmt_iterator save_gsi = m_gsi;
    1773          621 :           m_gsi = m_init_gsi;
    1774          621 :           if (gsi_end_p (m_gsi))
    1775           69 :             m_gsi = gsi_after_labels (gsi_bb (m_gsi));
    1776              :           else
    1777          552 :             gsi_next (&m_gsi);
    1778          398 :           if (BITINT_TYPE_P (rhs_type)
    1779          621 :               && bitint_precision_kind (rhs_type) == bitint_prec_middle)
    1780              :             {
    1781           63 :               tree type = NULL_TREE;
    1782           63 :               rhs1 = maybe_cast_middle_bitint (&m_gsi, rhs1, type);
    1783           63 :               rhs_type = TREE_TYPE (rhs1);
    1784              :             }
    1785          621 :           r1 = rhs1;
    1786          621 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1)))
    1787          553 :             r1 = add_cast (m_limb_type, rhs1);
    1788          621 :           if (TYPE_PRECISION (rhs_type) > limb_prec)
    1789              :             {
    1790          110 :               gassign *a = gimple_build_assign (make_ssa_name (rhs_type),
    1791              :                                                 RSHIFT_EXPR, rhs1,
    1792              :                                                 build_int_cst
    1793              :                                                 (unsigned_type_node,
    1794          110 :                                                  limb_prec));
    1795          110 :               insert_before (a);
    1796          110 :               r2 = add_cast (m_limb_type, gimple_assign_lhs (a));
    1797              :             }
    1798          621 :           if (TYPE_UNSIGNED (rhs_type))
    1799          309 :             rext = build_zero_cst (m_limb_type);
    1800              :           else
    1801              :             {
    1802          312 :               rext = add_cast (signed_type_for (m_limb_type), r2 ? r2 : r1);
    1803          312 :               gassign *a
    1804          312 :                 = gimple_build_assign (make_ssa_name (TREE_TYPE (rext)),
    1805              :                                        RSHIFT_EXPR, rext,
    1806              :                                        build_int_cst (unsigned_type_node,
    1807          312 :                                                       limb_prec - 1));
    1808          312 :               insert_before (a);
    1809          312 :               rext = add_cast (m_limb_type, gimple_assign_lhs (a));
    1810              :             }
    1811          621 :           m_init_gsi = m_gsi;
    1812          621 :           if (gsi_end_p (m_init_gsi))
    1813          624 :             m_init_gsi = gsi_last_bb (gsi_bb (m_init_gsi));
    1814              :           else
    1815          309 :             gsi_prev (&m_init_gsi);
    1816          621 :           m_gsi = save_gsi;
    1817              :         }
    1818         1712 :       tree t;
    1819         1712 :       if (m_upwards_2limb)
    1820              :         {
    1821          813 :           if (m_first)
    1822              :             {
    1823          310 :               tree out1, out2;
    1824          310 :               prepare_data_in_out (r1, idx, &out1, rext);
    1825          310 :               if (TYPE_PRECISION (rhs_type) > limb_prec)
    1826              :                 {
    1827           71 :                   prepare_data_in_out (r2, idx, &out2, rext);
    1828           71 :                   m_data.pop ();
    1829           71 :                   t = m_data.pop ();
    1830           71 :                   m_data[m_data_cnt + 1] = t;
    1831              :                 }
    1832              :               else
    1833          239 :                 m_data[m_data_cnt + 1] = rext;
    1834          310 :               m_data.safe_push (rext);
    1835          310 :               t = m_data[m_data_cnt];
    1836              :             }
    1837          503 :           else if (!tree_fits_uhwi_p (idx))
    1838          310 :             t = m_data[m_data_cnt + 1];
    1839              :           else
    1840              :             {
    1841          193 :               tree type = limb_access_type (lhs_type, idx);
    1842          193 :               t = m_data[m_data_cnt + 2];
    1843          193 :               if (!useless_type_conversion_p (type, m_limb_type))
    1844          164 :                 t = add_cast (type, t);
    1845              :             }
    1846          813 :           m_data_cnt += 3;
    1847          813 :           return t;
    1848              :         }
    1849          899 :       else if (m_first)
    1850              :         {
    1851          311 :           m_data.safe_push (r1);
    1852          311 :           m_data.safe_push (r2);
    1853          311 :           m_data.safe_push (rext);
    1854              :         }
    1855          899 :       unsigned lcnt = CEIL ((unsigned) TYPE_PRECISION (lhs_type), limb_prec);
    1856          899 :       if (tree_fits_uhwi_p (idx))
    1857              :         {
    1858          855 :           tree type = limb_access_type (lhs_type, idx);
    1859          855 :           if (bitint_big_endian
    1860          855 :               ? tree_to_uhwi (idx) == lcnt - 1 : integer_zerop (idx))
    1861          283 :             t = m_data[m_data_cnt];
    1862          572 :           else if (TYPE_PRECISION (rhs_type) > limb_prec
    1863          572 :                    && (bitint_big_endian
    1864           72 :                        ? tree_to_uhwi (idx) == lcnt - 2
    1865           72 :                        : integer_onep (idx)))
    1866           33 :             t = m_data[m_data_cnt + 1];
    1867              :           else
    1868          539 :             t = m_data[m_data_cnt + 2];
    1869          855 :           if (!useless_type_conversion_p (type, m_limb_type))
    1870          261 :             t = add_cast (type, t);
    1871          855 :           m_data_cnt += 3;
    1872          855 :           return t;
    1873              :         }
    1874           44 :       g = gimple_build_cond (NE_EXPR, idx,
    1875              :                              bitint_big_endian
    1876            0 :                              ? size_int (lcnt - 1) : size_zero_node,
    1877              :                              NULL_TREE, NULL_TREE);
    1878           44 :       edge e2, e3, e4 = NULL;
    1879           44 :       if_then (g, profile_probability::likely (), e2, e3);
    1880           44 :       if (m_data[m_data_cnt + 1])
    1881              :         {
    1882           14 :           g = gimple_build_cond (EQ_EXPR, idx,
    1883              :                                  bitint_big_endian
    1884            0 :                                  ? size_int (lcnt - 2) : size_one_node,
    1885              :                                  NULL_TREE, NULL_TREE);
    1886           14 :           insert_before (g);
    1887           14 :           edge e5 = split_block (gsi_bb (m_gsi), g);
    1888           14 :           e4 = make_edge (e5->src, e2->dest, EDGE_TRUE_VALUE);
    1889           14 :           e2 = find_edge (e5->dest, e2->dest);
    1890           14 :           e4->probability = profile_probability::unlikely ();
    1891           14 :           e5->flags = EDGE_FALSE_VALUE;
    1892           14 :           e5->probability = e4->probability.invert ();
    1893              :         }
    1894           44 :       m_gsi = gsi_after_labels (e2->dest);
    1895           44 :       t = make_ssa_name (m_limb_type);
    1896           44 :       gphi *phi = create_phi_node (t, e2->dest);
    1897           44 :       add_phi_arg (phi, m_data[m_data_cnt + 2], e2, UNKNOWN_LOCATION);
    1898           44 :       add_phi_arg (phi, m_data[m_data_cnt], e3, UNKNOWN_LOCATION);
    1899           44 :       if (e4)
    1900           14 :         add_phi_arg (phi, m_data[m_data_cnt + 1], e4, UNKNOWN_LOCATION);
    1901           44 :       m_data_cnt += 3;
    1902           44 :       return t;
    1903              :     }
    1904              :   return NULL_TREE;
    1905              : }
    1906              : 
    1907              : /* Helper function for handle_stmt method, handle a BIT_FIELD_REF.  */
    1908              : 
    1909              : tree
    1910           23 : bitint_large_huge::handle_bit_field_ref (tree op, tree idx)
    1911              : {
    1912           23 :   if (tree_fits_uhwi_p (idx))
    1913              :     {
    1914           13 :       if (m_first)
    1915            4 :         m_data.safe_push (NULL);
    1916           13 :       ++m_data_cnt;
    1917           13 :       unsigned HOST_WIDE_INT sz = tree_to_uhwi (TYPE_SIZE (m_limb_type));
    1918           13 :       unsigned i = tree_to_uhwi (idx);
    1919           13 :       if (bitint_big_endian)
    1920            0 :         i = CEIL (TYPE_PRECISION (TREE_TYPE (op)), limb_prec) - 1 - i;
    1921           26 :       tree bfr = build3 (BIT_FIELD_REF, m_limb_type,
    1922           13 :                          TREE_OPERAND (op, 0),
    1923           13 :                          TYPE_SIZE (m_limb_type),
    1924           13 :                          size_binop (PLUS_EXPR, TREE_OPERAND (op, 2),
    1925              :                                      bitsize_int (i * sz)));
    1926           13 :       tree r = make_ssa_name (m_limb_type);
    1927           13 :       gimple *g = gimple_build_assign (r, bfr);
    1928           13 :       insert_before (g);
    1929           13 :       tree type = limb_access_type (TREE_TYPE (op), idx);
    1930           13 :       if (!useless_type_conversion_p (type, m_limb_type))
    1931            0 :         r = add_cast (type, r);
    1932              :       return r;
    1933              :     }
    1934           10 :   tree var;
    1935           10 :   if (m_first)
    1936              :     {
    1937            5 :       unsigned HOST_WIDE_INT sz = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (op)));
    1938            5 :       machine_mode mode;
    1939            5 :       tree type, bfr;
    1940            5 :       if (bitwise_mode_for_size (sz).exists (&mode)
    1941            0 :           && known_eq (GET_MODE_BITSIZE (mode), sz))
    1942            0 :         type = bitwise_type_for_mode (mode);
    1943              :       else
    1944              :         {
    1945            5 :           mode = VOIDmode;
    1946            5 :           type = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (op, 0)));
    1947              :         }
    1948            5 :       if (TYPE_ALIGN (type) < TYPE_ALIGN (TREE_TYPE (op)))
    1949            0 :         type = build_aligned_type (type, TYPE_ALIGN (TREE_TYPE (op)));
    1950            5 :       var = create_tmp_var (type);
    1951            5 :       TREE_ADDRESSABLE (var) = 1;
    1952            5 :       gimple *g;
    1953            5 :       if (mode != VOIDmode)
    1954              :         {
    1955            0 :           bfr = build3 (BIT_FIELD_REF, type, TREE_OPERAND (op, 0),
    1956            0 :                         TYPE_SIZE (type), TREE_OPERAND (op, 2));
    1957            0 :           gassign *a = gimple_build_assign (make_ssa_name (type),
    1958              :                                             BIT_FIELD_REF, bfr);
    1959            0 :           gimple_set_location (a, m_loc);
    1960            0 :           gsi_insert_after (&m_init_gsi, a, GSI_NEW_STMT);
    1961            0 :           bfr = gimple_assign_lhs (a);
    1962              :         }
    1963              :       else
    1964            5 :         bfr = TREE_OPERAND (op, 0);
    1965            5 :       g = gimple_build_assign (var, bfr);
    1966            5 :       gimple_set_location (g, m_loc);
    1967            5 :       gsi_insert_after (&m_init_gsi, g, GSI_NEW_STMT);
    1968            5 :       if (mode == VOIDmode)
    1969              :         {
    1970            5 :           unsigned HOST_WIDE_INT nelts
    1971            5 :             = CEIL (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (op))), limb_prec);
    1972            5 :           tree atype = build_array_type_nelts (m_limb_type, nelts);
    1973            5 :           var = build2 (MEM_REF, atype, build_fold_addr_expr (var),
    1974              :                         build_int_cst (build_pointer_type (type),
    1975            5 :                                        tree_to_uhwi (TREE_OPERAND (op, 2))
    1976            5 :                                        / BITS_PER_UNIT));
    1977              :         }
    1978            5 :       m_data.safe_push (var);
    1979              :     }
    1980              :   else
    1981            5 :     var = unshare_expr (m_data[m_data_cnt]);
    1982           10 :   ++m_data_cnt;
    1983           10 :   var = limb_access (TREE_TYPE (op), var, idx, false);
    1984           10 :   tree r = make_ssa_name (m_limb_type);
    1985           10 :   gimple *g = gimple_build_assign (r, var);
    1986           10 :   insert_before (g);
    1987           10 :   return r;
    1988              : }
    1989              : 
    1990              : /* Add a new EH edge from SRC to EH_EDGE->dest, where EH_EDGE
    1991              :    is an older EH edge, and except for virtual PHIs duplicate the
    1992              :    PHI argument from the EH_EDGE to the new EH edge.  */
    1993              : 
    1994              : static void
    1995           20 : add_eh_edge (basic_block src, edge eh_edge)
    1996              : {
    1997           20 :   edge e = make_edge (src, eh_edge->dest, EDGE_EH);
    1998           20 :   e->probability = profile_probability::very_unlikely ();
    1999           20 :   for (gphi_iterator gsi = gsi_start_phis (eh_edge->dest);
    2000           27 :        !gsi_end_p (gsi); gsi_next (&gsi))
    2001              :     {
    2002            7 :       gphi *phi = gsi.phi ();
    2003            7 :       tree lhs = gimple_phi_result (phi);
    2004           14 :       if (virtual_operand_p (lhs))
    2005            4 :         continue;
    2006            3 :       const phi_arg_d *arg = gimple_phi_arg (phi, eh_edge->dest_idx);
    2007            3 :       add_phi_arg (phi, arg->def, e, arg->locus);
    2008              :     }
    2009           20 : }
    2010              : 
    2011              : /* Helper function for handle_stmt method, handle a load from memory.  */
    2012              : 
    2013              : tree
    2014        21550 : bitint_large_huge::handle_load (gimple *stmt, tree idx)
    2015              : {
    2016        21550 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    2017        21550 :   tree rhs_type = TREE_TYPE (rhs1);
    2018        21550 :   bool eh = stmt_ends_bb_p (stmt);
    2019        21550 :   bool load_bitfield_p = false;
    2020        21550 :   edge eh_edge = NULL;
    2021        21550 :   gimple *g;
    2022              : 
    2023        21550 :   if (TREE_CODE (rhs1) == BIT_FIELD_REF
    2024        21550 :       && integer_zerop (TREE_OPERAND (rhs1, 2)))
    2025            2 :     rhs1 = TREE_OPERAND (rhs1, 0);
    2026              : 
    2027        21550 :   if (eh)
    2028              :     {
    2029           10 :       edge_iterator ei;
    2030           10 :       basic_block bb = gimple_bb (stmt);
    2031              : 
    2032           10 :       FOR_EACH_EDGE (eh_edge, ei, bb->succs)
    2033           10 :         if (eh_edge->flags & EDGE_EH)
    2034              :             break;
    2035              :     }
    2036              : 
    2037        21550 :   if (TREE_CODE (rhs1) == COMPONENT_REF
    2038        21550 :       && DECL_BIT_FIELD_TYPE (TREE_OPERAND (rhs1, 1)))
    2039              :     {
    2040         1267 :       tree fld = TREE_OPERAND (rhs1, 1);
    2041              :       /* For little-endian, we can allow as inputs bit-fields
    2042              :          which start at a limb boundary.  */
    2043         1267 :       gcc_assert (tree_fits_uhwi_p (DECL_FIELD_BIT_OFFSET (fld)));
    2044         1267 :       if (!bitint_big_endian
    2045         1267 :           && DECL_OFFSET_ALIGN (fld) >= TYPE_ALIGN (TREE_TYPE (rhs1))
    2046         2534 :           && (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld)) % limb_prec) == 0)
    2047              :         {
    2048          739 :           load_bitfield_p = true;
    2049          751 :           goto normal_load;
    2050              :         }
    2051              :       /* Even if DECL_FIELD_BIT_OFFSET (fld) is a multiple of BITS_PER_UNIT,
    2052              :          handle it normally for now.  */
    2053          528 :       if (!bitint_big_endian
    2054          528 :           && (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld)) % BITS_PER_UNIT) == 0)
    2055              :         {
    2056           12 :           load_bitfield_p = true;
    2057           12 :           goto normal_load;
    2058              :         }
    2059          516 :       tree repr = DECL_BIT_FIELD_REPRESENTATIVE (fld);
    2060          516 :       poly_int64 bitoffset;
    2061          516 :       poly_uint64 field_offset, repr_offset;
    2062          516 :       bool var_field_off = false;
    2063          516 :       if (poly_int_tree_p (DECL_FIELD_OFFSET (fld), &field_offset)
    2064         1032 :           && poly_int_tree_p (DECL_FIELD_OFFSET (repr), &repr_offset))
    2065          516 :         bitoffset = (field_offset - repr_offset) * BITS_PER_UNIT;
    2066              :       else
    2067              :         {
    2068              :           bitoffset = 0;
    2069              :           var_field_off = true;
    2070              :         }
    2071          516 :       bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld))
    2072          516 :                     - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
    2073         1032 :       tree nrhs1 = build3 (COMPONENT_REF, TREE_TYPE (repr),
    2074          516 :                            TREE_OPERAND (rhs1, 0), repr,
    2075            0 :                            var_field_off ? TREE_OPERAND (rhs1, 2) : NULL_TREE);
    2076          516 :       HOST_WIDE_INT bo = bitoffset.to_constant ();
    2077          516 :       unsigned bo_idx = (unsigned HOST_WIDE_INT) bo / limb_prec;
    2078          516 :       unsigned bo_bit = (unsigned HOST_WIDE_INT) bo % limb_prec;
    2079          516 :       unsigned bo_last = 0;
    2080          516 :       unsigned bo_shift = bo_bit;
    2081          516 :       unsigned nelts = CEIL (TYPE_PRECISION (rhs_type), limb_prec);
    2082          516 :       if (bitint_big_endian)
    2083              :         {
    2084            0 :           bo_last = CEIL (TYPE_PRECISION (rhs_type) + bo_bit, limb_prec) - 1;
    2085            0 :           bo_shift = (TYPE_PRECISION (rhs_type) + bo_bit) % limb_prec;
    2086            0 :           if (bo_shift)
    2087            0 :             bo_shift = limb_prec - bo_shift;
    2088              :         }
    2089          516 :       if (m_first)
    2090              :         {
    2091          153 :           if (m_upwards && bo_shift)
    2092              :             {
    2093          150 :               gimple_stmt_iterator save_gsi = m_gsi;
    2094          150 :               m_gsi = m_init_gsi;
    2095          150 :               if (gsi_end_p (m_gsi))
    2096           61 :                 m_gsi = gsi_after_labels (gsi_bb (m_gsi));
    2097              :               else
    2098           89 :                 gsi_next (&m_gsi);
    2099          150 :               tree t = limb_access (NULL_TREE, nrhs1,
    2100          150 :                                     size_int (bo_idx + bo_last), true);
    2101          150 :               tree iv = make_ssa_name (m_limb_type);
    2102          150 :               g = gimple_build_assign (iv, t);
    2103          150 :               insert_before (g);
    2104          150 :               if (eh)
    2105              :                 {
    2106            2 :                   maybe_duplicate_eh_stmt (g, stmt);
    2107            2 :                   if (eh_edge)
    2108              :                     {
    2109            2 :                       edge e = split_block (gsi_bb (m_gsi), g);
    2110            2 :                       add_eh_edge (e->src, eh_edge);
    2111            2 :                       m_gsi = gsi_after_labels (e->dest);
    2112            2 :                       if (gsi_bb (save_gsi) == e->src)
    2113              :                         {
    2114            1 :                           if (gsi_end_p (save_gsi))
    2115            0 :                             save_gsi = gsi_end_bb (e->dest);
    2116              :                           else
    2117            1 :                             save_gsi = gsi_for_stmt (gsi_stmt (save_gsi));
    2118              :                         }
    2119            2 :                       if (m_preheader_bb == e->src)
    2120            1 :                         m_preheader_bb = e->dest;
    2121              :                     }
    2122              :                 }
    2123          150 :               m_init_gsi = m_gsi;
    2124          150 :               if (gsi_end_p (m_init_gsi))
    2125          246 :                 m_init_gsi = gsi_last_bb (gsi_bb (m_init_gsi));
    2126              :               else
    2127           28 :                 gsi_prev (&m_init_gsi);
    2128          150 :               m_gsi = save_gsi;
    2129          150 :               tree out;
    2130          150 :               prepare_data_in_out (iv, idx, &out);
    2131          150 :               out = m_data[m_data_cnt];
    2132          150 :               m_data.safe_push (out);
    2133          150 :             }
    2134              :           else
    2135              :             {
    2136            3 :               m_data.safe_push (NULL_TREE);
    2137            3 :               m_data.safe_push (NULL_TREE);
    2138            3 :               m_data.safe_push (NULL_TREE);
    2139              :             }
    2140              :         }
    2141              : 
    2142          516 :       tree nidx0 = NULL_TREE, nidx1 = NULL_TREE;
    2143          516 :       tree iv = m_data[m_data_cnt];
    2144          516 :       if (m_cast_conditional && iv)
    2145              :         {
    2146           12 :           gcc_assert (!m_bitfld_load);
    2147           12 :           m_bitfld_load = m_data_cnt;
    2148              :         }
    2149          516 :       if (tree_fits_uhwi_p (idx))
    2150              :         {
    2151          290 :           unsigned prec = TYPE_PRECISION (rhs_type);
    2152          290 :           unsigned HOST_WIDE_INT i = tree_to_uhwi (idx);
    2153          290 :           if (bitint_big_endian)
    2154            0 :             i = nelts - 1 - i;
    2155          290 :           gcc_assert (i * limb_prec < prec);
    2156          290 :           if (bo_shift)
    2157          290 :             nidx1 = size_int (bo_idx + (bitint_big_endian
    2158              :                                         ? bo_last - i - 1 : i + 1));
    2159          290 :           if ((i + 1) * limb_prec > prec)
    2160              :             {
    2161          109 :               prec %= limb_prec;
    2162          109 :               if (prec + bo_bit <= (unsigned) limb_prec)
    2163          290 :                 nidx1 = NULL_TREE;
    2164              :             }
    2165          290 :           if (!iv)
    2166            4 :             nidx0 = size_int (bo_idx + (bitint_big_endian ? bo_last - i : i));
    2167              :         }
    2168              :       else
    2169              :         {
    2170          226 :           HOST_WIDE_INT adj = bo_idx;
    2171          226 :           if (bitint_big_endian)
    2172            0 :             adj += (HOST_WIDE_INT) bo_last + 1 - nelts;
    2173          226 :           if (!iv)
    2174              :             {
    2175            4 :               if (adj == 0)
    2176              :                 nidx0 = idx;
    2177              :               else
    2178              :                 {
    2179            0 :                   nidx0 = make_ssa_name (sizetype);
    2180            0 :                   g = gimple_build_assign (nidx0, PLUS_EXPR, idx,
    2181            0 :                                            size_int (adj));
    2182            0 :                   insert_before (g);
    2183              :                 }
    2184              :             }
    2185          226 :           if (bo_shift)
    2186              :             {
    2187          226 :               if (bitint_big_endian && adj == 1)
    2188              :                 nidx1 = idx;
    2189              :               else
    2190              :                 {
    2191          226 :                   nidx1 = make_ssa_name (sizetype);
    2192          226 :                   g = gimple_build_assign (nidx1, PLUS_EXPR, idx,
    2193          452 :                                            size_int (adj + (bitint_big_endian
    2194              :                                                             ? -1 : 1)));
    2195          226 :                   insert_before (g);
    2196              :                 }
    2197              :             }
    2198              :         }
    2199              : 
    2200          746 :       tree iv2 = NULL_TREE;
    2201          230 :       if (nidx0)
    2202              :         {
    2203            8 :           tree t = limb_access (NULL_TREE, nrhs1, nidx0, true);
    2204            8 :           iv = make_ssa_name (m_limb_type);
    2205            8 :           g = gimple_build_assign (iv, t);
    2206            8 :           insert_before (g);
    2207            8 :           if (eh)
    2208              :             {
    2209            0 :               maybe_duplicate_eh_stmt (g, stmt);
    2210            0 :               if (eh_edge)
    2211              :                 {
    2212            0 :                   edge e = split_block (gsi_bb (m_gsi), g);
    2213            0 :                   m_gsi = gsi_after_labels (e->dest);
    2214            0 :                   add_eh_edge (e->src, eh_edge);
    2215              :                 }
    2216              :             }
    2217              :         }
    2218          516 :       if (nidx1)
    2219              :         {
    2220          427 :           bool conditional = m_var_msb && !tree_fits_uhwi_p (idx);
    2221          427 :           unsigned prec = TYPE_PRECISION (rhs_type);
    2222          427 :           if (conditional)
    2223              :             {
    2224            3 :               if ((prec % limb_prec) == 0
    2225            3 :                   || ((prec % limb_prec) + bo_bit > (unsigned) limb_prec))
    2226          424 :                 conditional = false;
    2227              :             }
    2228          427 :           edge edge_true = NULL, edge_false = NULL;
    2229          427 :           if (conditional)
    2230              :             {
    2231            6 :               g = gimple_build_cond (NE_EXPR, idx,
    2232              :                                      bitint_big_endian
    2233              :                                      ? size_zero_node
    2234            3 :                                      : size_int (prec / limb_prec),
    2235              :                                      NULL_TREE, NULL_TREE);
    2236            3 :               if_then (g, profile_probability::likely (),
    2237              :                        edge_true, edge_false);
    2238              :             }
    2239          427 :           tree t = limb_access (NULL_TREE, nrhs1, nidx1, true);
    2240          427 :           if (m_upwards_2limb
    2241          325 :               && !m_first
    2242          214 :               && !m_bitfld_load
    2243          208 :               && !tree_fits_uhwi_p (idx))
    2244          107 :             iv2 = m_data[m_data_cnt + 1];
    2245              :           else
    2246          320 :             iv2 = make_ssa_name (m_limb_type);
    2247          427 :           g = gimple_build_assign (iv2, t);
    2248          427 :           insert_before (g);
    2249          427 :           if (eh)
    2250              :             {
    2251            5 :               maybe_duplicate_eh_stmt (g, stmt);
    2252            5 :               if (eh_edge)
    2253              :                 {
    2254            5 :                   edge e = split_block (gsi_bb (m_gsi), g);
    2255            5 :                   m_gsi = gsi_after_labels (e->dest);
    2256            5 :                   add_eh_edge (e->src, eh_edge);
    2257              :                 }
    2258              :             }
    2259          427 :           if (conditional)
    2260              :             {
    2261            3 :               tree iv3 = make_ssa_name (m_limb_type);
    2262            3 :               if (eh)
    2263            0 :                 edge_true = find_edge (gsi_bb (m_gsi), edge_false->dest);
    2264            3 :               gphi *phi = create_phi_node (iv3, edge_true->dest);
    2265            3 :               add_phi_arg (phi, iv2, edge_true, UNKNOWN_LOCATION);
    2266            3 :               add_phi_arg (phi, build_zero_cst (m_limb_type),
    2267              :                            edge_false, UNKNOWN_LOCATION);
    2268            3 :               m_gsi = gsi_after_labels (edge_true->dest);
    2269            3 :               iv2 = iv3;
    2270              :             }
    2271              :         }
    2272          516 :       if (bo_shift)
    2273              :         {
    2274          516 :           gassign *a
    2275          516 :             = gimple_build_assign (make_ssa_name (m_limb_type), RSHIFT_EXPR,
    2276              :                                    iv, build_int_cst (unsigned_type_node,
    2277          516 :                                                       bo_shift));
    2278          516 :           insert_before (a);
    2279          516 :           iv = gimple_assign_lhs (a);
    2280              :         }
    2281          516 :       if (iv2)
    2282              :         {
    2283          427 :           gassign *a
    2284          427 :             = gimple_build_assign (make_ssa_name (m_limb_type), LSHIFT_EXPR,
    2285              :                                    iv2, build_int_cst (unsigned_type_node,
    2286          427 :                                                        limb_prec - bo_shift));
    2287          427 :           insert_before (a);
    2288          427 :           a = gimple_build_assign (make_ssa_name (m_limb_type), BIT_IOR_EXPR,
    2289              :                                    gimple_assign_lhs (a), iv);
    2290          427 :           insert_before (a);
    2291          427 :           iv = gimple_assign_lhs (a);
    2292          427 :           if (m_data[m_data_cnt])
    2293          421 :             m_data[m_data_cnt] = iv2;
    2294              :         }
    2295          516 :       if (tree_fits_uhwi_p (idx))
    2296              :         {
    2297          290 :           tree atype = limb_access_type (rhs_type, idx);
    2298          290 :           if (!useless_type_conversion_p (atype, TREE_TYPE (iv)))
    2299          109 :             iv = add_cast (atype, iv);
    2300              :         }
    2301          516 :       m_data_cnt += 3;
    2302          516 :       return iv;
    2303              :     }
    2304              : 
    2305        21034 : normal_load:
    2306              :   /* Use write_p = true for loads with EH edges to make
    2307              :      sure limb_access doesn't add a cast as separate
    2308              :      statement after it.  */
    2309        21034 :   rhs1 = limb_access (rhs_type, rhs1, idx, eh, !load_bitfield_p);
    2310        21034 :   tree ret = make_ssa_name (TREE_TYPE (rhs1));
    2311        21034 :   g = gimple_build_assign (ret, rhs1);
    2312        21034 :   insert_before (g);
    2313        21034 :   if (eh)
    2314              :     {
    2315            3 :       maybe_duplicate_eh_stmt (g, stmt);
    2316            3 :       if (eh_edge)
    2317              :         {
    2318            3 :           edge e = split_block (gsi_bb (m_gsi), g);
    2319            3 :           m_gsi = gsi_after_labels (e->dest);
    2320            3 :           add_eh_edge (e->src, eh_edge);
    2321              :         }
    2322            3 :       if (tree_fits_uhwi_p (idx))
    2323              :         {
    2324            1 :           tree atype = limb_access_type (rhs_type, idx);
    2325            1 :           if (!useless_type_conversion_p (atype, TREE_TYPE (rhs1)))
    2326            1 :             ret = add_cast (atype, ret);
    2327              :         }
    2328              :     }
    2329              :   return ret;
    2330              : }
    2331              : 
    2332              : /* Return a limb IDX from a mergeable statement STMT.  */
    2333              : 
    2334              : tree
    2335        41822 : bitint_large_huge::handle_stmt (gimple *stmt, tree idx)
    2336              : {
    2337        41822 :   tree lhs, rhs1, rhs2 = NULL_TREE;
    2338        41822 :   gimple *g;
    2339        41822 :   switch (gimple_code (stmt))
    2340              :     {
    2341        41822 :     case GIMPLE_ASSIGN:
    2342        41822 :       if (gimple_assign_load_p (stmt))
    2343        21550 :         return handle_load (stmt, idx);
    2344        20272 :       switch (gimple_assign_rhs_code (stmt))
    2345              :         {
    2346         1632 :         case BIT_AND_EXPR:
    2347         1632 :         case BIT_IOR_EXPR:
    2348         1632 :         case BIT_XOR_EXPR:
    2349         1632 :           rhs2 = handle_operand (gimple_assign_rhs2 (stmt), idx);
    2350              :           /* FALLTHRU */
    2351         2230 :         case BIT_NOT_EXPR:
    2352         2230 :           rhs1 = handle_operand (gimple_assign_rhs1 (stmt), idx);
    2353         2230 :           lhs = make_ssa_name (TREE_TYPE (rhs1));
    2354         2230 :           g = gimple_build_assign (lhs, gimple_assign_rhs_code (stmt),
    2355              :                                    rhs1, rhs2);
    2356         2230 :           insert_before (g);
    2357         2230 :           return lhs;
    2358         5061 :         case PLUS_EXPR:
    2359         5061 :         case MINUS_EXPR:
    2360         5061 :           rhs1 = handle_operand (gimple_assign_rhs1 (stmt), idx);
    2361         5061 :           rhs2 = handle_operand (gimple_assign_rhs2 (stmt), idx);
    2362         5061 :           return handle_plus_minus (gimple_assign_rhs_code (stmt),
    2363         5061 :                                     rhs1, rhs2, idx);
    2364          178 :         case NEGATE_EXPR:
    2365          178 :           rhs2 = handle_operand (gimple_assign_rhs1 (stmt), idx);
    2366          178 :           rhs1 = build_zero_cst (TREE_TYPE (rhs2));
    2367          178 :           return handle_plus_minus (MINUS_EXPR, rhs1, rhs2, idx);
    2368          224 :         case LSHIFT_EXPR:
    2369          224 :           return handle_lshift (handle_operand (gimple_assign_rhs1 (stmt),
    2370              :                                                 idx),
    2371          224 :                                 gimple_assign_rhs2 (stmt), idx);
    2372         5476 :         case SSA_NAME:
    2373         5476 :         case PAREN_EXPR:
    2374         5476 :         case INTEGER_CST:
    2375         5476 :           return handle_operand (gimple_assign_rhs1 (stmt), idx);
    2376         7072 :         CASE_CONVERT:
    2377         7072 :           return handle_cast (TREE_TYPE (gimple_assign_lhs (stmt)),
    2378         7072 :                               gimple_assign_rhs1 (stmt), idx);
    2379            8 :         case VIEW_CONVERT_EXPR:
    2380            8 :           return handle_cast (TREE_TYPE (gimple_assign_lhs (stmt)),
    2381            8 :                               TREE_OPERAND (gimple_assign_rhs1 (stmt), 0),
    2382            8 :                               idx);
    2383           23 :         case BIT_FIELD_REF:
    2384           23 :           return handle_bit_field_ref (gimple_assign_rhs1 (stmt), idx);
    2385              :         default:
    2386              :           break;
    2387              :         }
    2388              :       break;
    2389              :     default:
    2390              :       break;
    2391              :     }
    2392            0 :   gcc_unreachable ();
    2393              : }
    2394              : 
    2395              : /* Return minimum precision of OP at STMT.
    2396              :    Positive value is minimum precision above which all bits
    2397              :    are zero, negative means all bits above negation of the
    2398              :    value are copies of the sign bit.  */
    2399              : 
    2400              : static int
    2401         8524 : range_to_prec (tree op, gimple *stmt)
    2402              : {
    2403         8524 :   int_range_max r;
    2404         8524 :   wide_int w;
    2405         8524 :   tree type = TREE_TYPE (op);
    2406         8524 :   unsigned int prec = TYPE_PRECISION (type);
    2407              : 
    2408         8524 :   if (!optimize
    2409         7650 :       || !get_range_query (cfun)->range_of_expr (r, op, stmt)
    2410        12349 :       || r.undefined_p ())
    2411              :     {
    2412         4700 :       if (TYPE_UNSIGNED (type))
    2413         1908 :         return prec;
    2414              :       else
    2415         2792 :         return MIN ((int) -prec, -2);
    2416              :     }
    2417              : 
    2418         3824 :   if (!TYPE_UNSIGNED (TREE_TYPE (op)))
    2419              :     {
    2420         2358 :       w = r.lower_bound ();
    2421         2358 :       if (wi::neg_p (w))
    2422              :         {
    2423         1953 :           int min_prec1 = wi::min_precision (w, SIGNED);
    2424         1953 :           w = r.upper_bound ();
    2425         1953 :           int min_prec2 = wi::min_precision (w, SIGNED);
    2426         1953 :           int min_prec = MAX (min_prec1, min_prec2);
    2427         1953 :           return MIN (-min_prec, -2);
    2428              :         }
    2429              :     }
    2430              : 
    2431         1871 :   w = r.upper_bound ();
    2432         1871 :   int min_prec = wi::min_precision (w, UNSIGNED);
    2433         1871 :   return MAX (min_prec, 1);
    2434         8524 : }
    2435              : 
    2436              : /* Return address of the first limb of OP and write into *PREC
    2437              :    its precision.  If positive, the operand is zero extended
    2438              :    from that precision, if it is negative, the operand is sign-extended
    2439              :    from -*PREC.  If PREC_STORED is NULL, it is the toplevel call,
    2440              :    otherwise *PREC_STORED is prec from the innermost call without
    2441              :    range optimizations (0 for uninitialized SSA_NAME).  */
    2442              : 
    2443              : tree
    2444         4012 : bitint_large_huge::handle_operand_addr (tree op, gimple *stmt,
    2445              :                                         int *prec_stored, int *prec)
    2446              : {
    2447         4012 :   wide_int w;
    2448         4012 :   location_t loc_save = m_loc;
    2449         4012 :   tree ret = NULL_TREE;
    2450         4012 :   int precs = 0;
    2451         4047 :   if ((!BITINT_TYPE_P (TREE_TYPE (op))
    2452         3983 :        || bitint_precision_kind (TREE_TYPE (op)) < bitint_prec_large)
    2453         4136 :       && TREE_CODE (op) != INTEGER_CST)
    2454              :     {
    2455          126 :     do_int:
    2456          126 :       *prec = range_to_prec (op, stmt);
    2457          126 :       bitint_prec_kind kind = bitint_prec_small;
    2458          126 :       gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (op)));
    2459          126 :       if (BITINT_TYPE_P (TREE_TYPE (op)))
    2460          106 :         kind = bitint_precision_kind (TREE_TYPE (op));
    2461          106 :       if (kind == bitint_prec_middle)
    2462              :         {
    2463           12 :           tree type = NULL_TREE;
    2464           12 :           op = maybe_cast_middle_bitint (&m_gsi, op, type);
    2465              :         }
    2466          126 :       tree op_type = TREE_TYPE (op);
    2467          126 :       unsigned HOST_WIDE_INT nelts
    2468          126 :         = CEIL (TYPE_PRECISION (op_type), limb_prec);
    2469              :       /* Add support for 3 or more limbs filled in from normal
    2470              :          integral type if this assert fails.  If no target chooses
    2471              :          limb mode smaller than half of largest supported normal
    2472              :          integral type, this will not be needed.  */
    2473          126 :       gcc_assert (nelts <= 2);
    2474          126 :       precs = (TYPE_UNSIGNED (op_type)
    2475          126 :                ? TYPE_PRECISION (op_type) : -TYPE_PRECISION (op_type));
    2476          126 :       if (*prec <= limb_prec && *prec >= -limb_prec)
    2477              :         {
    2478          113 :           nelts = 1;
    2479          113 :           if (TYPE_UNSIGNED (op_type))
    2480              :             {
    2481           26 :               if (precs > limb_prec)
    2482          126 :                 precs = limb_prec;
    2483              :             }
    2484           87 :           else if (precs < -limb_prec)
    2485          126 :             precs = -limb_prec;
    2486              :         }
    2487          126 :       if (prec_stored)
    2488            0 :         *prec_stored = precs;
    2489          126 :       tree atype = build_array_type_nelts (m_limb_type, nelts);
    2490          126 :       tree var = create_tmp_var (atype);
    2491          126 :       tree t1 = op;
    2492          126 :       if (!useless_type_conversion_p (m_limb_type, op_type))
    2493          126 :         t1 = add_cast (m_limb_type, t1);
    2494          126 :       tree v = build4 (ARRAY_REF, m_limb_type, var,
    2495            0 :                        bitint_big_endian && nelts > 1
    2496              :                        ? size_one_node : size_zero_node,
    2497              :                        NULL_TREE, NULL_TREE);
    2498          126 :       gimple *g = gimple_build_assign (v, t1);
    2499          126 :       insert_before (g);
    2500          126 :       if (nelts > 1)
    2501              :         {
    2502           13 :           tree lp = build_int_cst (unsigned_type_node, limb_prec);
    2503           13 :           gassign *a = gimple_build_assign (make_ssa_name (op_type),
    2504              :                                             RSHIFT_EXPR, op, lp);
    2505           13 :           insert_before (a);
    2506           13 :           tree t2 = gimple_assign_lhs (a);
    2507           13 :           t2 = add_cast (m_limb_type, t2);
    2508           13 :           v = build4 (ARRAY_REF, m_limb_type, var,
    2509              :                       bitint_big_endian ? size_zero_node : size_one_node,
    2510              :                       NULL_TREE, NULL_TREE);
    2511           13 :           a = gimple_build_assign (v, t2);
    2512           13 :           insert_before (a);
    2513              :         }
    2514          126 :       ret = build_fold_addr_expr (var);
    2515          126 :       if (!stmt_ends_bb_p (gsi_stmt (m_gsi)))
    2516              :         {
    2517          125 :           tree clobber = build_clobber (atype, CLOBBER_STORAGE_END);
    2518          125 :           g = gimple_build_assign (var, clobber);
    2519          125 :           gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
    2520              :         }
    2521          126 :       m_loc = loc_save;
    2522          126 :       goto do_ret;
    2523              :     }
    2524         3936 :   switch (TREE_CODE (op))
    2525              :     {
    2526         3000 :     case SSA_NAME:
    2527         3000 :       if (m_names == NULL
    2528         3000 :           || !bitmap_bit_p (m_names, SSA_NAME_VERSION (op)))
    2529              :         {
    2530          104 :           gimple *g = SSA_NAME_DEF_STMT (op);
    2531          104 :           m_loc = gimple_location (g);
    2532          104 :           if (gimple_assign_load_p (g))
    2533              :             {
    2534           36 :               *prec = range_to_prec (op, NULL);
    2535           36 :               precs = (TYPE_UNSIGNED (TREE_TYPE (op))
    2536           36 :                        ? TYPE_PRECISION (TREE_TYPE (op))
    2537           25 :                        : -TYPE_PRECISION (TREE_TYPE (op)));
    2538           36 :               if (prec_stored)
    2539            6 :                 *prec_stored = precs;
    2540           36 :               ret = build_fold_addr_expr (gimple_assign_rhs1 (g));
    2541           36 :               ret = force_gimple_operand_gsi (&m_gsi, ret, true,
    2542              :                                               NULL_TREE, true, GSI_SAME_STMT);
    2543              :             }
    2544           68 :           else if (gimple_code (g) == GIMPLE_NOP)
    2545              :             {
    2546            2 :               *prec = TYPE_UNSIGNED (TREE_TYPE (op)) ? limb_prec : -limb_prec;
    2547            2 :               precs = *prec;
    2548            2 :               if (prec_stored)
    2549            1 :                 *prec_stored = 0;
    2550            2 :               tree var = create_tmp_var (m_limb_type);
    2551            2 :               TREE_ADDRESSABLE (var) = 1;
    2552            2 :               ret = build_fold_addr_expr (var);
    2553            2 :               if (!stmt_ends_bb_p (gsi_stmt (m_gsi)))
    2554              :                 {
    2555            2 :                   tree clobber = build_clobber (m_limb_type,
    2556              :                                                 CLOBBER_STORAGE_END);
    2557            2 :                   g = gimple_build_assign (var, clobber);
    2558            2 :                   gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
    2559              :                 }
    2560              :             }
    2561              :           else
    2562              :             {
    2563           66 :               gcc_assert (gimple_assign_cast_p (g));
    2564           66 :               tree rhs1 = gimple_assign_rhs1 (g);
    2565           66 :               bitint_prec_kind kind = bitint_prec_small;
    2566           66 :               if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR)
    2567            1 :                 rhs1 = TREE_OPERAND (rhs1, 0);
    2568           66 :               gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (rhs1)));
    2569           66 :               if (BITINT_TYPE_P (TREE_TYPE (rhs1)))
    2570           51 :                 kind = bitint_precision_kind (TREE_TYPE (rhs1));
    2571           51 :               if (kind >= bitint_prec_large)
    2572              :                 {
    2573           16 :                   tree lhs_type = TREE_TYPE (op);
    2574           16 :                   tree rhs_type = TREE_TYPE (rhs1);
    2575           16 :                   int prec_stored_val = 0;
    2576           16 :                   ret = handle_operand_addr (rhs1, g, &prec_stored_val, prec);
    2577           16 :                   precs = prec_stored_val;
    2578           16 :                   if (prec_stored)
    2579            0 :                     *prec_stored = prec_stored_val;
    2580           16 :                   if (precs == 0)
    2581              :                     {
    2582            1 :                       gcc_assert (*prec == limb_prec || *prec == -limb_prec);
    2583              :                       precs = *prec;
    2584              :                     }
    2585           16 :                   if (TYPE_PRECISION (lhs_type) > TYPE_PRECISION (rhs_type))
    2586              :                     {
    2587            4 :                       if (TYPE_UNSIGNED (lhs_type)
    2588            4 :                           && !TYPE_UNSIGNED (rhs_type))
    2589            1 :                         gcc_assert (*prec >= 0 || prec_stored == NULL);
    2590              :                     }
    2591              :                   else
    2592              :                     {
    2593           12 :                       if (prec_stored_val == 0)
    2594              :                         /* Non-widening cast of uninitialized value.  */;
    2595           11 :                       else if (*prec > 0 && *prec < TYPE_PRECISION (lhs_type))
    2596              :                         ;
    2597           11 :                       else if (TYPE_UNSIGNED (lhs_type))
    2598              :                         {
    2599            8 :                           gcc_assert (*prec > 0
    2600              :                                       || prec_stored_val > 0
    2601              :                                       || (-prec_stored_val
    2602              :                                           >= TYPE_PRECISION (lhs_type)));
    2603            8 :                           *prec = TYPE_PRECISION (lhs_type);
    2604              :                         }
    2605            3 :                       else if (*prec < 0 && -*prec < TYPE_PRECISION (lhs_type))
    2606              :                         ;
    2607              :                       else
    2608            3 :                         *prec = -TYPE_PRECISION (lhs_type);
    2609              :                     }
    2610              :                 }
    2611              :               else
    2612              :                 {
    2613           50 :                   op = rhs1;
    2614           50 :                   stmt = g;
    2615           50 :                   goto do_int;
    2616              :                 }
    2617              :             }
    2618           54 :           m_loc = loc_save;
    2619           54 :           goto do_ret;
    2620              :         }
    2621              :       else
    2622              :         {
    2623         2896 :           int p = var_to_partition (m_map, op);
    2624         2896 :           gcc_assert (m_vars[p] != NULL_TREE);
    2625         2896 :           *prec = range_to_prec (op, stmt);
    2626         2896 :           precs = (TYPE_UNSIGNED (TREE_TYPE (op))
    2627         2896 :                    ? TYPE_PRECISION (TREE_TYPE (op))
    2628         1688 :                    : -TYPE_PRECISION (TREE_TYPE (op)));
    2629         2896 :           if (prec_stored)
    2630            9 :             *prec_stored = precs;
    2631         2896 :           ret = build_fold_addr_expr (m_vars[p]);
    2632         2896 :           goto do_ret;
    2633              :         }
    2634          936 :     case INTEGER_CST:
    2635          936 :       unsigned int min_prec, mp;
    2636          936 :       tree type;
    2637          936 :       w = wi::to_wide (op);
    2638          936 :       if (tree_int_cst_sgn (op) >= 0)
    2639              :         {
    2640          721 :           min_prec = wi::min_precision (w, UNSIGNED);
    2641          721 :           *prec = MAX (min_prec, 1);
    2642              :         }
    2643              :       else
    2644              :         {
    2645          215 :           min_prec = wi::min_precision (w, SIGNED);
    2646          215 :           *prec = MIN ((int) -min_prec, -2);
    2647              :         }
    2648          936 :       mp = CEIL (min_prec, limb_prec) * limb_prec;
    2649          936 :       if (mp == 0)
    2650              :         mp = 1;
    2651          936 :       if (mp >= (unsigned) TYPE_PRECISION (TREE_TYPE (op))
    2652          936 :           && (BITINT_TYPE_P (TREE_TYPE (op))
    2653           24 :               || TYPE_PRECISION (TREE_TYPE (op)) <= limb_prec))
    2654          316 :         type = TREE_TYPE (op);
    2655              :       else
    2656          620 :         type = build_bitint_type (mp, 1);
    2657           20 :       if (!BITINT_TYPE_P (type)
    2658          936 :           || bitint_precision_kind (type) == bitint_prec_small)
    2659              :         {
    2660          657 :           if (TYPE_PRECISION (type) <= limb_prec)
    2661          657 :             type = m_limb_type;
    2662              :           else
    2663              :             {
    2664            0 :               while (bitint_precision_kind (mp) == bitint_prec_small)
    2665            0 :                 mp += limb_prec;
    2666              :               /* This case is for targets which e.g. have 64-bit
    2667              :                  limb but categorize up to 128-bits _BitInts as
    2668              :                  small.  We could use type of m_limb_type[2] and
    2669              :                  similar instead to save space.  */
    2670            0 :               type = build_bitint_type (mp, 1);
    2671              :             }
    2672              :         }
    2673          936 :       if (tree_int_cst_sgn (op) >= 0)
    2674          721 :         precs = MAX (TYPE_PRECISION (type), 1);
    2675              :       else
    2676          215 :         precs = MIN ((int) -TYPE_PRECISION (type), -2);
    2677          936 :       if (prec_stored)
    2678            0 :         *prec_stored = precs;
    2679          936 :       op = tree_output_constant_def (fold_convert (type, op));
    2680          936 :       ret = build_fold_addr_expr (op);
    2681          936 :       goto do_ret;
    2682            0 :     default:
    2683            0 :       gcc_unreachable ();
    2684              :     }
    2685         4012 : do_ret:
    2686         4012 :   if (bitint_big_endian && prec_stored == NULL)
    2687              :     {
    2688            0 :       int p1 = *prec < 0 ? -*prec : *prec;
    2689            0 :       int p2 = precs < 0 ? -precs : precs;
    2690            0 :       int c1 = CEIL (p1, limb_prec);
    2691            0 :       int c2 = CEIL (p2, limb_prec);
    2692            0 :       gcc_assert (c1 <= c2);
    2693            0 :       if (c1 != c2)
    2694              :         {
    2695            0 :           gassign *g
    2696            0 :             = gimple_build_assign (make_ssa_name (TREE_TYPE (ret)),
    2697              :                                    POINTER_PLUS_EXPR, ret,
    2698            0 :                                    size_int ((c2 - c1) * m_limb_size));
    2699            0 :           insert_before (g);
    2700            0 :           ret = gimple_assign_lhs (g);
    2701              :         }
    2702              :     }
    2703         4012 :   return ret;
    2704         4012 : }
    2705              : 
    2706              : /* Helper function, create a loop before the current location,
    2707              :    start with sizetype INIT value from the preheader edge.  Return
    2708              :    a PHI result and set *IDX_NEXT to SSA_NAME it creates and uses
    2709              :    from the latch edge.  */
    2710              : 
    2711              : tree
    2712        16182 : bitint_large_huge::create_loop (tree init, tree *idx_next)
    2713              : {
    2714        16182 :   if (!gsi_end_p (m_gsi))
    2715        17240 :     gsi_prev (&m_gsi);
    2716              :   else
    2717         4946 :     m_gsi = gsi_last_bb (gsi_bb (m_gsi));
    2718        16182 :   edge e1 = split_block (gsi_bb (m_gsi), gsi_stmt (m_gsi));
    2719        16182 :   edge e2 = split_block (e1->dest, (gimple *) NULL);
    2720        16182 :   edge e3 = make_edge (e1->dest, e1->dest, EDGE_TRUE_VALUE);
    2721        16182 :   e3->probability = profile_probability::very_unlikely ();
    2722        16182 :   e2->flags = EDGE_FALSE_VALUE;
    2723        16182 :   e2->probability = e3->probability.invert ();
    2724        16182 :   tree idx = make_ssa_name (sizetype);
    2725        16182 :   gphi *phi = create_phi_node (idx, e1->dest);
    2726        16182 :   add_phi_arg (phi, init, e1, UNKNOWN_LOCATION);
    2727        16182 :   *idx_next = make_ssa_name (sizetype);
    2728        16182 :   add_phi_arg (phi, *idx_next, e3, UNKNOWN_LOCATION);
    2729        16182 :   m_gsi = gsi_after_labels (e1->dest);
    2730        16182 :   m_bb = e1->dest;
    2731        16182 :   m_preheader_bb = e1->src;
    2732        16182 :   class loop *loop = alloc_loop ();
    2733        16182 :   loop->header = e1->dest;
    2734        16182 :   add_loop (loop, e1->src->loop_father);
    2735        16182 :   return idx;
    2736              : }
    2737              : 
    2738              : /* Lower large/huge _BitInt statement mergeable or similar STMT which can be
    2739              :    lowered using iteration from the least significant limb up to the most
    2740              :    significant limb.  For large _BitInt it is emitted as straight line code
    2741              :    before current location, for huge _BitInt as a loop handling two limbs
    2742              :    at once, followed by handling up to limbs in straight line code (at most
    2743              :    one full and one partial limb).  It can also handle EQ_EXPR/NE_EXPR
    2744              :    comparisons, in that case CMP_CODE should be the comparison code and
    2745              :    CMP_OP1/CMP_OP2 the comparison operands.  */
    2746              : 
    2747              : tree
    2748        24675 : bitint_large_huge::lower_mergeable_stmt (gimple *stmt, tree_code &cmp_code,
    2749              :                                          tree cmp_op1, tree cmp_op2)
    2750              : {
    2751        24675 :   bool eq_p = cmp_code != ERROR_MARK;
    2752        24675 :   tree type;
    2753        24675 :   if (eq_p)
    2754         7014 :     type = TREE_TYPE (cmp_op1);
    2755              :   else
    2756        17661 :     type = TREE_TYPE (gimple_assign_lhs (stmt));
    2757        24675 :   gcc_assert (BITINT_TYPE_P (type));
    2758        24675 :   bitint_prec_kind kind = bitint_precision_kind (type);
    2759        24675 :   gcc_assert (kind >= bitint_prec_large);
    2760        24675 :   gimple *g;
    2761        24675 :   tree lhs = gimple_get_lhs (stmt);
    2762        24675 :   tree rhs1, lhs_type = lhs ? TREE_TYPE (lhs) : NULL_TREE;
    2763        18102 :   if (lhs
    2764        18102 :       && TREE_CODE (lhs) == SSA_NAME
    2765         9299 :       && BITINT_TYPE_P (TREE_TYPE (lhs))
    2766         8858 :       && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large)
    2767              :     {
    2768         8858 :       int p = var_to_partition (m_map, lhs);
    2769         8858 :       gcc_assert (m_vars[p] != NULL_TREE);
    2770         8858 :       m_lhs = lhs = m_vars[p];
    2771              :     }
    2772        24675 :   unsigned cnt, rem = 0, end = 0, prec = TYPE_PRECISION (type);
    2773        24675 :   bool sext = false;
    2774        24675 :   tree ext = NULL_TREE, store_operand = NULL_TREE;
    2775        24675 :   bool eh = false;
    2776        24675 :   basic_block eh_pad = NULL;
    2777        24675 :   tree nlhs = NULL_TREE;
    2778        24675 :   unsigned HOST_WIDE_INT bo_idx = 0;
    2779        24675 :   unsigned HOST_WIDE_INT bo_bit = 0;
    2780        24675 :   unsigned bo_shift = 0;
    2781        24675 :   unsigned bo_last = 0;
    2782        24675 :   bool bo_be_p = false;
    2783        24675 :   tree bf_cur = NULL_TREE, bf_next = NULL_TREE;
    2784        24675 :   if (gimple_store_p (stmt))
    2785              :     {
    2786         8803 :       store_operand = gimple_assign_rhs1 (stmt);
    2787         8803 :       eh = stmt_ends_bb_p (stmt);
    2788         8803 :       if (eh)
    2789              :         {
    2790            2 :           edge e;
    2791            2 :           edge_iterator ei;
    2792            2 :           basic_block bb = gimple_bb (stmt);
    2793              : 
    2794            2 :           FOR_EACH_EDGE (e, ei, bb->succs)
    2795            2 :             if (e->flags & EDGE_EH)
    2796              :               {
    2797            2 :                 eh_pad = e->dest;
    2798            2 :                 break;
    2799              :               }
    2800              :         }
    2801         8803 :       if (TREE_CODE (lhs) == COMPONENT_REF
    2802         8803 :           && DECL_BIT_FIELD_TYPE (TREE_OPERAND (lhs, 1)))
    2803              :         {
    2804          175 :           tree fld = TREE_OPERAND (lhs, 1);
    2805          175 :           gcc_assert (tree_fits_uhwi_p (DECL_FIELD_BIT_OFFSET (fld)));
    2806          175 :           tree repr = DECL_BIT_FIELD_REPRESENTATIVE (fld);
    2807          175 :           poly_int64 bitoffset;
    2808          175 :           poly_uint64 field_offset, repr_offset;
    2809          175 :           if (!bitint_big_endian
    2810          175 :               && (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld))
    2811          175 :                   % BITS_PER_UNIT) == 0)
    2812              :             nlhs = lhs;
    2813              :           else
    2814              :             {
    2815          150 :               bool var_field_off = false;
    2816          150 :               if (poly_int_tree_p (DECL_FIELD_OFFSET (fld), &field_offset)
    2817          300 :                   && poly_int_tree_p (DECL_FIELD_OFFSET (repr), &repr_offset))
    2818          150 :                 bitoffset = (field_offset - repr_offset) * BITS_PER_UNIT;
    2819              :               else
    2820              :                 {
    2821              :                   bitoffset = 0;
    2822              :                   var_field_off = true;
    2823              :                 }
    2824          150 :               bitoffset += (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld))
    2825          150 :                             - tree_to_uhwi (DECL_FIELD_BIT_OFFSET (repr)));
    2826          300 :               nlhs = build3 (COMPONENT_REF, TREE_TYPE (repr),
    2827          150 :                              TREE_OPERAND (lhs, 0), repr,
    2828              :                              var_field_off
    2829            0 :                              ? TREE_OPERAND (lhs, 2) : NULL_TREE);
    2830          150 :               HOST_WIDE_INT bo = bitoffset.to_constant ();
    2831          150 :               bo_idx = (unsigned HOST_WIDE_INT) bo / limb_prec;
    2832          150 :               bo_bit = (unsigned HOST_WIDE_INT) bo % limb_prec;
    2833          150 :               bo_shift = bo_bit;
    2834          150 :               if (bitint_big_endian)
    2835              :                 {
    2836            0 :                   bo_last = CEIL (prec + bo_bit, limb_prec) - 1;
    2837            0 :                   bo_shift = (prec + bo_bit) % limb_prec;
    2838            0 :                   bo_be_p = true;
    2839            0 :                   if (bo_shift)
    2840            0 :                     bo_shift = limb_prec - bo_shift;
    2841              :                 }
    2842              :             }
    2843              :         }
    2844              :     }
    2845         8803 :   if ((store_operand
    2846         8803 :        && TREE_CODE (store_operand) == SSA_NAME
    2847         7802 :        && (m_names == NULL
    2848         7772 :            || !bitmap_bit_p (m_names, SSA_NAME_VERSION (store_operand)))
    2849         1226 :        && gimple_assign_cast_p (SSA_NAME_DEF_STMT (store_operand)))
    2850        32919 :       || gimple_assign_cast_p (stmt))
    2851              :     {
    2852         2181 :       rhs1 = gimple_assign_rhs1 (store_operand
    2853          559 :                                  ? SSA_NAME_DEF_STMT (store_operand)
    2854              :                                  : stmt);
    2855         1622 :       if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR)
    2856            2 :         rhs1 = TREE_OPERAND (rhs1, 0);
    2857              :       /* Optimize mergeable ops ending with widening cast to _BitInt
    2858              :          (or followed by store).  We can lower just the limbs of the
    2859              :          cast operand and widen afterwards.  */
    2860         1622 :       if (TREE_CODE (rhs1) == SSA_NAME
    2861         1622 :           && (m_names == NULL
    2862         1616 :               || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1)))
    2863          637 :           && BITINT_TYPE_P (TREE_TYPE (rhs1))
    2864          485 :           && bitint_precision_kind (TREE_TYPE (rhs1)) >= bitint_prec_large
    2865         2056 :           && (CEIL ((unsigned) TYPE_PRECISION (TREE_TYPE (rhs1)),
    2866          434 :                     limb_prec) < CEIL (prec, limb_prec)
    2867          308 :               || (kind == bitint_prec_huge
    2868          262 :                   && TYPE_PRECISION (TREE_TYPE (rhs1)) < prec)))
    2869              :         {
    2870          132 :           store_operand = rhs1;
    2871          132 :           prec = TYPE_PRECISION (TREE_TYPE (rhs1));
    2872          132 :           kind = bitint_precision_kind (TREE_TYPE (rhs1));
    2873          132 :           if (!TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    2874           55 :             sext = true;
    2875              :         }
    2876              :     }
    2877        24675 :   tree idx = NULL_TREE, idx_first = NULL_TREE, idx_next = NULL_TREE;
    2878        24675 :   if (kind == bitint_prec_large)
    2879        12383 :     cnt = CEIL (prec, limb_prec);
    2880              :   else
    2881              :     {
    2882        12292 :       rem = (prec % (2 * limb_prec));
    2883        12292 :       end = (prec - rem) / limb_prec;
    2884        12292 :       cnt = 2 + CEIL (rem, limb_prec);
    2885        12292 :       idx = idx_first = create_loop (bitint_big_endian
    2886        12292 :                                      ? size_int (cnt - 2 + end - 1)
    2887              :                                      : size_zero_node, &idx_next);
    2888              :     }
    2889              : 
    2890        24675 :   basic_block edge_bb = NULL;
    2891        24675 :   if (eq_p)
    2892              :     {
    2893         7014 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    2894         7014 :       gsi_prev (&gsi);
    2895         7014 :       edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    2896         7014 :       edge_bb = e->src;
    2897         7014 :       if (kind == bitint_prec_large)
    2898         7304 :         m_gsi = gsi_end_bb (edge_bb);
    2899              :     }
    2900              :   else
    2901        17661 :     m_after_stmt = stmt;
    2902        24675 :   if (kind != bitint_prec_large)
    2903        12292 :     m_upwards_2limb = end;
    2904        24675 :   m_upwards = true;
    2905              : 
    2906        24675 :   bool separate_ext
    2907        24675 :     = (prec != (unsigned) TYPE_PRECISION (type)
    2908        24675 :        && (CEIL ((unsigned) TYPE_PRECISION (type), limb_prec)
    2909          132 :            > CEIL (prec, limb_prec)));
    2910        24675 :   bool zero_ms_limb = false;
    2911        24675 :   if (bitint_extended == bitint_ext_full
    2912            0 :       && !eq_p
    2913            0 :       && !nlhs
    2914            0 :       && abi_limb_prec > limb_prec
    2915        24675 :       && ((CEIL ((unsigned) TYPE_PRECISION (type), abi_limb_prec)
    2916            0 :            * abi_limb_prec / limb_prec)
    2917            0 :           > CEIL ((unsigned) TYPE_PRECISION (type), limb_prec)))
    2918              :     {
    2919            0 :       if (prec == (unsigned) TYPE_PRECISION (type))
    2920              :         {
    2921            0 :           sext = !TYPE_UNSIGNED (type);
    2922            0 :           separate_ext = true;
    2923              :         }
    2924            0 :       else if (TYPE_UNSIGNED (type) && sext)
    2925              :         zero_ms_limb = true;
    2926              :       else
    2927              :         separate_ext = true;
    2928              :     }
    2929        24801 :   unsigned dst_idx_off = 0;
    2930        24675 :   if (separate_ext && bitint_big_endian)
    2931            0 :     dst_idx_off = (CEIL ((unsigned) TYPE_PRECISION (type), limb_prec)
    2932            0 :                    - CEIL (prec, limb_prec));
    2933              : 
    2934        98748 :   for (unsigned i = 0; i < cnt; i++)
    2935              :     {
    2936        74073 :       m_data_cnt = 0;
    2937        74073 :       if (kind == bitint_prec_large)
    2938        37767 :         idx = size_int (bitint_big_endian ? cnt - 1 - i : i);
    2939        36306 :       else if (i >= 2)
    2940        11722 :         idx = size_int (bitint_big_endian ? cnt - 1 - i : end + (i > 2));
    2941        74073 :       if (eq_p)
    2942              :         {
    2943        21138 :           rhs1 = handle_operand (cmp_op1, idx);
    2944        21138 :           tree rhs2 = handle_operand (cmp_op2, idx);
    2945        21138 :           g = gimple_build_cond (NE_EXPR, rhs1, rhs2, NULL_TREE, NULL_TREE);
    2946        21138 :           insert_before (g);
    2947        21138 :           edge e1 = split_block (gsi_bb (m_gsi), g);
    2948        21138 :           e1->flags = EDGE_FALSE_VALUE;
    2949        21138 :           edge e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE);
    2950        21138 :           e1->probability = profile_probability::unlikely ();
    2951        21138 :           e2->probability = e1->probability.invert ();
    2952        21138 :           if (i == 0)
    2953         7014 :             set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    2954        21138 :           m_gsi = gsi_after_labels (e1->dest);
    2955              :         }
    2956              :       else
    2957              :         {
    2958        52935 :           if (store_operand)
    2959        26627 :             rhs1 = handle_operand (store_operand, idx);
    2960              :           else
    2961        26308 :             rhs1 = handle_stmt (stmt, idx);
    2962        52935 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1)))
    2963        12774 :             rhs1 = add_cast (m_limb_type, rhs1);
    2964        52935 :           if (sext && i == cnt - 1)
    2965        52935 :             ext = rhs1;
    2966        52935 :           tree nidx = idx;
    2967        52935 :           HOST_WIDE_INT adj = bo_idx;
    2968        52935 :           if (bo_be_p)
    2969            0 :             adj += bo_last - (CEIL (prec, limb_prec) - 1);
    2970              :           else
    2971        52935 :             adj += dst_idx_off;
    2972        52935 :           if (adj)
    2973              :             {
    2974          220 :               if (tree_fits_uhwi_p (idx))
    2975          116 :                 nidx = size_int (tree_to_uhwi (idx) + adj);
    2976              :               else
    2977              :                 {
    2978          104 :                   nidx = make_ssa_name (sizetype);
    2979          104 :                   g = gimple_build_assign (nidx, PLUS_EXPR, idx,
    2980          104 :                                            size_int (adj));
    2981          104 :                   insert_before (g);
    2982              :                 }
    2983              :             }
    2984        52935 :           bool done = false;
    2985        52935 :           basic_block new_bb = NULL;
    2986              :           /* Handle stores into bit-fields.  */
    2987        52935 :           if (bo_shift)
    2988              :             {
    2989          483 :               if (i == 0)
    2990              :                 {
    2991          150 :                   edge e2 = NULL;
    2992          150 :                   if (kind != bitint_prec_large)
    2993              :                     {
    2994          119 :                       prepare_data_in_out (build_zero_cst (m_limb_type),
    2995              :                                            idx, &bf_next);
    2996          119 :                       bf_next = m_data.pop ();
    2997          119 :                       bf_cur = m_data.pop ();
    2998          119 :                       g = gimple_build_cond (EQ_EXPR, idx,
    2999              :                                              bitint_big_endian
    3000            0 :                                              ? size_int (CEIL (prec,
    3001              :                                                                limb_prec) - 1)
    3002              :                                              : size_zero_node,
    3003              :                                              NULL_TREE, NULL_TREE);
    3004          119 :                       edge edge_true;
    3005          119 :                       if_then_else (g, profile_probability::unlikely (),
    3006              :                                     edge_true, e2);
    3007          119 :                       new_bb = e2->dest;
    3008              :                     }
    3009          150 :                   tree ftype
    3010          150 :                     = build_nonstandard_integer_type (limb_prec - bo_shift, 1);
    3011          300 :                   tree bfr = build_bit_field_ref (ftype, unshare_expr (nlhs),
    3012          150 :                                                   limb_prec - bo_shift,
    3013              :                                                   bitint_big_endian
    3014            0 :                                                   ? (bo_idx + bo_last)
    3015            0 :                                                     * limb_prec
    3016          150 :                                                   : bo_idx * limb_prec
    3017              :                                                     + bo_bit);
    3018          150 :                   tree t = add_cast (ftype, rhs1);
    3019          150 :                   g = gimple_build_assign (bfr, t);
    3020          150 :                   insert_before (g);
    3021          150 :                   if (eh)
    3022              :                     {
    3023            0 :                       maybe_duplicate_eh_stmt (g, stmt);
    3024            0 :                       if (eh_pad)
    3025              :                         {
    3026            0 :                           edge e = split_block (gsi_bb (m_gsi), g);
    3027            0 :                           m_gsi = gsi_after_labels (e->dest);
    3028            0 :                           add_eh_edge (e->src,
    3029              :                                        find_edge (gimple_bb (stmt), eh_pad));
    3030              :                         }
    3031              :                     }
    3032          150 :                   if (kind == bitint_prec_large)
    3033              :                     {
    3034              :                       bf_cur = rhs1;
    3035              :                       done = true;
    3036              :                     }
    3037          119 :                   else if (e2)
    3038          119 :                     m_gsi = gsi_after_labels (e2->src);
    3039              :                 }
    3040          119 :               if (!done)
    3041              :                 {
    3042          452 :                   tree t1 = make_ssa_name (m_limb_type);
    3043          452 :                   tree t2 = make_ssa_name (m_limb_type);
    3044          452 :                   tree t3 = make_ssa_name (m_limb_type);
    3045          452 :                   g = gimple_build_assign (t1, RSHIFT_EXPR, bf_cur,
    3046              :                                            build_int_cst (unsigned_type_node,
    3047          452 :                                                           limb_prec
    3048          452 :                                                           - bo_shift));
    3049          452 :                   insert_before (g);
    3050          452 :                   g = gimple_build_assign (t2, LSHIFT_EXPR, rhs1,
    3051              :                                            build_int_cst (unsigned_type_node,
    3052          452 :                                                           bo_shift));
    3053          452 :                   insert_before (g);
    3054          452 :                   bf_cur = rhs1;
    3055          452 :                   g = gimple_build_assign (t3, BIT_IOR_EXPR, t1, t2);
    3056          452 :                   insert_before (g);
    3057          452 :                   rhs1 = t3;
    3058          452 :                   if (bf_next && i == 1)
    3059              :                     {
    3060          119 :                       g = gimple_build_assign (bf_next, bf_cur);
    3061          119 :                       insert_before (g);
    3062              :                     }
    3063              :                 }
    3064              :             }
    3065           31 :           if (!done)
    3066              :             {
    3067              :               /* Handle bit-field access to partial last limb if needed.  */
    3068        52904 :               if (nlhs
    3069          532 :                   && i == cnt - 1
    3070          175 :                   && !separate_ext
    3071          151 :                   && tree_fits_uhwi_p (idx))
    3072              :                 {
    3073          136 :                   unsigned int tprec = TYPE_PRECISION (type);
    3074          136 :                   unsigned int rprec = (tprec - 1) % limb_prec + 1;
    3075          136 :                   if (rprec + bo_shift < (unsigned) limb_prec)
    3076              :                     {
    3077           59 :                       tree ftype
    3078           59 :                         = build_nonstandard_integer_type (rprec + bo_shift, 1);
    3079           59 :                       tree bfr
    3080          118 :                         = build_bit_field_ref (ftype, unshare_expr (nlhs),
    3081              :                                                rprec + bo_shift,
    3082              :                                                bitint_big_endian
    3083            0 :                                                ? bo_idx * limb_prec + bo_bit
    3084           59 :                                                : (bo_idx + tprec / limb_prec)
    3085           59 :                                                  * limb_prec);
    3086           59 :                       tree t = add_cast (ftype, rhs1);
    3087           59 :                       g = gimple_build_assign (bfr, t);
    3088           59 :                       done = true;
    3089           59 :                       bf_cur = NULL_TREE;
    3090              :                     }
    3091           77 :                   else if (rprec + bo_shift == (unsigned) limb_prec)
    3092        52845 :                     bf_cur = NULL_TREE;
    3093              :                 }
    3094              :               /* Otherwise, stores to any other lhs.  */
    3095           59 :               if (!done)
    3096              :                 {
    3097        53318 :                   tree l = limb_access (nlhs ? NULL_TREE : lhs_type,
    3098              :                                         nlhs ? nlhs : lhs, nidx, true);
    3099        52845 :                   g = gimple_build_assign (l, rhs1);
    3100              :                 }
    3101        52904 :               insert_before (g);
    3102        52904 :               if (eh)
    3103              :                 {
    3104            6 :                   maybe_duplicate_eh_stmt (g, stmt);
    3105            6 :                   if (eh_pad)
    3106              :                     {
    3107            6 :                       edge e = split_block (gsi_bb (m_gsi), g);
    3108            6 :                       m_gsi = gsi_after_labels (e->dest);
    3109            6 :                       add_eh_edge (e->src,
    3110              :                                    find_edge (gimple_bb (stmt), eh_pad));
    3111              :                     }
    3112              :                 }
    3113        52904 :               if (new_bb)
    3114          119 :                 m_gsi = gsi_after_labels (new_bb);
    3115              :             }
    3116              :         }
    3117        74073 :       m_first = false;
    3118        74073 :       if (kind == bitint_prec_huge && i <= 1)
    3119              :         {
    3120        24584 :           if (i == 0)
    3121              :             {
    3122        12292 :               idx = make_ssa_name (sizetype);
    3123        12292 :               g = gimple_build_assign (idx, PLUS_EXPR, idx_first,
    3124              :                                        bitint_big_endian
    3125            0 :                                        ? size_int (-1) : size_one_node);
    3126        12292 :               insert_before (g);
    3127              :             }
    3128              :           else
    3129              :             {
    3130        12292 :               g = gimple_build_assign (idx_next, PLUS_EXPR, idx_first,
    3131        24584 :                                        size_int (bitint_big_endian ? -2 : 2));
    3132        12292 :               insert_before (g);
    3133        12292 :               if (bitint_big_endian)
    3134            0 :                 g = gimple_build_cond (NE_EXPR, idx_first, size_int (cnt - 1),
    3135              :                                        NULL_TREE, NULL_TREE);
    3136              :               else
    3137        12292 :                 g = gimple_build_cond (NE_EXPR, idx_next, size_int (end),
    3138              :                                        NULL_TREE, NULL_TREE);
    3139        12292 :               insert_before (g);
    3140        12292 :               if (eq_p)
    3141         3362 :                 m_gsi = gsi_after_labels (edge_bb);
    3142              :               else
    3143         8930 :                 m_gsi = gsi_for_stmt (stmt);
    3144        12292 :               m_bb = NULL;
    3145              :             }
    3146              :         }
    3147              :     }
    3148              : 
    3149        24675 :   if (separate_ext)
    3150              :     {
    3151          126 :       if (sext)
    3152              :         {
    3153           52 :           ext = add_cast (signed_type_for (m_limb_type), ext);
    3154          104 :           tree lpm1 = build_int_cst (unsigned_type_node,
    3155           52 :                                      limb_prec - 1);
    3156           52 :           tree n = make_ssa_name (TREE_TYPE (ext));
    3157           52 :           g = gimple_build_assign (n, RSHIFT_EXPR, ext, lpm1);
    3158           52 :           insert_before (g);
    3159           52 :           ext = add_cast (m_limb_type, n);
    3160              :         }
    3161              :       else
    3162           74 :         ext = build_zero_cst (m_limb_type);
    3163          126 :       kind = bitint_precision_kind (type);
    3164          126 :       unsigned start = CEIL (prec, limb_prec);
    3165          126 :       prec = TYPE_PRECISION (type);
    3166          126 :       if (bitint_extended == bitint_ext_full
    3167            0 :           && !nlhs
    3168            0 :           && !zero_ms_limb
    3169            0 :           && abi_limb_prec > limb_prec)
    3170              :         {
    3171            0 :           prec = CEIL (prec, abi_limb_prec) * abi_limb_prec;
    3172            0 :           kind = bitint_precision_kind (prec);
    3173              :         }
    3174          126 :       unsigned total = CEIL (prec, limb_prec);
    3175          126 :       idx = idx_first = idx_next = NULL_TREE;
    3176          126 :       if (prec <= (start + 2 + (bo_shift != 0)) * limb_prec)
    3177              :         kind = bitint_prec_large;
    3178           80 :       if (kind == bitint_prec_large)
    3179           46 :         cnt = total - start;
    3180              :       else
    3181              :         {
    3182           80 :           rem = prec % limb_prec;
    3183           80 :           end = (prec - rem) / limb_prec;
    3184          152 :           cnt = (bo_shift != 0) + 1 + (rem != 0);
    3185              :         }
    3186          126 :       if (bitint_big_endian && bo_shift != 0 && (prec % limb_prec) == 0)
    3187            0 :         ++total;
    3188          323 :       for (unsigned i = 0; i < cnt; i++)
    3189              :         {
    3190          197 :           if (kind == bitint_prec_large || (i == 0 && bo_shift != 0))
    3191           63 :             idx = size_int (bo_idx
    3192              :                             + (bitint_big_endian
    3193              :                                ? total - 1 - start - i : start + i));
    3194          134 :           else if (i == cnt - 1 && rem != 0)
    3195          108 :             idx = size_int (bo_idx + (bitint_big_endian ? 0 : end));
    3196           80 :           else if (i == (bo_shift != 0))
    3197           80 :             idx = create_loop (size_int (bo_idx
    3198              :                                          + (bitint_big_endian
    3199              :                                             ? total - 1 - start - i
    3200              :                                             : start + i)), &idx_next);
    3201          197 :           rhs1 = ext;
    3202          197 :           if (bf_cur != NULL_TREE && bf_cur != ext)
    3203              :             {
    3204           20 :               tree t1 = make_ssa_name (m_limb_type);
    3205           20 :               g = gimple_build_assign (t1, RSHIFT_EXPR, bf_cur,
    3206              :                                        build_int_cst (unsigned_type_node,
    3207           20 :                                                       limb_prec - bo_shift));
    3208           20 :               insert_before (g);
    3209           20 :               if (integer_zerop (ext))
    3210              :                 rhs1 = t1;
    3211              :               else
    3212              :                 {
    3213           10 :                   tree t2 = make_ssa_name (m_limb_type);
    3214           10 :                   rhs1 = make_ssa_name (m_limb_type);
    3215           10 :                   g = gimple_build_assign (t2, LSHIFT_EXPR, ext,
    3216              :                                            build_int_cst (unsigned_type_node,
    3217           10 :                                                           bo_shift));
    3218           10 :                   insert_before (g);
    3219           10 :                   g = gimple_build_assign (rhs1, BIT_IOR_EXPR, t1, t2);
    3220           10 :                   insert_before (g);
    3221              :                 }
    3222              :               bf_cur = ext;
    3223              :             }
    3224          197 :           bool done = false;
    3225              :           /* Handle bit-field access to partial last limb if needed.  */
    3226          197 :           if (nlhs && i == cnt - 1)
    3227              :             {
    3228           24 :               unsigned int tprec = TYPE_PRECISION (type);
    3229           24 :               unsigned int rprec = (tprec - 1) % limb_prec + 1;
    3230           24 :               if (rprec + bo_shift < (unsigned) limb_prec)
    3231              :                 {
    3232           12 :                   tree ftype
    3233           12 :                     = build_nonstandard_integer_type (rprec + bo_shift, 1);
    3234           12 :                   tree bfr
    3235           24 :                     = build_bit_field_ref (ftype, unshare_expr (nlhs),
    3236              :                                            rprec + bo_shift,
    3237              :                                            bitint_big_endian
    3238            0 :                                            ? bo_idx * limb_prec + bo_bit
    3239           12 :                                            : (bo_idx + tprec / limb_prec)
    3240           12 :                                              * limb_prec);
    3241           12 :                   tree t = add_cast (ftype, rhs1);
    3242           12 :                   g = gimple_build_assign (bfr, t);
    3243           12 :                   done = true;
    3244           12 :                   bf_cur = NULL_TREE;
    3245              :                 }
    3246           12 :               else if (rprec + bo_shift == (unsigned) limb_prec)
    3247              :                 bf_cur = NULL_TREE;
    3248              :             }
    3249              :           /* Otherwise, stores to any other lhs.  */
    3250           12 :           if (!done)
    3251              :             {
    3252          215 :               tree l = limb_access (nlhs ? NULL_TREE : lhs_type,
    3253              :                                     nlhs ? nlhs : lhs, idx, true);
    3254              : 
    3255          185 :               if (bitint_extended
    3256            0 :                   && sext
    3257            0 :                   && TYPE_UNSIGNED (lhs_type)
    3258            0 :                   && tree_fits_uhwi_p (idx)
    3259          185 :                   && !nlhs)
    3260              :                 {
    3261            0 :                   rhs1 = add_cast (limb_access_type (lhs_type, idx), rhs1);
    3262            0 :                   rhs1 = add_cast (TREE_TYPE (l), rhs1);
    3263              :                 }
    3264              : 
    3265          185 :               g = gimple_build_assign (l, rhs1);
    3266              :             }
    3267          197 :           insert_before (g);
    3268          197 :           if (eh)
    3269              :             {
    3270            0 :               maybe_duplicate_eh_stmt (g, stmt);
    3271            0 :               if (eh_pad)
    3272              :                 {
    3273            0 :                   edge e = split_block (gsi_bb (m_gsi), g);
    3274            0 :                   m_gsi = gsi_after_labels (e->dest);
    3275            0 :                   add_eh_edge (e->src, find_edge (gimple_bb (stmt), eh_pad));
    3276              :                 }
    3277              :             }
    3278          197 :           if (kind == bitint_prec_huge && i == (bo_shift != 0))
    3279              :             {
    3280           80 :               g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    3281              :                                        bitint_big_endian
    3282            0 :                                        ? size_int (-1) : size_one_node);
    3283           80 :               insert_before (g);
    3284              :               /* For big-endian, if bo_idx + total - 1 - end is all ones, then
    3285              :                  compare idx (which is equal to idx_next + 1) against 0
    3286              :                  instead.  */
    3287           80 :               if (bitint_big_endian && bo_idx + total - end == 0)
    3288            0 :                 g = gimple_build_cond (NE_EXPR, idx, size_zero_node,
    3289              :                                        NULL_TREE, NULL_TREE);
    3290              :               else
    3291           80 :                 g = gimple_build_cond (NE_EXPR, idx_next,
    3292           80 :                                        size_int (bo_idx
    3293              :                                                  + (bitint_big_endian
    3294              :                                                     ? total - 1 - end
    3295              :                                                     : end)),
    3296              :                                        NULL_TREE, NULL_TREE);
    3297           80 :               insert_before (g);
    3298           80 :               m_gsi = gsi_for_stmt (stmt);
    3299           80 :               m_bb = NULL;
    3300              :             }
    3301              :         }
    3302              :     }
    3303        24675 :   if (bf_cur != NULL_TREE)
    3304              :     {
    3305           72 :       unsigned int tprec = TYPE_PRECISION (type);
    3306           72 :       unsigned int rprec = (tprec + bo_shift) % limb_prec;
    3307           72 :       tree ftype = build_nonstandard_integer_type (rprec, 1);
    3308          144 :       tree bfr = build_bit_field_ref (ftype, unshare_expr (nlhs),
    3309              :                                       rprec,
    3310              :                                       bitint_big_endian
    3311            0 :                                       ? bo_idx * limb_prec + bo_bit
    3312           72 :                                       : (bo_idx + (tprec + bo_bit) / limb_prec)
    3313              :                                         * limb_prec);
    3314           72 :       rhs1 = bf_cur;
    3315           72 :       if (bf_cur != ext)
    3316              :         {
    3317           64 :           rhs1 = make_ssa_name (TREE_TYPE (rhs1));
    3318           64 :           g = gimple_build_assign (rhs1, RSHIFT_EXPR, bf_cur,
    3319              :                                    build_int_cst (unsigned_type_node,
    3320           64 :                                                   limb_prec - bo_shift));
    3321           64 :           insert_before (g);
    3322              :         }
    3323           72 :       rhs1 = add_cast (ftype, rhs1);
    3324           72 :       g = gimple_build_assign (bfr, rhs1);
    3325           72 :       insert_before (g);
    3326           72 :       if (eh)
    3327              :         {
    3328            0 :           maybe_duplicate_eh_stmt (g, stmt);
    3329            0 :           if (eh_pad)
    3330              :             {
    3331            0 :               edge e = split_block (gsi_bb (m_gsi), g);
    3332            0 :               m_gsi = gsi_after_labels (e->dest);
    3333            0 :               add_eh_edge (e->src, find_edge (gimple_bb (stmt), eh_pad));
    3334              :             }
    3335              :         }
    3336              :     }
    3337        24675 :   if (zero_ms_limb)
    3338              :     {
    3339            0 :       tree p2 = build_int_cst (sizetype,
    3340            0 :                                CEIL ((unsigned) TYPE_PRECISION (type),
    3341              :                                      abi_limb_prec)
    3342            0 :                                * abi_limb_prec / limb_prec - 1);
    3343            0 :       tree l = limb_access (lhs_type, lhs, p2, true);
    3344            0 :       g = gimple_build_assign (l, build_zero_cst (m_limb_type));
    3345            0 :       insert_before (g);
    3346            0 :       if (eh)
    3347              :         {
    3348            0 :           maybe_duplicate_eh_stmt (g, stmt);
    3349            0 :           if (eh_pad)
    3350              :             {
    3351            0 :               edge e = split_block (gsi_bb (m_gsi), g);
    3352            0 :               m_gsi = gsi_after_labels (e->dest);
    3353            0 :               add_eh_edge (e->src, find_edge (gimple_bb (stmt), eh_pad));
    3354              :             }
    3355              :         }
    3356              :     }
    3357              : 
    3358        24675 :   if (gimple_store_p (stmt))
    3359              :     {
    3360         8803 :       unlink_stmt_vdef (stmt);
    3361        17606 :       if (tree vdef = gimple_vdef (stmt))
    3362         8803 :         if (TREE_CODE (vdef) == SSA_NAME)
    3363         8803 :           release_ssa_name (vdef);
    3364         8803 :       gsi_remove (&m_gsi, true);
    3365              :     }
    3366        24675 :   if (eq_p)
    3367              :     {
    3368         7014 :       lhs = make_ssa_name (boolean_type_node);
    3369         7014 :       basic_block bb = gimple_bb (stmt);
    3370         7014 :       gphi *phi = create_phi_node (lhs, bb);
    3371         7014 :       edge e = find_edge (gsi_bb (m_gsi), bb);
    3372         7014 :       unsigned int n = EDGE_COUNT (bb->preds);
    3373        35166 :       for (unsigned int i = 0; i < n; i++)
    3374              :         {
    3375        28152 :           edge e2 = EDGE_PRED (bb, i);
    3376        28152 :           add_phi_arg (phi, e == e2 ? boolean_true_node : boolean_false_node,
    3377              :                        e2, UNKNOWN_LOCATION);
    3378              :         }
    3379         7014 :       cmp_code = cmp_code == EQ_EXPR ? NE_EXPR : EQ_EXPR;
    3380         7014 :       return lhs;
    3381              :     }
    3382              :   else
    3383              :     return NULL_TREE;
    3384              : }
    3385              : 
    3386              : /* Handle a large/huge _BitInt comparison statement STMT other than
    3387              :    EQ_EXPR/NE_EXPR.  CMP_CODE, CMP_OP1 and CMP_OP2 meaning is like in
    3388              :    lower_mergeable_stmt.  The {GT,GE,LT,LE}_EXPR comparisons are
    3389              :    lowered by iteration from the most significant limb downwards to
    3390              :    the least significant one, for large _BitInt in straight line code,
    3391              :    otherwise with most significant limb handled in
    3392              :    straight line code followed by a loop handling one limb at a time.
    3393              :    Comparisons with unsigned huge _BitInt with precisions which are
    3394              :    multiples of limb precision can use just the loop and don't need to
    3395              :    handle most significant limb before the loop.  The loop or straight
    3396              :    line code jumps to final basic block if a particular pair of limbs
    3397              :    is not equal.  */
    3398              : 
    3399              : tree
    3400          745 : bitint_large_huge::lower_comparison_stmt (gimple *stmt, tree_code &cmp_code,
    3401              :                                           tree cmp_op1, tree cmp_op2)
    3402              : {
    3403          745 :   tree type = TREE_TYPE (cmp_op1);
    3404          745 :   gcc_assert (BITINT_TYPE_P (type));
    3405          745 :   bitint_prec_kind kind = bitint_precision_kind (type);
    3406          745 :   gcc_assert (kind >= bitint_prec_large);
    3407          745 :   gimple *g;
    3408          745 :   if (!TYPE_UNSIGNED (type)
    3409          463 :       && integer_zerop (cmp_op2)
    3410          773 :       && (cmp_code == GE_EXPR || cmp_code == LT_EXPR))
    3411              :     {
    3412           28 :       unsigned end = CEIL ((unsigned) TYPE_PRECISION (type), limb_prec) - 1;
    3413           56 :       tree idx = size_int (bitint_big_endian ? 0 : end);
    3414           28 :       m_data_cnt = 0;
    3415           28 :       tree rhs1 = handle_operand (cmp_op1, idx);
    3416           28 :       if (TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    3417              :         {
    3418           24 :           tree stype = signed_type_for (TREE_TYPE (rhs1));
    3419           24 :           rhs1 = add_cast (stype, rhs1);
    3420              :         }
    3421           28 :       tree lhs = make_ssa_name (boolean_type_node);
    3422           28 :       g = gimple_build_assign (lhs, cmp_code, rhs1,
    3423           28 :                                build_zero_cst (TREE_TYPE (rhs1)));
    3424           28 :       insert_before (g);
    3425           28 :       cmp_code = NE_EXPR;
    3426           28 :       return lhs;
    3427              :     }
    3428              : 
    3429          717 :   unsigned cnt, rem = 0, end = 0;
    3430          717 :   tree idx = NULL_TREE, idx_next = NULL_TREE;
    3431          717 :   if (kind == bitint_prec_large)
    3432          378 :     cnt = CEIL ((unsigned) TYPE_PRECISION (type), limb_prec);
    3433              :   else
    3434              :     {
    3435          339 :       rem = ((unsigned) TYPE_PRECISION (type) % limb_prec);
    3436          339 :       if (rem == 0 && !TYPE_UNSIGNED (type))
    3437              :         rem = limb_prec;
    3438          339 :       end = ((unsigned) TYPE_PRECISION (type) - rem) / limb_prec;
    3439          339 :       cnt = 1 + (rem != 0);
    3440              :     }
    3441              : 
    3442          717 :   basic_block edge_bb = NULL;
    3443          717 :   gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    3444          717 :   gsi_prev (&gsi);
    3445          717 :   edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    3446          717 :   edge_bb = e->src;
    3447          717 :   m_gsi = gsi_end_bb (edge_bb);
    3448              : 
    3449          717 :   edge *edges = XALLOCAVEC (edge, cnt * 2);
    3450         2588 :   for (unsigned i = 0; i < cnt; i++)
    3451              :     {
    3452         1871 :       m_data_cnt = 0;
    3453         1871 :       if (kind == bitint_prec_large)
    3454         1249 :         idx = size_int (bitint_big_endian ? i : cnt - i - 1);
    3455          622 :       else if (i == cnt - 1)
    3456          339 :         idx = create_loop (size_int (bitint_big_endian ? cnt - 1 : end - 1),
    3457              :                            &idx_next);
    3458              :       else
    3459          566 :         idx = size_int (bitint_big_endian ? 0 : end);
    3460         1871 :       tree rhs1 = handle_operand (cmp_op1, idx);
    3461         1871 :       tree rhs2 = handle_operand (cmp_op2, idx);
    3462         1871 :       if (i == 0
    3463          717 :           && !TYPE_UNSIGNED (type)
    3464         2306 :           && TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    3465              :         {
    3466          113 :           tree stype = signed_type_for (TREE_TYPE (rhs1));
    3467          113 :           rhs1 = add_cast (stype, rhs1);
    3468          113 :           rhs2 = add_cast (stype, rhs2);
    3469              :         }
    3470         1871 :       g = gimple_build_cond (GT_EXPR, rhs1, rhs2, NULL_TREE, NULL_TREE);
    3471         1871 :       insert_before (g);
    3472         1871 :       edge e1 = split_block (gsi_bb (m_gsi), g);
    3473         1871 :       e1->flags = EDGE_FALSE_VALUE;
    3474         1871 :       edge e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE);
    3475         1871 :       e1->probability = profile_probability::likely ();
    3476         1871 :       e2->probability = e1->probability.invert ();
    3477         1871 :       if (i == 0)
    3478          717 :         set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    3479         1871 :       m_gsi = gsi_after_labels (e1->dest);
    3480         1871 :       edges[2 * i] = e2;
    3481         1871 :       g = gimple_build_cond (LT_EXPR, rhs1, rhs2, NULL_TREE, NULL_TREE);
    3482         1871 :       insert_before (g);
    3483         1871 :       e1 = split_block (gsi_bb (m_gsi), g);
    3484         1871 :       e1->flags = EDGE_FALSE_VALUE;
    3485         1871 :       e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE);
    3486         1871 :       e1->probability = profile_probability::unlikely ();
    3487         1871 :       e2->probability = e1->probability.invert ();
    3488         1871 :       m_gsi = gsi_after_labels (e1->dest);
    3489         1871 :       edges[2 * i + 1] = e2;
    3490         1871 :       m_first = false;
    3491         1871 :       if (kind == bitint_prec_huge && i == cnt - 1)
    3492              :         {
    3493          678 :           g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    3494              :                                    bitint_big_endian ? size_one_node
    3495          339 :                                    : size_int (-1));
    3496          339 :           insert_before (g);
    3497          339 :           g = gimple_build_cond (NE_EXPR, idx,
    3498              :                                  bitint_big_endian
    3499            0 :                                  ? size_int (end - 1 + (cnt != 1))
    3500              :                                  : size_zero_node,
    3501              :                                  NULL_TREE, NULL_TREE);
    3502          339 :           insert_before (g);
    3503          339 :           edge true_edge, false_edge;
    3504          339 :           extract_true_false_edges_from_block (gsi_bb (m_gsi),
    3505              :                                                &true_edge, &false_edge);
    3506          339 :           m_gsi = gsi_after_labels (false_edge->dest);
    3507          339 :           m_bb = NULL;
    3508              :         }
    3509              :     }
    3510              : 
    3511          717 :   tree lhs = make_ssa_name (boolean_type_node);
    3512          717 :   basic_block bb = gimple_bb (stmt);
    3513          717 :   gphi *phi = create_phi_node (lhs, bb);
    3514         5176 :   for (unsigned int i = 0; i < cnt * 2; i++)
    3515              :     {
    3516         3742 :       tree val = ((cmp_code == GT_EXPR || cmp_code == GE_EXPR)
    3517         3742 :                   ^ (i & 1)) ? boolean_true_node : boolean_false_node;
    3518         3742 :       add_phi_arg (phi, val, edges[i], UNKNOWN_LOCATION);
    3519              :     }
    3520          717 :   add_phi_arg (phi, (cmp_code == GE_EXPR || cmp_code == LE_EXPR)
    3521              :                     ? boolean_true_node : boolean_false_node,
    3522              :                find_edge (gsi_bb (m_gsi), bb), UNKNOWN_LOCATION);
    3523          717 :   cmp_code = NE_EXPR;
    3524          717 :   return lhs;
    3525              : }
    3526              : 
    3527              : /* Lower large/huge _BitInt left and right shift except for left
    3528              :    shift by < limb_prec constant.  */
    3529              : 
    3530              : void
    3531          682 : bitint_large_huge::lower_shift_stmt (tree obj, gimple *stmt)
    3532              : {
    3533          682 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    3534          682 :   tree lhs = gimple_assign_lhs (stmt);
    3535          682 :   tree_code rhs_code = gimple_assign_rhs_code (stmt);
    3536          682 :   tree type = TREE_TYPE (rhs1);
    3537          682 :   gimple *final_stmt = gsi_stmt (m_gsi);
    3538          682 :   gcc_assert (BITINT_TYPE_P (type)
    3539              :               && bitint_precision_kind (type) >= bitint_prec_large);
    3540          682 :   int prec = TYPE_PRECISION (type);
    3541          682 :   tree n = gimple_assign_rhs2 (stmt), n1, n2, n3, n4;
    3542          682 :   gimple *g;
    3543          682 :   if (obj == NULL_TREE)
    3544              :     {
    3545          563 :       int part = var_to_partition (m_map, lhs);
    3546          563 :       gcc_assert (m_vars[part] != NULL_TREE);
    3547              :       obj = m_vars[part];
    3548              :     }
    3549              :   /* Preparation code common for both left and right shifts.
    3550              :      unsigned n1 = n % limb_prec;
    3551              :      size_t n2 = n / limb_prec;
    3552              :      size_t n3 = n1 != 0;
    3553              :      unsigned n4 = (limb_prec - n1) % limb_prec;
    3554              :      (for power of 2 limb_prec n4 can be -n1 & limb_prec).  */
    3555          682 :   if (TREE_CODE (n) == INTEGER_CST)
    3556              :     {
    3557          268 :       tree lp = build_int_cst (TREE_TYPE (n), limb_prec);
    3558          268 :       n1 = int_const_binop (TRUNC_MOD_EXPR, n, lp);
    3559          268 :       n2 = fold_convert (sizetype, int_const_binop (TRUNC_DIV_EXPR, n, lp));
    3560          268 :       n3 = size_int (!integer_zerop (n1));
    3561          268 :       n4 = int_const_binop (TRUNC_MOD_EXPR,
    3562          268 :                             int_const_binop (MINUS_EXPR, lp, n1), lp);
    3563              :     }
    3564              :   else
    3565              :     {
    3566          414 :       n1 = make_ssa_name (TREE_TYPE (n));
    3567          414 :       n2 = make_ssa_name (sizetype);
    3568          414 :       n3 = make_ssa_name (sizetype);
    3569          414 :       n4 = make_ssa_name (TREE_TYPE (n));
    3570          414 :       if (pow2p_hwi (limb_prec))
    3571              :         {
    3572          414 :           tree lpm1 = build_int_cst (TREE_TYPE (n), limb_prec - 1);
    3573          414 :           gassign *a = gimple_build_assign (n1, BIT_AND_EXPR, n, lpm1);
    3574          414 :           insert_before (a);
    3575         1226 :           a = gimple_build_assign (useless_type_conversion_p (sizetype,
    3576          414 :                                                               TREE_TYPE (n))
    3577          398 :                                    ? n2 : make_ssa_name (TREE_TYPE (n)),
    3578              :                                    RSHIFT_EXPR, n,
    3579          414 :                                    build_int_cst (TREE_TYPE (n),
    3580          828 :                                                   exact_log2 (limb_prec)));
    3581          414 :           insert_before (a);
    3582          414 :           if (gimple_assign_lhs (a) != n2)
    3583              :             {
    3584          398 :               a = gimple_build_assign (n2, NOP_EXPR, gimple_assign_lhs (a));
    3585          398 :               insert_before (a);
    3586              :             }
    3587          414 :           a = gimple_build_assign (make_ssa_name (TREE_TYPE (n)),
    3588              :                                    NEGATE_EXPR, n1);
    3589          414 :           insert_before (a);
    3590          414 :           a = gimple_build_assign (n4, BIT_AND_EXPR, gimple_assign_lhs (a),
    3591              :                                    lpm1);
    3592          414 :           insert_before (a);
    3593              :         }
    3594              :       else
    3595              :         {
    3596            0 :           tree lp = build_int_cst (TREE_TYPE (n), limb_prec);
    3597            0 :           gassign *a = gimple_build_assign (n1, TRUNC_MOD_EXPR, n, lp);
    3598            0 :           insert_before (a);
    3599            0 :           a = gimple_build_assign (useless_type_conversion_p (sizetype,
    3600            0 :                                                               TREE_TYPE (n))
    3601            0 :                                    ? n2 : make_ssa_name (TREE_TYPE (n)),
    3602              :                                    TRUNC_DIV_EXPR, n, lp);
    3603            0 :           insert_before (a);
    3604            0 :           if (gimple_assign_lhs (a) != n2)
    3605              :             {
    3606            0 :               a = gimple_build_assign (n2, NOP_EXPR, gimple_assign_lhs (a));
    3607            0 :               insert_before (a);
    3608              :             }
    3609            0 :           a = gimple_build_assign (make_ssa_name (TREE_TYPE (n)),
    3610              :                                    MINUS_EXPR, lp, n1);
    3611            0 :           insert_before (a);
    3612            0 :           a = gimple_build_assign (n4, TRUNC_MOD_EXPR, gimple_assign_lhs (a),
    3613              :                                    lp);
    3614            0 :           insert_before (a);
    3615              :         }
    3616          414 :       gassign *a
    3617          414 :         = gimple_build_assign (make_ssa_name (boolean_type_node), NE_EXPR, n1,
    3618          414 :                                build_zero_cst (TREE_TYPE (n)));
    3619          414 :       insert_before (a);
    3620          414 :       a = gimple_build_assign (n3, NOP_EXPR, gimple_assign_lhs (a));
    3621          414 :       insert_before (a);
    3622              :     }
    3623         1364 :   tree p = build_int_cst (sizetype,
    3624          682 :                           prec / limb_prec - (prec % limb_prec == 0));
    3625          682 :   if (rhs_code == RSHIFT_EXPR)
    3626              :     {
    3627              :       /* Lower
    3628              :            dst = src >> n;
    3629              :          as
    3630              :            unsigned n1 = n % limb_prec;
    3631              :            size_t n2 = n / limb_prec;
    3632              :            size_t n3 = n1 != 0;
    3633              :            unsigned n4 = (limb_prec - n1) % limb_prec;
    3634              :            size_t idx;
    3635              :            size_t p = prec / limb_prec - (prec % limb_prec == 0);
    3636              :            int signed_p = (typeof (src) -1) < 0;
    3637              :            for (idx = n2; idx < ((!signed_p && (prec % limb_prec == 0))
    3638              :                                  ? p : p - n3); ++idx)
    3639              :              dst[idx - n2] = (src[idx] >> n1) | (src[idx + n3] << n4);
    3640              :            limb_type ext;
    3641              :            if (prec % limb_prec == 0)
    3642              :              ext = src[p];
    3643              :            else if (signed_p)
    3644              :              ext = ((signed limb_type) (src[p] << (limb_prec
    3645              :                                                    - (prec % limb_prec))))
    3646              :                    >> (limb_prec - (prec % limb_prec));
    3647              :            else
    3648              :              ext = src[p] & (((limb_type) 1 << (prec % limb_prec)) - 1);
    3649              :            if (!signed_p && (prec % limb_prec == 0))
    3650              :              ;
    3651              :            else if (idx < prec / 64)
    3652              :              {
    3653              :                dst[idx - n2] = (src[idx] >> n1) | (ext << n4);
    3654              :                ++idx;
    3655              :              }
    3656              :            idx -= n2;
    3657              :            if (signed_p)
    3658              :              {
    3659              :                dst[idx] = ((signed limb_type) ext) >> n1;
    3660              :                ext = ((signed limb_type) ext) >> (limb_prec - 1);
    3661              :              }
    3662              :            else
    3663              :              {
    3664              :                dst[idx] = ext >> n1;
    3665              :                ext = 0;
    3666              :              }
    3667              :            for (++idx; idx <= p; ++idx)
    3668              :              dst[idx] = ext;  */
    3669          444 :       tree pmn3;
    3670          444 :       if (TYPE_UNSIGNED (type) && prec % limb_prec == 0)
    3671          117 :         pmn3 = bitint_big_endian ? size_zero_node : p;
    3672          327 :       else if (bitint_big_endian)
    3673              :         pmn3 = n3;
    3674          327 :       else if (TREE_CODE (n3) == INTEGER_CST)
    3675          129 :         pmn3 = int_const_binop (MINUS_EXPR, p, n3);
    3676              :       else
    3677              :         {
    3678          198 :           pmn3 = make_ssa_name (sizetype);
    3679          198 :           g = gimple_build_assign (pmn3, MINUS_EXPR, p, n3);
    3680          198 :           insert_before (g);
    3681              :         }
    3682          444 :       tree pmn2 = NULL_TREE;
    3683          444 :       if (bitint_big_endian)
    3684              :         {
    3685            0 :           if (TREE_CODE (n2) == INTEGER_CST)
    3686            0 :             pmn2 = int_const_binop (MINUS_EXPR, p, n2);
    3687              :           else
    3688              :             {
    3689            0 :               pmn2 = make_ssa_name (sizetype);
    3690            0 :               g = gimple_build_assign (pmn2, MINUS_EXPR, p, n2);
    3691            0 :               insert_before (g);
    3692              :             }
    3693            0 :           g = gimple_build_cond (GT_EXPR, pmn2, pmn3, NULL_TREE, NULL_TREE);
    3694              :         }
    3695              :       else
    3696          444 :         g = gimple_build_cond (LT_EXPR, n2, pmn3, NULL_TREE, NULL_TREE);
    3697          444 :       edge edge_true, edge_false;
    3698          444 :       if_then (g, profile_probability::likely (), edge_true, edge_false);
    3699          444 :       tree idx_next;
    3700          888 :       tree idx = create_loop (bitint_big_endian ? pmn2 : n2, &idx_next);
    3701          444 :       tree idxmn2 = make_ssa_name (sizetype);
    3702          444 :       tree idxpn3 = make_ssa_name (sizetype);
    3703          888 :       g = gimple_build_assign (idxmn2,
    3704              :                                bitint_big_endian ? PLUS_EXPR : MINUS_EXPR,
    3705              :                                idx, n2);
    3706          444 :       insert_before (g);
    3707          888 :       g = gimple_build_assign (idxpn3,
    3708              :                                bitint_big_endian ? MINUS_EXPR : PLUS_EXPR,
    3709              :                                idx, n3);
    3710          444 :       insert_before (g);
    3711          444 :       m_data_cnt = 0;
    3712          444 :       tree t1 = handle_operand (rhs1, idx);
    3713          444 :       m_first = false;
    3714          444 :       g = gimple_build_assign (make_ssa_name (m_limb_type),
    3715              :                                RSHIFT_EXPR, t1, n1);
    3716          444 :       insert_before (g);
    3717          444 :       t1 = gimple_assign_lhs (g);
    3718          444 :       if (!integer_zerop (n3))
    3719              :         {
    3720          356 :           m_data_cnt = 0;
    3721          356 :           tree t2 = handle_operand (rhs1, idxpn3);
    3722          356 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3723              :                                    LSHIFT_EXPR, t2, n4);
    3724          356 :           insert_before (g);
    3725          356 :           t2 = gimple_assign_lhs (g);
    3726          356 :           g = gimple_build_assign (make_ssa_name (m_limb_type),
    3727              :                                    BIT_IOR_EXPR, t1, t2);
    3728          356 :           insert_before (g);
    3729          356 :           t1 = gimple_assign_lhs (g);
    3730              :         }
    3731          444 :       tree l = limb_access (TREE_TYPE (lhs), obj, idxmn2, true);
    3732          444 :       g = gimple_build_assign (l, t1);
    3733          444 :       insert_before (g);
    3734          444 :       g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    3735            0 :                                bitint_big_endian ? size_int (-1)
    3736              :                                                  : size_one_node);
    3737          444 :       insert_before (g);
    3738          888 :       g = gimple_build_cond (bitint_big_endian ? GT_EXPR : LT_EXPR,
    3739              :                              idx_next, pmn3, NULL_TREE, NULL_TREE);
    3740          444 :       insert_before (g);
    3741          444 :       idx = make_ssa_name (sizetype);
    3742          444 :       m_gsi = gsi_for_stmt (final_stmt);
    3743          444 :       gphi *phi = create_phi_node (idx, gsi_bb (m_gsi));
    3744          444 :       edge_false = find_edge (edge_false->src, gsi_bb (m_gsi));
    3745          444 :       edge_true = EDGE_PRED (gsi_bb (m_gsi),
    3746              :                              EDGE_PRED (gsi_bb (m_gsi), 0) == edge_false);
    3747          888 :       add_phi_arg (phi, bitint_big_endian ? pmn2 : n2, edge_false,
    3748              :                    UNKNOWN_LOCATION);
    3749          444 :       add_phi_arg (phi, idx_next, edge_true, UNKNOWN_LOCATION);
    3750          444 :       m_data_cnt = 0;
    3751          444 :       tree ms = handle_operand (rhs1, bitint_big_endian ? size_zero_node : p);
    3752          444 :       tree ext = ms;
    3753          444 :       if (!types_compatible_p (TREE_TYPE (ms), m_limb_type))
    3754          269 :         ext = add_cast (m_limb_type, ms);
    3755          700 :       if (!(TYPE_UNSIGNED (type) && prec % limb_prec == 0)
    3756          583 :           && !integer_zerop (n3))
    3757              :         {
    3758          289 :           if (bitint_big_endian)
    3759            0 :             g = gimple_build_cond (GT_EXPR, idx, size_zero_node,
    3760              :                                    NULL_TREE, NULL_TREE);
    3761              :           else
    3762          289 :             g = gimple_build_cond (LT_EXPR, idx, p, NULL_TREE, NULL_TREE);
    3763          289 :           if_then (g, profile_probability::likely (), edge_true, edge_false);
    3764          289 :           m_data_cnt = 0;
    3765          289 :           t1 = handle_operand (rhs1, idx);
    3766          289 :           gassign *a = gimple_build_assign (make_ssa_name (m_limb_type),
    3767              :                                             RSHIFT_EXPR, t1, n1);
    3768          289 :           insert_before (a);
    3769          289 :           t1 = gimple_assign_lhs (a);
    3770          289 :           a = gimple_build_assign (make_ssa_name (m_limb_type),
    3771              :                                    LSHIFT_EXPR, ext, n4);
    3772          289 :           insert_before (a);
    3773          289 :           tree t2 = gimple_assign_lhs (a);
    3774          289 :           a = gimple_build_assign (make_ssa_name (m_limb_type),
    3775              :                                    BIT_IOR_EXPR, t1, t2);
    3776          289 :           insert_before (a);
    3777          289 :           t1 = gimple_assign_lhs (a);
    3778          289 :           idxmn2 = make_ssa_name (sizetype);
    3779          578 :           a = gimple_build_assign (idxmn2, bitint_big_endian
    3780              :                                            ? PLUS_EXPR : MINUS_EXPR, idx, n2);
    3781          289 :           insert_before (a);
    3782          289 :           l = limb_access (TREE_TYPE (lhs), obj, idxmn2, true);
    3783          289 :           a = gimple_build_assign (l, t1);
    3784          289 :           insert_before (a);
    3785          289 :           idx_next = make_ssa_name (sizetype);
    3786          289 :           a = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    3787              :                                    bitint_big_endian
    3788            0 :                                    ? size_int (-1) : size_one_node);
    3789          289 :           insert_before (a);
    3790          289 :           m_gsi = gsi_for_stmt (final_stmt);
    3791          289 :           tree nidx = make_ssa_name (sizetype);
    3792          289 :           phi = create_phi_node (nidx, gsi_bb (m_gsi));
    3793          289 :           edge_false = find_edge (edge_false->src, gsi_bb (m_gsi));
    3794          289 :           edge_true = EDGE_PRED (gsi_bb (m_gsi),
    3795              :                                  EDGE_PRED (gsi_bb (m_gsi), 0) == edge_false);
    3796          289 :           add_phi_arg (phi, idx, edge_false, UNKNOWN_LOCATION);
    3797          289 :           add_phi_arg (phi, idx_next, edge_true, UNKNOWN_LOCATION);
    3798          289 :           idx = nidx;
    3799              :         }
    3800          888 :       gassign *a = gimple_build_assign (make_ssa_name (sizetype),
    3801              :                                         bitint_big_endian
    3802              :                                         ? PLUS_EXPR : MINUS_EXPR,
    3803              :                                         idx, n2);
    3804          444 :       insert_before (a);
    3805          444 :       idx = gimple_assign_lhs (a);
    3806          444 :       tree sext = ext;
    3807          444 :       if (!TYPE_UNSIGNED (type))
    3808          188 :         sext = add_cast (signed_type_for (m_limb_type), ext);
    3809          444 :       a = gimple_build_assign (make_ssa_name (TREE_TYPE (sext)),
    3810              :                                RSHIFT_EXPR, sext, n1);
    3811          444 :       insert_before (a);
    3812          444 :       t1 = gimple_assign_lhs (a);
    3813          444 :       if (!TYPE_UNSIGNED (type))
    3814              :         {
    3815          188 :           t1 = add_cast (m_limb_type, t1);
    3816          188 :           a = gimple_build_assign (make_ssa_name (TREE_TYPE (sext)),
    3817              :                                    RSHIFT_EXPR, sext,
    3818          188 :                                    build_int_cst (TREE_TYPE (n),
    3819          188 :                                                   limb_prec - 1));
    3820          188 :           insert_before (a);
    3821          188 :           ext = add_cast (m_limb_type, gimple_assign_lhs (a));
    3822              :         }
    3823              :       else
    3824          256 :         ext = build_zero_cst (m_limb_type);
    3825          444 :       l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    3826          444 :       a = gimple_build_assign (l, t1);
    3827          444 :       insert_before (a);
    3828          444 :       a = gimple_build_assign (make_ssa_name (sizetype), PLUS_EXPR, idx,
    3829              :                                bitint_big_endian
    3830            0 :                                ? size_int (-1) : size_one_node);
    3831          444 :       insert_before (a);
    3832          444 :       tree p2 = p;
    3833          444 :       if (bitint_big_endian)
    3834              :         {
    3835            0 :           tree new_idx = gimple_assign_lhs (a);
    3836            0 :           g = gimple_build_cond (NE_EXPR, idx, size_zero_node,
    3837              :                                  NULL_TREE, NULL_TREE);
    3838            0 :           idx = new_idx;
    3839              :         }
    3840              :       else
    3841              :         {
    3842          444 :           if (bitint_extended == bitint_ext_full
    3843            0 :               && abi_limb_prec > limb_prec)
    3844            0 :             p2 = build_int_cst (sizetype,
    3845            0 :                                 CEIL (prec, abi_limb_prec)
    3846            0 :                                 * abi_limb_prec / limb_prec - 1);
    3847          444 :           idx = gimple_assign_lhs (a);
    3848          444 :           g = gimple_build_cond (LE_EXPR, idx, p2, NULL_TREE, NULL_TREE);
    3849              :         }
    3850          444 :       if_then (g, profile_probability::likely (), edge_true, edge_false);
    3851          444 :       idx = create_loop (idx, &idx_next);
    3852          444 :       l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    3853          444 :       g = gimple_build_assign (l, ext);
    3854          444 :       insert_before (g);
    3855          444 :       g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    3856              :                                bitint_big_endian
    3857            0 :                                ? size_int (-1) : size_one_node);
    3858          444 :       insert_before (g);
    3859          444 :       if (bitint_big_endian)
    3860            0 :         g = gimple_build_cond (NE_EXPR, idx, size_zero_node,
    3861              :                                NULL_TREE, NULL_TREE);
    3862              :       else
    3863          444 :         g = gimple_build_cond (LE_EXPR, idx_next, p2, NULL_TREE, NULL_TREE);
    3864          444 :       insert_before (g);
    3865              :     }
    3866              :   else
    3867              :     {
    3868              :       /* Lower
    3869              :            dst = src << n;
    3870              :          as
    3871              :            unsigned n1 = n % limb_prec;
    3872              :            size_t n2 = n / limb_prec;
    3873              :            size_t n3 = n1 != 0;
    3874              :            unsigned n4 = (limb_prec - n1) % limb_prec;
    3875              :            size_t idx;
    3876              :            size_t p = prec / limb_prec - (prec % limb_prec == 0);
    3877              :            for (idx = p; (ssize_t) idx >= (ssize_t) (n2 + n3); --idx)
    3878              :              dst[idx] = (src[idx - n2] << n1) | (src[idx - n2 - n3] >> n4);
    3879              :            if (n1)
    3880              :              {
    3881              :                dst[idx] = src[idx - n2] << n1;
    3882              :                --idx;
    3883              :              }
    3884              :            for (; (ssize_t) idx >= 0; --idx)
    3885              :              dst[idx] = 0;  */
    3886          238 :       tree n2pn3;
    3887          238 :       if (TREE_CODE (n2) == INTEGER_CST && TREE_CODE (n3) == INTEGER_CST)
    3888           71 :         n2pn3 = int_const_binop (PLUS_EXPR, n2, n3);
    3889              :       else
    3890              :         {
    3891          167 :           n2pn3 = make_ssa_name (sizetype);
    3892          167 :           g = gimple_build_assign (n2pn3, PLUS_EXPR, n2, n3);
    3893          167 :           insert_before (g);
    3894              :         }
    3895          238 :       if (bitint_big_endian)
    3896              :         {
    3897            0 :           if (TREE_CODE (n2pn3) == INTEGER_CST)
    3898            0 :             n2pn3 = int_const_binop (MINUS_EXPR, p, n2pn3);
    3899              :           else
    3900              :             {
    3901            0 :               gassign *a = gimple_build_assign (make_ssa_name (sizetype),
    3902              :                                                 MINUS_EXPR, p, n2pn3);
    3903            0 :               insert_before (a);
    3904            0 :               n2pn3 = gimple_assign_lhs (a);
    3905              :             }
    3906              :         }
    3907              :       /* For LSHIFT_EXPR, we can use handle_operand with non-INTEGER_CST
    3908              :          idx even to access the most significant partial limb.  */
    3909          238 :       m_var_msb = true;
    3910          238 :       if (integer_zerop (n3))
    3911              :         /* For n3 == 0 p >= n2 + n3 is always true for all valid shift
    3912              :            counts.  Emit if (true) condition that can be optimized later.  */
    3913           45 :         g = gimple_build_cond (NE_EXPR, boolean_true_node, boolean_false_node,
    3914              :                                NULL_TREE, NULL_TREE);
    3915          193 :       else if (bitint_big_endian)
    3916            0 :         g = gimple_build_cond (NE_EXPR, n2pn3, size_int (-1), NULL_TREE,
    3917              :                                NULL_TREE);
    3918              :       else
    3919          193 :         g = gimple_build_cond (LE_EXPR, n2pn3, p, NULL_TREE, NULL_TREE);
    3920          238 :       edge edge_true, edge_false;
    3921          238 :       if_then (g, profile_probability::likely (), edge_true, edge_false);
    3922          238 :       tree idx_next;
    3923          238 :       tree idx = create_loop (bitint_big_endian ? size_zero_node : p,
    3924              :                               &idx_next);
    3925          238 :       tree idxmn2 = make_ssa_name (sizetype);
    3926          238 :       tree idxmn2mn3 = make_ssa_name (sizetype);
    3927          476 :       g = gimple_build_assign (idxmn2,
    3928              :                                bitint_big_endian ? PLUS_EXPR : MINUS_EXPR,
    3929              :                                idx, n2);
    3930          238 :       insert_before (g);
    3931          476 :       g = gimple_build_assign (idxmn2mn3,
    3932              :                                bitint_big_endian ? PLUS_EXPR : MINUS_EXPR,
    3933              :                                idxmn2, n3);
    3934          238 :       insert_before (g);
    3935          238 :       m_data_cnt = 0;
    3936          238 :       tree t1 = handle_operand (rhs1, idxmn2);
    3937          238 :       m_first = false;
    3938          238 :       gassign *a = gimple_build_assign (make_ssa_name (m_limb_type),
    3939              :                                         LSHIFT_EXPR, t1, n1);
    3940          238 :       insert_before (a);
    3941          238 :       t1 = gimple_assign_lhs (a);
    3942          238 :       if (!integer_zerop (n3))
    3943              :         {
    3944          193 :           m_data_cnt = 0;
    3945          193 :           tree t2 = handle_operand (rhs1, idxmn2mn3);
    3946          193 :           a = gimple_build_assign (make_ssa_name (m_limb_type),
    3947              :                                    RSHIFT_EXPR, t2, n4);
    3948          193 :           insert_before (a);
    3949          193 :           t2 = gimple_assign_lhs (a);
    3950          193 :           a = gimple_build_assign (make_ssa_name (m_limb_type),
    3951              :                                    BIT_IOR_EXPR, t1, t2);
    3952          193 :           insert_before (a);
    3953          193 :           t1 = gimple_assign_lhs (a);
    3954              :         }
    3955          238 :       tree l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    3956          238 :       a = gimple_build_assign (l, t1);
    3957          238 :       insert_before (a);
    3958          476 :       a = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    3959              :                                bitint_big_endian
    3960          238 :                                ? size_one_node : size_int (-1));
    3961          238 :       insert_before (a);
    3962          238 :       tree sn2pn3 = add_cast (ssizetype, n2pn3);
    3963          476 :       g = gimple_build_cond (bitint_big_endian ? LE_EXPR : GE_EXPR,
    3964              :                              add_cast (ssizetype, idx_next), sn2pn3,
    3965              :                              NULL_TREE, NULL_TREE);
    3966          238 :       insert_before (g);
    3967          238 :       idx = make_ssa_name (sizetype);
    3968          238 :       m_gsi = gsi_for_stmt (final_stmt);
    3969          238 :       gphi *phi = create_phi_node (idx, gsi_bb (m_gsi));
    3970          238 :       edge_false = find_edge (edge_false->src, gsi_bb (m_gsi));
    3971          238 :       edge_true = EDGE_PRED (gsi_bb (m_gsi),
    3972              :                              EDGE_PRED (gsi_bb (m_gsi), 0) == edge_false);
    3973          238 :       add_phi_arg (phi, bitint_big_endian ? size_zero_node : p,
    3974              :                    edge_false, UNKNOWN_LOCATION);
    3975          238 :       add_phi_arg (phi, idx_next, edge_true, UNKNOWN_LOCATION);
    3976          238 :       m_data_cnt = 0;
    3977          238 :       if (!integer_zerop (n3))
    3978              :         {
    3979          193 :           g = gimple_build_cond (NE_EXPR, n3, size_zero_node,
    3980              :                                  NULL_TREE, NULL_TREE);
    3981          193 :           if_then (g, profile_probability::likely (), edge_true, edge_false);
    3982          193 :           idxmn2 = make_ssa_name (sizetype);
    3983          386 :           g = gimple_build_assign (idxmn2,
    3984              :                                    bitint_big_endian ? PLUS_EXPR : MINUS_EXPR,
    3985              :                                    idx, n2);
    3986          193 :           insert_before (g);
    3987          193 :           m_data_cnt = 0;
    3988          193 :           t1 = handle_operand (rhs1, idxmn2);
    3989          193 :           gassign *a = gimple_build_assign (make_ssa_name (m_limb_type),
    3990              :                                             LSHIFT_EXPR, t1, n1);
    3991          193 :           insert_before (a);
    3992          193 :           t1 = gimple_assign_lhs (a);
    3993          193 :           l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    3994          193 :           a = gimple_build_assign (l, t1);
    3995          193 :           insert_before (a);
    3996          193 :           idx_next = make_ssa_name (sizetype);
    3997          386 :           a = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    3998              :                                    bitint_big_endian
    3999          193 :                                    ? size_one_node : size_int (-1));
    4000          193 :           insert_before (a);
    4001          193 :           m_gsi = gsi_for_stmt (final_stmt);
    4002          193 :           tree nidx = make_ssa_name (sizetype);
    4003          193 :           phi = create_phi_node (nidx, gsi_bb (m_gsi));
    4004          193 :           edge_false = find_edge (edge_false->src, gsi_bb (m_gsi));
    4005          193 :           edge_true = EDGE_PRED (gsi_bb (m_gsi),
    4006              :                                  EDGE_PRED (gsi_bb (m_gsi), 0) == edge_false);
    4007          193 :           add_phi_arg (phi, idx, edge_false, UNKNOWN_LOCATION);
    4008          193 :           add_phi_arg (phi, idx_next, edge_true, UNKNOWN_LOCATION);
    4009          193 :           idx = nidx;
    4010              :         }
    4011          238 :       if (bitint_big_endian)
    4012            0 :         g = gimple_build_cond (LE_EXPR, idx, p, NULL_TREE, NULL_TREE);
    4013              :       else
    4014          238 :         g = gimple_build_cond (GE_EXPR, add_cast (ssizetype, idx),
    4015              :                                ssize_int (0), NULL_TREE, NULL_TREE);
    4016          238 :       if_then (g, profile_probability::likely (), edge_true, edge_false);
    4017          238 :       idx = create_loop (idx, &idx_next);
    4018          238 :       l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    4019          238 :       g = gimple_build_assign (l, build_zero_cst (m_limb_type));
    4020          238 :       insert_before (g);
    4021          476 :       g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    4022              :                                bitint_big_endian
    4023          238 :                                ? size_one_node : size_int (-1));
    4024          238 :       insert_before (g);
    4025          238 :       if (bitint_big_endian)
    4026            0 :         g = gimple_build_cond (LE_EXPR, idx_next, p, NULL_TREE, NULL_TREE);
    4027              :       else
    4028          238 :         g = gimple_build_cond (GE_EXPR, add_cast (ssizetype, idx_next),
    4029              :                                ssize_int (0), NULL_TREE, NULL_TREE);
    4030          238 :       insert_before (g);
    4031          238 :       if (bitint_extended && prec % limb_prec != 0)
    4032              :         {
    4033              :           /* The most significant limb has been updated either in the
    4034              :              loop or in the if after it.  To simplify the code, just
    4035              :              read it back from memory and extend.  */
    4036            0 :           m_gsi = gsi_after_labels (edge_false->dest);
    4037            0 :           idx = bitint_big_endian ? size_zero_node : p;
    4038            0 :           tree l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    4039            0 :           tree type = limb_access_type (TREE_TYPE (lhs), idx);
    4040            0 :           tree v = make_ssa_name (m_limb_type);
    4041            0 :           g = gimple_build_assign (v, l);
    4042            0 :           insert_before (g);
    4043            0 :           v = add_cast (type, v);
    4044            0 :           l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    4045            0 :           v = add_cast (m_limb_type, v);
    4046            0 :           g = gimple_build_assign (l, v);
    4047            0 :           insert_before (g);
    4048            0 :           if (bitint_extended == bitint_ext_full
    4049            0 :               && abi_limb_prec > limb_prec
    4050            0 :               && (CEIL (prec, abi_limb_prec) * abi_limb_prec
    4051            0 :                   > CEIL (prec, limb_prec) * limb_prec))
    4052              :             {
    4053            0 :               tree p2 = build_int_cst (sizetype,
    4054              :                                        CEIL (prec, abi_limb_prec)
    4055            0 :                                        * abi_limb_prec / limb_prec - 1);
    4056            0 :               if (TYPE_UNSIGNED (TREE_TYPE (lhs)))
    4057            0 :                 v = build_zero_cst (m_limb_type);
    4058              :               else
    4059              :                 {
    4060            0 :                   v = add_cast (signed_type_for (m_limb_type), v);
    4061            0 :                   gassign *a
    4062            0 :                     = gimple_build_assign (make_ssa_name (TREE_TYPE (v)),
    4063              :                                            RSHIFT_EXPR, v,
    4064              :                                            build_int_cst (unsigned_type_node,
    4065            0 :                                                           limb_prec - 1));
    4066            0 :                   insert_before (a);
    4067            0 :                   v = add_cast (m_limb_type, gimple_assign_lhs (a));
    4068              :                 }
    4069            0 :               l = limb_access (TREE_TYPE (lhs), obj, p2, true);
    4070            0 :               g = gimple_build_assign (l, v);
    4071            0 :               insert_before (g);
    4072              :             }
    4073              :         }
    4074          238 :       else if (bitint_extended == bitint_ext_full
    4075            0 :                && abi_limb_prec > limb_prec
    4076            0 :                && (CEIL (prec, abi_limb_prec) * abi_limb_prec
    4077            0 :                    > CEIL (prec, limb_prec) * limb_prec))
    4078              :         {
    4079            0 :           m_gsi = gsi_after_labels (edge_false->dest);
    4080            0 :           tree p2 = build_int_cst (sizetype,
    4081              :                                    CEIL (prec, abi_limb_prec)
    4082            0 :                                    * abi_limb_prec / limb_prec - 1);
    4083            0 :           tree v;
    4084            0 :           if (TYPE_UNSIGNED (TREE_TYPE (lhs)))
    4085            0 :             v = build_zero_cst (m_limb_type);
    4086              :           else
    4087              :             {
    4088            0 :               tree l = limb_access (TREE_TYPE (lhs), obj, p, true);
    4089            0 :               v = make_ssa_name (m_limb_type);
    4090            0 :               gassign *a = gimple_build_assign (v, l);
    4091            0 :               insert_before (a);
    4092            0 :               v = add_cast (signed_type_for (m_limb_type), v);
    4093            0 :               a = gimple_build_assign (make_ssa_name (TREE_TYPE (v)),
    4094              :                                        RSHIFT_EXPR, v,
    4095              :                                        build_int_cst (unsigned_type_node,
    4096            0 :                                                       limb_prec - 1));
    4097            0 :               insert_before (a);
    4098            0 :               v = add_cast (m_limb_type, gimple_assign_lhs (a));
    4099              :             }
    4100            0 :           tree l = limb_access (TREE_TYPE (lhs), obj, p2, true);
    4101            0 :           g = gimple_build_assign (l, v);
    4102            0 :           insert_before (g);
    4103              :         }
    4104              :     }
    4105          682 : }
    4106              : 
    4107              : /* Lower large/huge _BitInt multiplication or division.  */
    4108              : 
    4109              : void
    4110          445 : bitint_large_huge::lower_muldiv_stmt (tree obj, gimple *stmt)
    4111              : {
    4112          445 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    4113          445 :   tree rhs2 = gimple_assign_rhs2 (stmt);
    4114          445 :   tree lhs = gimple_assign_lhs (stmt);
    4115          445 :   tree_code rhs_code = gimple_assign_rhs_code (stmt);
    4116          445 :   tree type = TREE_TYPE (rhs1);
    4117          445 :   gcc_assert (BITINT_TYPE_P (type)
    4118              :               && bitint_precision_kind (type) >= bitint_prec_large);
    4119          445 :   int prec = TYPE_PRECISION (type), prec1, prec2;
    4120          445 :   bool ext_ms_limb = false;
    4121          445 :   bool do_ext = false;
    4122          445 :   rhs1 = handle_operand_addr (rhs1, stmt, NULL, &prec1);
    4123          445 :   rhs2 = handle_operand_addr (rhs2, stmt, NULL, &prec2);
    4124          445 :   if (obj == NULL_TREE)
    4125              :     {
    4126          236 :       int part = var_to_partition (m_map, lhs);
    4127          236 :       gcc_assert (m_vars[part] != NULL_TREE);
    4128          236 :       obj = m_vars[part];
    4129          236 :       lhs = build_fold_addr_expr (obj);
    4130              :     }
    4131              :   else
    4132              :     {
    4133          209 :       lhs = build_fold_addr_expr (obj);
    4134          209 :       lhs = force_gimple_operand_gsi (&m_gsi, lhs, true,
    4135              :                                       NULL_TREE, true, GSI_SAME_STMT);
    4136              :     }
    4137          445 :   if (bitint_extended && TYPE_OVERFLOW_WRAPS (type))
    4138              :     {
    4139            0 :       if (rhs_code == MULT_EXPR)
    4140              :         do_ext = true;
    4141              :       /* For signed division with -fwrapv, minimum negative / -1 needs
    4142              :          is minimum negative and the padding bits above it should be all
    4143              :          set.  */
    4144            0 :       else if (!TYPE_UNSIGNED (type)
    4145            0 :                && (rhs_code == TRUNC_DIV_EXPR || rhs_code == EXACT_DIV_EXPR))
    4146          445 :         do_ext = true;
    4147              :     }
    4148          445 :   if (bitint_extended == bitint_ext_full
    4149            0 :       && abi_limb_prec > limb_prec
    4150            0 :       && (CEIL (prec, abi_limb_prec) * abi_limb_prec
    4151            0 :           > CEIL (prec, limb_prec) * limb_prec))
    4152              :     {
    4153              :       /* unsigned multiplication needs to wrap around, so we can't
    4154              :          increase prec.  Similarly for -fwrapv.  */
    4155            0 :       if (do_ext)
    4156              :         ext_ms_limb = true;
    4157              :       else
    4158            0 :         prec = CEIL (prec, abi_limb_prec) * abi_limb_prec;
    4159              :     }
    4160          445 :   tree sitype = lang_hooks.types.type_for_mode (SImode, 0);
    4161          445 :   gimple *g;
    4162          445 :   switch (rhs_code)
    4163              :     {
    4164          282 :     case MULT_EXPR:
    4165          282 :       g = gimple_build_call_internal (IFN_MULBITINT, 6,
    4166          282 :                                       lhs, build_int_cst (sitype, prec),
    4167          282 :                                       rhs1, build_int_cst (sitype, prec1),
    4168          282 :                                       rhs2, build_int_cst (sitype, prec2));
    4169          282 :       insert_before (g);
    4170          282 :       break;
    4171          103 :     case TRUNC_DIV_EXPR:
    4172          103 :     case EXACT_DIV_EXPR:
    4173          103 :       g = gimple_build_call_internal (IFN_DIVMODBITINT, 8,
    4174          103 :                                       lhs, build_int_cst (sitype, prec),
    4175              :                                       null_pointer_node,
    4176              :                                       build_int_cst (sitype, 0),
    4177          103 :                                       rhs1, build_int_cst (sitype, prec1),
    4178          103 :                                       rhs2, build_int_cst (sitype, prec2));
    4179          103 :       if (!stmt_ends_bb_p (stmt))
    4180          102 :         gimple_call_set_nothrow (as_a <gcall *> (g), true);
    4181          103 :       insert_before (g);
    4182          103 :       break;
    4183           60 :     case TRUNC_MOD_EXPR:
    4184           60 :       g = gimple_build_call_internal (IFN_DIVMODBITINT, 8, null_pointer_node,
    4185              :                                       build_int_cst (sitype, 0),
    4186           60 :                                       lhs, build_int_cst (sitype, prec),
    4187           60 :                                       rhs1, build_int_cst (sitype, prec1),
    4188           60 :                                       rhs2, build_int_cst (sitype, prec2));
    4189           60 :       if (!stmt_ends_bb_p (stmt))
    4190           57 :         gimple_call_set_nothrow (as_a <gcall *> (g), true);
    4191           60 :       insert_before (g);
    4192           60 :       break;
    4193            0 :     default:
    4194            0 :       gcc_unreachable ();
    4195              :     }
    4196          445 :   if (stmt_ends_bb_p (stmt))
    4197              :     {
    4198            4 :       maybe_duplicate_eh_stmt (g, stmt);
    4199            4 :       edge e1;
    4200            4 :       edge_iterator ei;
    4201            4 :       basic_block bb = gimple_bb (stmt);
    4202              : 
    4203            4 :       FOR_EACH_EDGE (e1, ei, bb->succs)
    4204            4 :         if (e1->flags & EDGE_EH)
    4205              :           break;
    4206            4 :       if (e1)
    4207              :         {
    4208            4 :           edge e2 = split_block (gsi_bb (m_gsi), g);
    4209            4 :           m_gsi = gsi_after_labels (e2->dest);
    4210            4 :           add_eh_edge (e2->src, e1);
    4211              :         }
    4212              :     }
    4213          445 :   if (do_ext
    4214          445 :       && ((prec % limb_prec) != 0 || (ext_ms_limb && !TYPE_UNSIGNED (type))))
    4215              :     {
    4216              :       /* Unsigned multiplication wraps, but libgcc function will return the
    4217              :          bits beyond prec within the top limb as another limb of the full
    4218              :          multiplication.  So, clear the padding bits here.  */
    4219            0 :       tree idx = size_int (bitint_big_endian ? 0 : prec / limb_prec);
    4220            0 :       tree l = limb_access (type, obj, idx, true);
    4221            0 :       tree ctype = limb_access_type (type, idx);
    4222            0 :       tree v = make_ssa_name (m_limb_type);
    4223            0 :       g = gimple_build_assign (v, l);
    4224            0 :       insert_before (g);
    4225            0 :       tree v2 = v;
    4226            0 :       if ((prec % limb_prec) != 0)
    4227              :         {
    4228            0 :           v = add_cast (ctype, v);
    4229            0 :           l = limb_access (type, obj, idx, true);
    4230            0 :           v = add_cast (m_limb_type, v);
    4231            0 :           v2 = v;
    4232            0 :           g = gimple_build_assign (l, v);
    4233            0 :           insert_before (g);
    4234              :         }
    4235            0 :       if (ext_ms_limb && !TYPE_UNSIGNED (type))
    4236              :         {
    4237            0 :           v2 = add_cast (signed_type_for (m_limb_type), v2);
    4238            0 :           tree lpm1 = build_int_cst (unsigned_type_node, limb_prec - 1);
    4239            0 :           v = make_ssa_name (TREE_TYPE (v2));
    4240            0 :           g = gimple_build_assign (v, RSHIFT_EXPR, v2, lpm1);
    4241            0 :           insert_before (g);
    4242            0 :           unsigned int i
    4243            0 :             = CEIL (prec, abi_limb_prec) * abi_limb_prec / limb_prec;
    4244            0 :           v = add_cast (m_limb_type, v);
    4245            0 :           g = gimple_build_assign (limb_access (type, obj, size_int (i - 1),
    4246              :                                                 true), v);
    4247            0 :           insert_before (g);
    4248            0 :           ext_ms_limb = false;
    4249              :         }
    4250              :     }
    4251          445 :   if (ext_ms_limb)
    4252              :     {
    4253            0 :       unsigned int i = CEIL (prec, abi_limb_prec) * abi_limb_prec / limb_prec;
    4254            0 :       g = gimple_build_assign (limb_access (type, obj, size_int (i - 1), true),
    4255              :                                build_zero_cst (m_limb_type));
    4256            0 :       insert_before (g);
    4257              :     }
    4258          445 : }
    4259              : 
    4260              : /* Lower large/huge _BitInt conversion to/from floating point.  */
    4261              : 
    4262              : void
    4263          327 : bitint_large_huge::lower_float_conv_stmt (tree obj, gimple *stmt)
    4264              : {
    4265          327 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    4266          327 :   tree lhs = gimple_assign_lhs (stmt);
    4267          327 :   tree_code rhs_code = gimple_assign_rhs_code (stmt);
    4268          327 :   tree sitype = lang_hooks.types.type_for_mode (SImode, 0);
    4269          327 :   gimple *g;
    4270          327 :   if (rhs_code == FIX_TRUNC_EXPR)
    4271              :     {
    4272          179 :       tree type = TREE_TYPE (lhs);
    4273          179 :       int prec = TYPE_PRECISION (type);
    4274          179 :       bool extend_ms_limb = false;
    4275          179 :       if (bitint_extended == bitint_ext_full
    4276            0 :           && abi_limb_prec > limb_prec
    4277            0 :           && (CEIL (prec, abi_limb_prec) * abi_limb_prec
    4278            0 :               > CEIL (prec, limb_prec) * limb_prec))
    4279          179 :         extend_ms_limb = true;
    4280          179 :       if (!TYPE_UNSIGNED (type))
    4281           93 :         prec = -prec;
    4282          179 :       if (obj == NULL_TREE)
    4283              :         {
    4284          135 :           int part = var_to_partition (m_map, lhs);
    4285          135 :           gcc_assert (m_vars[part] != NULL_TREE);
    4286          135 :           obj = m_vars[part];
    4287          135 :           lhs = build_fold_addr_expr (obj);
    4288              :         }
    4289              :       else
    4290              :         {
    4291           44 :           lhs = build_fold_addr_expr (obj);
    4292           44 :           lhs = force_gimple_operand_gsi (&m_gsi, lhs, true,
    4293              :                                           NULL_TREE, true, GSI_SAME_STMT);
    4294              :         }
    4295          179 :       scalar_mode from_mode
    4296          179 :         = as_a <scalar_mode> (TYPE_MODE (TREE_TYPE (rhs1)));
    4297              : #ifdef HAVE_SFmode
    4298              :       /* IEEE single is a full superset of both IEEE half and
    4299              :          bfloat formats, convert to float first and then to _BitInt
    4300              :          to avoid the need of another 2 library routines.  */
    4301          179 :       if ((REAL_MODE_FORMAT (from_mode) == &arm_bfloat_half_format
    4302          179 :            || REAL_MODE_FORMAT (from_mode) == &ieee_half_format)
    4303          191 :           && REAL_MODE_FORMAT (SFmode) == &ieee_single_format)
    4304              :         {
    4305           12 :           tree type = lang_hooks.types.type_for_mode (SFmode, 0);
    4306           12 :           if (type)
    4307           12 :             rhs1 = add_cast (type, rhs1);
    4308              :         }
    4309              : #endif
    4310          179 :       g = gimple_build_call_internal (IFN_FLOATTOBITINT, 3,
    4311          179 :                                       lhs, build_int_cst (sitype, prec),
    4312              :                                       rhs1);
    4313          179 :       insert_before (g);
    4314          179 :       if (extend_ms_limb)
    4315              :         {
    4316            0 :           unsigned int i
    4317            0 :             = (CEIL (prec < 0 ? -prec : prec, abi_limb_prec)
    4318            0 :                * abi_limb_prec / limb_prec);
    4319            0 :           tree val;
    4320            0 :           if (prec < 0)
    4321              :             {
    4322            0 :               gassign *a = gimple_build_assign (make_ssa_name (m_limb_type),
    4323              :                                                 limb_access (type, obj,
    4324            0 :                                                              size_int (i - 2),
    4325              :                                                              true));
    4326            0 :               insert_before (a);
    4327            0 :               val = add_cast (signed_type_for (m_limb_type),
    4328              :                               gimple_assign_lhs (a));
    4329            0 :               a = gimple_build_assign (make_ssa_name (TREE_TYPE (val)),
    4330              :                                        RSHIFT_EXPR, val,
    4331              :                                        build_int_cst (unsigned_type_node,
    4332            0 :                                                       limb_prec - 1));
    4333            0 :               insert_before (a);
    4334            0 :               val = add_cast (m_limb_type, gimple_assign_lhs (a));
    4335              :             }
    4336              :           else
    4337            0 :             val = build_zero_cst (m_limb_type);
    4338            0 :           g = gimple_build_assign (limb_access (type, obj, size_int (i - 1),
    4339              :                                                 true), val);
    4340            0 :           insert_before (g);
    4341              :         }
    4342              :     }
    4343              :   else
    4344              :     {
    4345          148 :       int prec;
    4346          148 :       rhs1 = handle_operand_addr (rhs1, stmt, NULL, &prec);
    4347          148 :       g = gimple_build_call_internal (IFN_BITINTTOFLOAT, 2,
    4348          148 :                                       rhs1, build_int_cst (sitype, prec));
    4349          148 :       gimple_call_set_lhs (g, lhs);
    4350          148 :       if (!stmt_ends_bb_p (stmt))
    4351          147 :         gimple_call_set_nothrow (as_a <gcall *> (g), true);
    4352          148 :       gsi_replace (&m_gsi, g, true);
    4353              :     }
    4354          327 : }
    4355              : 
    4356              : /* Helper method for lower_addsub_overflow and lower_mul_overflow.
    4357              :    If check_zero is true, caller wants to check if all bits in [start, end)
    4358              :    are zero, otherwise if bits in [start, end) are either all zero or
    4359              :    all ones.  L is the limb with index LIMB, START and END are measured
    4360              :    in bits.  */
    4361              : 
    4362              : tree
    4363         6453 : bitint_large_huge::arith_overflow_extract_bits (unsigned int start,
    4364              :                                                 unsigned int end, tree l,
    4365              :                                                 unsigned int limb,
    4366              :                                                 bool check_zero)
    4367              : {
    4368         6453 :   unsigned startlimb = start / limb_prec;
    4369         6453 :   unsigned endlimb = (end - 1) / limb_prec;
    4370              : 
    4371         6453 :   if ((start % limb_prec) == 0 && (end % limb_prec) == 0)
    4372              :     return l;
    4373         6184 :   if (startlimb == endlimb && limb == startlimb)
    4374              :     {
    4375         2039 :       if (check_zero)
    4376              :         {
    4377         1486 :           wide_int w = wi::shifted_mask (start % limb_prec,
    4378         1486 :                                          end - start, false, limb_prec);
    4379         2972 :           gassign *a = gimple_build_assign (make_ssa_name (m_limb_type),
    4380              :                                             BIT_AND_EXPR, l,
    4381         1486 :                                             wide_int_to_tree (m_limb_type, w));
    4382         1486 :           insert_before (a);
    4383         1486 :           return gimple_assign_lhs (a);
    4384         1486 :         }
    4385          553 :       unsigned int shift = start % limb_prec;
    4386          553 :       if ((end % limb_prec) != 0)
    4387              :         {
    4388          336 :           unsigned int lshift = (-end) % limb_prec;
    4389          336 :           shift += lshift;
    4390          336 :           gassign *a = gimple_build_assign (make_ssa_name (m_limb_type),
    4391              :                                             LSHIFT_EXPR, l,
    4392              :                                             build_int_cst (unsigned_type_node,
    4393          336 :                                                            lshift));
    4394          336 :           insert_before (a);
    4395          336 :           l = gimple_assign_lhs (a);
    4396              :         }
    4397          553 :       l = add_cast (signed_type_for (m_limb_type), l);
    4398          553 :       gassign *a = gimple_build_assign (make_ssa_name (TREE_TYPE (l)),
    4399              :                                         RSHIFT_EXPR, l,
    4400              :                                         build_int_cst (unsigned_type_node,
    4401          553 :                                                        shift));
    4402          553 :       insert_before (a);
    4403          553 :       return add_cast (m_limb_type, gimple_assign_lhs (a));
    4404              :     }
    4405         4145 :   else if (limb == startlimb)
    4406              :     {
    4407         1990 :       if ((start % limb_prec) == 0)
    4408              :         return l;
    4409         1876 :       if (!check_zero)
    4410          950 :         l = add_cast (signed_type_for (m_limb_type), l);
    4411         1876 :       gassign *a = gimple_build_assign (make_ssa_name (TREE_TYPE (l)),
    4412              :                                         RSHIFT_EXPR, l,
    4413              :                                         build_int_cst (unsigned_type_node,
    4414         1876 :                                                        start % limb_prec));
    4415         1876 :       insert_before (a);
    4416         1876 :       l = gimple_assign_lhs (a);
    4417         1876 :       if (!check_zero)
    4418          950 :         l = add_cast (m_limb_type, l);
    4419              :       return l;
    4420              :     }
    4421         2155 :   else if (limb == endlimb)
    4422              :     {
    4423         1704 :       if ((end % limb_prec) == 0)
    4424              :         return l;
    4425         1687 :       if (check_zero)
    4426              :         {
    4427          880 :           wide_int w = wi::mask (end % limb_prec, false, limb_prec);
    4428         1760 :           gassign *a = gimple_build_assign (make_ssa_name (m_limb_type),
    4429              :                                             BIT_AND_EXPR, l,
    4430          880 :                                             wide_int_to_tree (m_limb_type, w));
    4431          880 :           insert_before (a);
    4432          880 :           return gimple_assign_lhs (a);
    4433          880 :         }
    4434          807 :       unsigned int shift = (-end) % limb_prec;
    4435          807 :       gassign *a = gimple_build_assign (make_ssa_name (m_limb_type),
    4436              :                                         LSHIFT_EXPR, l,
    4437              :                                         build_int_cst (unsigned_type_node,
    4438          807 :                                                        shift));
    4439          807 :       insert_before (a);
    4440          807 :       l = add_cast (signed_type_for (m_limb_type), gimple_assign_lhs (a));
    4441          807 :       a = gimple_build_assign (make_ssa_name (TREE_TYPE (l)),
    4442              :                                RSHIFT_EXPR, l,
    4443          807 :                                build_int_cst (unsigned_type_node, shift));
    4444          807 :       insert_before (a);
    4445          807 :       return add_cast (m_limb_type, gimple_assign_lhs (a));
    4446              :     }
    4447              :   return l;
    4448              : }
    4449              : 
    4450              : /* Helper method for lower_addsub_overflow and lower_mul_overflow.  Store
    4451              :    result including overflow flag into the right locations.  */
    4452              : 
    4453              : void
    4454         4212 : bitint_large_huge::finish_arith_overflow (tree var, tree obj, tree type,
    4455              :                                           tree ovf, tree lhs, tree orig_obj,
    4456              :                                           gimple *stmt, unsigned nelts,
    4457              :                                           tree_code code)
    4458              : {
    4459         4212 :   gimple *g;
    4460              : 
    4461         4212 :   if (obj == NULL_TREE
    4462         4212 :       && (!BITINT_TYPE_P (type)
    4463          231 :           || bitint_precision_kind (type) < bitint_prec_large))
    4464              :     {
    4465              :       /* Add support for 3 or more limbs filled in from normal integral
    4466              :          type if this assert fails.  If no target chooses limb mode smaller
    4467              :          than half of largest supported normal integral type, this will not
    4468              :          be needed.  */
    4469          250 :       gcc_assert (TYPE_PRECISION (type) <= 2 * limb_prec);
    4470          250 :       tree lhs_type = type;
    4471          110 :       if (BITINT_TYPE_P (type)
    4472          250 :           && bitint_precision_kind (type) == bitint_prec_middle)
    4473           46 :         lhs_type = build_nonstandard_integer_type (TYPE_PRECISION (type),
    4474           46 :                                                    TYPE_UNSIGNED (type));
    4475          250 :       tree r1 = limb_access (NULL_TREE, var,
    4476              :                              bitint_big_endian
    4477            0 :                              ? size_int (nelts - 1) : size_zero_node, true);
    4478          250 :       gassign *a = gimple_build_assign (make_ssa_name (m_limb_type), r1);
    4479          250 :       insert_before (a);
    4480          250 :       r1 = gimple_assign_lhs (a);
    4481          250 :       if (!useless_type_conversion_p (lhs_type, TREE_TYPE (r1)))
    4482          250 :         r1 = add_cast (lhs_type, r1);
    4483          250 :       if (TYPE_PRECISION (lhs_type) > limb_prec)
    4484              :         {
    4485           90 :           tree r2 = limb_access (NULL_TREE, var,
    4486              :                                  bitint_big_endian
    4487            0 :                                  ? size_int (nelts - 2) : size_one_node, true);
    4488           90 :           gassign *a = gimple_build_assign (make_ssa_name (m_limb_type), r2);
    4489           90 :           insert_before (a);
    4490           90 :           r2 = gimple_assign_lhs (a);
    4491           90 :           r2 = add_cast (lhs_type, r2);
    4492           90 :           a = gimple_build_assign (make_ssa_name (lhs_type), LSHIFT_EXPR, r2,
    4493              :                                    build_int_cst (unsigned_type_node,
    4494           90 :                                                   limb_prec));
    4495           90 :           insert_before (a);
    4496           90 :           a = gimple_build_assign (make_ssa_name (lhs_type), BIT_IOR_EXPR, r1,
    4497              :                                    gimple_assign_lhs (a));
    4498           90 :           insert_before (a);
    4499           90 :           r1 = gimple_assign_lhs (a);
    4500              :         }
    4501          250 :       if (lhs_type != type)
    4502           46 :         r1 = add_cast (type, r1);
    4503          250 :       ovf = add_cast (lhs_type, ovf);
    4504          250 :       if (lhs_type != type)
    4505           46 :         ovf = add_cast (type, ovf);
    4506          250 :       g = gimple_build_assign (lhs, COMPLEX_EXPR, r1, ovf);
    4507          250 :       m_gsi = gsi_for_stmt (stmt);
    4508          250 :       gsi_replace (&m_gsi, g, true);
    4509              :     }
    4510              :   else
    4511              :     {
    4512         3962 :       unsigned HOST_WIDE_INT obj_nelts = 0;
    4513         3962 :       tree atype = NULL_TREE;
    4514         3962 :       if (obj)
    4515              :         {
    4516         3871 :           obj_nelts = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (obj))) / limb_prec;
    4517         3871 :           if (orig_obj == NULL_TREE)
    4518         2277 :             obj_nelts >>= 1;
    4519         3871 :           atype = build_array_type_nelts (m_limb_type, obj_nelts);
    4520              :         }
    4521         3962 :       if (bitint_extended && (var || obj))
    4522              :         {
    4523            0 :           unsigned prec = TYPE_PRECISION (type);
    4524            0 :           unsigned prec_limbs = CEIL (prec, limb_prec);
    4525            0 :           bool ext_ms_limb
    4526              :             = (bitint_extended == bitint_ext_full
    4527            0 :                && abi_limb_prec > limb_prec
    4528            0 :                && (CEIL (prec, abi_limb_prec) * abi_limb_prec
    4529            0 :                    > CEIL (prec, limb_prec) * limb_prec));
    4530              :           /* For .{ADD,SUB}_OVERFLOW the partial limb if any is
    4531              :              already extended in lower_addsub_overflow.  */
    4532            0 :           if ((code == MULT_EXPR && (prec % limb_prec) != 0)
    4533            0 :               || (ext_ms_limb && !TYPE_UNSIGNED (type)))
    4534              :             {
    4535            0 :               tree plm1idx = size_int (bitint_big_endian
    4536              :                                        ? nelts - obj_nelts : prec_limbs - 1);
    4537            0 :               tree plm1type
    4538            0 :                 = limb_access_type (type, bitint_big_endian
    4539              :                                           ? size_zero_node : plm1idx);
    4540            0 :               tree l = limb_access (bitint_big_endian ? NULL_TREE : type,
    4541              :                                     var ? var : obj, plm1idx, true);
    4542            0 :               tree rhs = make_ssa_name (TREE_TYPE (l));
    4543            0 :               g = gimple_build_assign (rhs, l);
    4544            0 :               insert_before (g);
    4545            0 :               if (code == MULT_EXPR && (prec % limb_prec) != 0)
    4546              :                 {
    4547            0 :                   if (!useless_type_conversion_p (plm1type, TREE_TYPE (rhs)))
    4548            0 :                     rhs = add_cast (plm1type, rhs);
    4549            0 :                   if (!useless_type_conversion_p (TREE_TYPE (l),
    4550            0 :                                                   TREE_TYPE (rhs)))
    4551            0 :                     rhs = add_cast (TREE_TYPE (l), rhs);
    4552            0 :                   l = limb_access (bitint_big_endian ? NULL_TREE : type,
    4553              :                                    var ? var : obj, plm1idx, true);
    4554            0 :                   g = gimple_build_assign (l, rhs);
    4555            0 :                   insert_before (g);
    4556              :                 }
    4557            0 :               if (ext_ms_limb && !TYPE_UNSIGNED (type))
    4558              :                 {
    4559            0 :                   rhs = add_cast (signed_type_for (m_limb_type), rhs);
    4560            0 :                   tree lpm1 = build_int_cst (unsigned_type_node,
    4561            0 :                                              limb_prec - 1);
    4562            0 :                   tree v = make_ssa_name (TREE_TYPE (rhs));
    4563            0 :                   g = gimple_build_assign (v, RSHIFT_EXPR, rhs, lpm1);
    4564            0 :                   insert_before (g);
    4565            0 :                   unsigned int i
    4566            0 :                     = CEIL (prec, abi_limb_prec) * abi_limb_prec / limb_prec;
    4567            0 :                   v = add_cast (m_limb_type, v);
    4568            0 :                   g = gimple_build_assign (limb_access (type, var ? var : obj,
    4569            0 :                                                         size_int (i - 1),
    4570              :                                                         true), v);
    4571            0 :                   insert_before (g);
    4572            0 :                   ext_ms_limb = false;
    4573              :                 }
    4574              :             }
    4575            0 :           if (ext_ms_limb)
    4576              :             {
    4577            0 :               unsigned int i
    4578            0 :                 = CEIL (prec, abi_limb_prec) * abi_limb_prec / limb_prec;
    4579            0 :               g = gimple_build_assign (limb_access (type, var ? var : obj,
    4580            0 :                                                     size_int (i - 1), true),
    4581              :                                        build_zero_cst (m_limb_type));
    4582            0 :               insert_before (g);
    4583              :             }
    4584              :         }
    4585         3962 :       if (var && obj)
    4586              :         {
    4587          519 :           tree v1, v2;
    4588          519 :           tree off;
    4589          519 :           if (orig_obj == NULL_TREE)
    4590              :             {
    4591           32 :               off = build_zero_cst (build_pointer_type (TREE_TYPE (obj)));
    4592           32 :               v1 = build2 (MEM_REF, atype,
    4593              :                            build_fold_addr_expr (unshare_expr (obj)), off);
    4594              :             }
    4595          487 :           else if (!useless_type_conversion_p (atype, TREE_TYPE (obj)))
    4596            9 :             v1 = build1 (VIEW_CONVERT_EXPR, atype, unshare_expr (obj));
    4597              :           else
    4598          478 :             v1 = unshare_expr (obj);
    4599          519 :           off = build_int_cst (build_pointer_type (TREE_TYPE (var)),
    4600              :                                bitint_big_endian
    4601          519 :                                ? (nelts - obj_nelts) * m_limb_size : 0);
    4602          519 :           v2 = build2 (MEM_REF, atype, build_fold_addr_expr (var), off);
    4603          519 :           g = gimple_build_assign (v1, v2);
    4604          519 :           insert_before (g);
    4605              :         }
    4606         3443 :       else if (obj && bitint_big_endian && nelts != obj_nelts)
    4607              :         {
    4608            0 :           gcc_assert (nelts > obj_nelts);
    4609            0 :           tree fn = builtin_decl_implicit (BUILT_IN_MEMMOVE);
    4610            0 :           tree off = build_int_cst (build_pointer_type (TREE_TYPE (obj)),
    4611            0 :                                     (nelts - obj_nelts) * m_limb_size);
    4612            0 :           tree src = build2 (MEM_REF, atype,
    4613              :                              build_fold_addr_expr (unshare_expr (obj)), off);
    4614            0 :           g = gimple_build_call (fn, 3,
    4615              :                                  build_fold_addr_expr (unshare_expr (obj)),
    4616              :                                  build_fold_addr_expr (src),
    4617              :                                  build_int_cst (size_type_node,
    4618            0 :                                                 obj_nelts * m_limb_size));
    4619            0 :           insert_before (g);
    4620              :         }
    4621         3962 :       if (orig_obj == NULL_TREE && obj)
    4622              :         {
    4623         2277 :           ovf = add_cast (m_limb_type, ovf);
    4624         2277 :           tree l = limb_access (NULL_TREE, obj,
    4625         2277 :                                 size_int (bitint_big_endian
    4626              :                                           ? obj_nelts * 2 - 1 : obj_nelts),
    4627              :                                 true);
    4628         2277 :           g = gimple_build_assign (l, ovf);
    4629         2277 :           insert_before (g);
    4630         2277 :           if (obj_nelts > 1)
    4631              :             {
    4632         2277 :               atype = build_array_type_nelts (m_limb_type, obj_nelts - 1);
    4633         2277 :               tree off = build_int_cst (build_pointer_type (TREE_TYPE (obj)),
    4634         2277 :                                         (obj_nelts + !bitint_big_endian)
    4635         2277 :                                         * m_limb_size);
    4636         2277 :               tree v1 = build2 (MEM_REF, atype,
    4637              :                                 build_fold_addr_expr (unshare_expr (obj)),
    4638              :                                 off);
    4639         2277 :               g = gimple_build_assign (v1, build_zero_cst (atype));
    4640         2277 :               insert_before (g);
    4641              :             }
    4642              :         }
    4643         1685 :       else if (TREE_CODE (TREE_TYPE (lhs)) == COMPLEX_TYPE)
    4644              :         {
    4645         1640 :           imm_use_iterator ui;
    4646         1640 :           use_operand_p use_p;
    4647         1640 :           FOR_EACH_IMM_USE_FAST (use_p, ui, lhs)
    4648              :             {
    4649         1640 :               gassign *stmt = dyn_cast<gassign *> (USE_STMT (use_p));
    4650         3280 :               if (!stmt || gimple_assign_rhs_code (stmt) != IMAGPART_EXPR)
    4651            0 :                 continue;
    4652         1640 :               tree lhs2 = gimple_assign_lhs (stmt);
    4653         1640 :               gimple *use_stmt;
    4654         1640 :               single_imm_use (lhs2, &use_p, &use_stmt);
    4655         1640 :               lhs2 = gimple_assign_lhs (use_stmt);
    4656         1640 :               gimple_stmt_iterator gsi = gsi_for_stmt (use_stmt);
    4657         1640 :               if (useless_type_conversion_p (TREE_TYPE (lhs2), TREE_TYPE (ovf)))
    4658         1619 :                 g = gimple_build_assign (lhs2, ovf);
    4659              :               else
    4660           21 :                 g = gimple_build_assign (lhs2, NOP_EXPR, ovf);
    4661         1640 :               gsi_replace (&gsi, g, true);
    4662         1640 :               if (gsi_stmt (m_gsi) == use_stmt)
    4663           91 :                 m_gsi = gsi_for_stmt (g);
    4664         1640 :               break;
    4665         1640 :             }
    4666              :         }
    4667           45 :       else if (ovf != boolean_false_node)
    4668              :         {
    4669           45 :           g = gimple_build_cond (NE_EXPR, ovf, boolean_false_node,
    4670              :                                  NULL_TREE, NULL_TREE);
    4671           45 :           edge edge_true, edge_false;
    4672           45 :           if_then (g, profile_probability::very_unlikely (),
    4673              :                    edge_true, edge_false);
    4674           45 :           tree zero = build_zero_cst (TREE_TYPE (lhs));
    4675           45 :           tree fn = ubsan_build_overflow_builtin (code, m_loc,
    4676           45 :                                                   TREE_TYPE (lhs),
    4677              :                                                   zero, zero, NULL);
    4678           45 :           force_gimple_operand_gsi (&m_gsi, fn, true, NULL_TREE,
    4679              :                                     true, GSI_SAME_STMT);
    4680           45 :           m_gsi = gsi_after_labels (edge_true->dest);
    4681              :         }
    4682              :     }
    4683         4212 :   if (var)
    4684              :     {
    4685          781 :       tree clobber = build_clobber (TREE_TYPE (var), CLOBBER_STORAGE_END);
    4686          781 :       g = gimple_build_assign (var, clobber);
    4687          781 :       gsi_insert_after (&m_gsi, g, GSI_SAME_STMT);
    4688              :     }
    4689         4212 : }
    4690              : 
    4691              : /* Helper function for lower_addsub_overflow and lower_mul_overflow.
    4692              :    Given precisions of result TYPE (PREC), argument 0 precision PREC0,
    4693              :    argument 1 precision PREC1 and minimum precision for the result
    4694              :    PREC2, compute *START, *END, *CHECK_ZERO and return OVF.  */
    4695              : 
    4696              : static tree
    4697         4212 : arith_overflow (tree_code code, tree type, int prec, int prec0, int prec1,
    4698              :                 int prec2, unsigned *start, unsigned *end, bool *check_zero)
    4699              : {
    4700         4212 :   *start = 0;
    4701         4212 :   *end = 0;
    4702         4212 :   *check_zero = true;
    4703              :   /* Ignore this special rule for subtraction, even if both
    4704              :      prec0 >= 0 and prec1 >= 0, their subtraction can be negative
    4705              :      in infinite precision.  */
    4706         4212 :   if (code != MINUS_EXPR && prec0 >= 0 && prec1 >= 0)
    4707              :     {
    4708              :       /* Result in [0, prec2) is unsigned, if prec > prec2,
    4709              :          all bits above it will be zero.  */
    4710          681 :       if ((prec - !TYPE_UNSIGNED (type)) >= prec2)
    4711            0 :         return boolean_false_node;
    4712              :       else
    4713              :         {
    4714              :           /* ovf if any of bits in [start, end) is non-zero.  */
    4715          681 :           *start = prec - !TYPE_UNSIGNED (type);
    4716          681 :           *end = prec2;
    4717              :         }
    4718              :     }
    4719         3531 :   else if (TYPE_UNSIGNED (type))
    4720              :     {
    4721              :       /* If result in [0, prec2) is signed and if prec > prec2,
    4722              :          all bits above it will be sign bit copies.  */
    4723         1950 :       if (prec >= prec2)
    4724              :         {
    4725              :           /* ovf if bit prec - 1 is non-zero.  */
    4726          184 :           *start = prec - 1;
    4727          184 :           *end = prec;
    4728              :         }
    4729              :       else
    4730              :         {
    4731              :           /* ovf if any of bits in [start, end) is non-zero.  */
    4732         1766 :           *start = prec;
    4733         1766 :           *end = prec2;
    4734              :         }
    4735              :     }
    4736         1581 :   else if (prec >= prec2)
    4737            2 :     return boolean_false_node;
    4738              :   else
    4739              :     {
    4740              :       /* ovf if [start, end) bits aren't all zeros or all ones.  */
    4741         1579 :       *start = prec - 1;
    4742         1579 :       *end = prec2;
    4743         1579 :       *check_zero = false;
    4744              :     }
    4745              :   return NULL_TREE;
    4746              : }
    4747              : 
    4748              : /* Lower a .{ADD,SUB}_OVERFLOW call with at least one large/huge _BitInt
    4749              :    argument or return type _Complex large/huge _BitInt.  */
    4750              : 
    4751              : void
    4752         2733 : bitint_large_huge::lower_addsub_overflow (tree obj, gimple *stmt)
    4753              : {
    4754         2733 :   tree arg0 = gimple_call_arg (stmt, 0);
    4755         2733 :   tree arg1 = gimple_call_arg (stmt, 1);
    4756         2733 :   tree lhs = gimple_call_lhs (stmt);
    4757         2733 :   gimple *g;
    4758              : 
    4759         2733 :   if (!lhs)
    4760              :     {
    4761            0 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    4762            0 :       gsi_remove (&gsi, true);
    4763            0 :       return;
    4764              :     }
    4765         2733 :   gimple *final_stmt = gsi_stmt (m_gsi);
    4766         2733 :   tree type = TREE_TYPE (lhs);
    4767         2733 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    4768         2703 :     type = TREE_TYPE (type);
    4769         2733 :   int prec = TYPE_PRECISION (type);
    4770         2733 :   int prec0 = range_to_prec (arg0, stmt);
    4771         2733 :   int prec1 = range_to_prec (arg1, stmt);
    4772              :   /* If PREC0 >= 0 && PREC1 >= 0 and CODE is not MINUS_EXPR, PREC2 is
    4773              :      the minimum unsigned precision of any possible operation's
    4774              :      result, otherwise it is minimum signed precision.
    4775              :      Some examples:
    4776              :      If PREC0 or PREC1 is 8, it means that argument is [0, 0xff],
    4777              :      if PREC0 or PREC1 is 10, it means that argument is [0, 0x3ff],
    4778              :      if PREC0 or PREC1 is -8, it means that argument is [-0x80, 0x7f],
    4779              :      if PREC0 or PREC1 is -10, it means that argument is [-0x200, 0x1ff].
    4780              :      PREC0  CODE  PREC1  RESULT          PREC2  SIGNED vs. UNSIGNED
    4781              :        8      +     8    [0, 0x1fe]        9    UNSIGNED
    4782              :        8      +    10    [0, 0x4fe]       11    UNSIGNED
    4783              :       -8      +    -8    [-0x100, 0xfe]    9    SIGNED
    4784              :       -8      +   -10    [-0x280, 0x27e]  11    SIGNED
    4785              :        8      +    -8    [-0x80, 0x17e]   10    SIGNED
    4786              :        8      +   -10    [-0x200, 0x2fe]  11    SIGNED
    4787              :       10      +    -8    [-0x80, 0x47e]   12    SIGNED
    4788              :        8      -     8    [-0xff, 0xff]     9    SIGNED
    4789              :        8      -    10    [-0x3ff, 0xff]   11    SIGNED
    4790              :       10      -     8    [-0xff, 0x3ff]   11    SIGNED
    4791              :       -8      -    -8    [-0xff, 0xff]     9    SIGNED
    4792              :       -8      -   -10    [-0x27f, 0x27f]  11    SIGNED
    4793              :      -10      -    -8    [-0x27f, 0x27f]  11    SIGNED
    4794              :        8      -    -8    [-0x7f, 0x17f]   10    SIGNED
    4795              :        8      -   -10    [-0x1ff, 0x2ff]  11    SIGNED
    4796              :       10      -    -8    [-0x7f, 0x47f]   12    SIGNED
    4797              :       -8      -     8    [-0x17f, 0x7f]   10    SIGNED
    4798              :       -8      -    10    [-0x47f, 0x7f]   12    SIGNED
    4799              :      -10      -     8    [-0x2ff, 0x1ff]  11    SIGNED  */
    4800         2733 :   int prec2 = MAX (prec0 < 0 ? -prec0 : prec0,
    4801              :                    prec1 < 0 ? -prec1 : prec1);
    4802              :             /* If operands are either both signed or both unsigned,
    4803              :                we need just one additional bit.  */
    4804         3777 :   prec2 = (((prec0 < 0) == (prec1 < 0)
    4805              :                /* If one operand is signed and one unsigned and
    4806              :                   the signed one has larger precision, we need
    4807              :                   just one extra bit, otherwise two.  */
    4808          707 :             || (prec0 < 0 ? (prec2 == -prec0 && prec2 != prec1)
    4809          337 :                           : (prec2 == -prec1 && prec2 != prec0)))
    4810         2733 :            ? prec2 + 1 : prec2 + 2);
    4811         2733 :   int prec3 = MAX (prec0 < 0 ? -prec0 : prec0,
    4812              :                    prec1 < 0 ? -prec1 : prec1);
    4813         2733 :   prec3 = MAX (prec3, prec);
    4814         2733 :   tree var = NULL_TREE;
    4815         2733 :   tree orig_obj = obj;
    4816         2733 :   if (obj == NULL_TREE
    4817         1753 :       && BITINT_TYPE_P (type)
    4818         1652 :       && bitint_precision_kind (type) >= bitint_prec_large
    4819         1536 :       && m_names
    4820         4245 :       && bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs)))
    4821              :     {
    4822         1457 :       int part = var_to_partition (m_map, lhs);
    4823         1457 :       gcc_assert (m_vars[part] != NULL_TREE);
    4824         1457 :       obj = m_vars[part];
    4825         1457 :       if (TREE_TYPE (lhs) == type)
    4826           14 :         orig_obj = obj;
    4827              :     }
    4828          101 :   if (!BITINT_TYPE_P (type)
    4829         2733 :       || bitint_precision_kind (type) < bitint_prec_large)
    4830              :     {
    4831          217 :       unsigned HOST_WIDE_INT nelts = CEIL (prec, limb_prec);
    4832          217 :       tree atype = build_array_type_nelts (m_limb_type, nelts);
    4833          217 :       var = create_tmp_var (atype);
    4834              :     }
    4835              : 
    4836         2733 :   enum tree_code code;
    4837         2733 :   switch (gimple_call_internal_fn (stmt))
    4838              :     {
    4839              :     case IFN_ADD_OVERFLOW:
    4840              :     case IFN_UBSAN_CHECK_ADD:
    4841              :       code = PLUS_EXPR;
    4842              :       break;
    4843         1399 :     case IFN_SUB_OVERFLOW:
    4844         1399 :     case IFN_UBSAN_CHECK_SUB:
    4845         1399 :       code = MINUS_EXPR;
    4846         1399 :       break;
    4847            0 :     default:
    4848            0 :       gcc_unreachable ();
    4849              :     }
    4850         2733 :   unsigned start, end;
    4851         2733 :   bool check_zero;
    4852         2733 :   tree ovf = arith_overflow (code, type, prec, prec0, prec1, prec2,
    4853              :                              &start, &end, &check_zero);
    4854              : 
    4855         2733 :   unsigned startlimb, endlimb;
    4856         2733 :   if (ovf)
    4857              :     {
    4858              :       startlimb = ~0U;
    4859              :       endlimb = ~0U;
    4860              :     }
    4861              :   else
    4862              :     {
    4863         2733 :       startlimb = start / limb_prec;
    4864         2733 :       endlimb = (end - 1) / limb_prec;
    4865              :     }
    4866              : 
    4867         2733 :   int prec4 = ovf != NULL_TREE ? prec : prec3;
    4868         2733 :   bitint_prec_kind kind = bitint_precision_kind (prec4);
    4869         2733 :   unsigned cnt, rem = 0, fin = 0, nelts;
    4870         2733 :   tree idx = NULL_TREE, idx_first = NULL_TREE, idx_next = NULL_TREE;
    4871         5466 :   bool last_ovf = (ovf == NULL_TREE
    4872         2733 :                    && CEIL (prec2, limb_prec) > CEIL (prec3, limb_prec));
    4873         2733 :   if (kind != bitint_prec_huge)
    4874         1539 :     nelts = cnt = CEIL (prec4, limb_prec) + last_ovf;
    4875              :   else
    4876              :     {
    4877         1194 :       rem = prec4 % (2 * limb_prec);
    4878         1194 :       fin = (prec4 - rem) / limb_prec;
    4879         1194 :       cnt = 2 + CEIL (rem, limb_prec) + last_ovf;
    4880         1194 :       nelts = fin + cnt - 2;
    4881         1194 :       idx = idx_first = create_loop (bitint_big_endian
    4882         1194 :                                      ? size_int (nelts - 1) : size_zero_node,
    4883              :                                      &idx_next);
    4884              :     }
    4885              : 
    4886         2733 :   if (kind == bitint_prec_huge)
    4887         1194 :     m_upwards_2limb = fin;
    4888         2733 :   m_upwards = true;
    4889              : 
    4890         2733 :   tree type0 = TREE_TYPE (arg0);
    4891         2733 :   tree type1 = TREE_TYPE (arg1);
    4892         2733 :   int prec5 = prec3;
    4893         2733 :   if (bitint_precision_kind (prec5) < bitint_prec_large)
    4894           10 :     prec5 = MAX (TYPE_PRECISION (type0), TYPE_PRECISION (type1));
    4895         2733 :   if (TYPE_PRECISION (type0) < prec5)
    4896              :     {
    4897          146 :       type0 = build_bitint_type (prec5, TYPE_UNSIGNED (type0));
    4898          146 :       if (TREE_CODE (arg0) == INTEGER_CST)
    4899           27 :         arg0 = fold_convert (type0, arg0);
    4900              :     }
    4901         2733 :   if (TYPE_PRECISION (type1) < prec5)
    4902              :     {
    4903          156 :       type1 = build_bitint_type (prec5, TYPE_UNSIGNED (type1));
    4904          156 :       if (TREE_CODE (arg1) == INTEGER_CST)
    4905           76 :         arg1 = fold_convert (type1, arg1);
    4906              :     }
    4907         2733 :   unsigned int data_cnt = 0;
    4908         2733 :   tree last_rhs1 = NULL_TREE, last_rhs2 = NULL_TREE;
    4909         2733 :   tree cmp = build_zero_cst (m_limb_type);
    4910         2733 :   unsigned prec_limbs = CEIL ((unsigned) prec, limb_prec);
    4911         2733 :   tree ovf_out = NULL_TREE, cmp_out = NULL_TREE;
    4912        11904 :   for (unsigned i = 0; i < cnt; i++)
    4913              :     {
    4914         9171 :       m_data_cnt = 0;
    4915         9171 :       tree rhs1, rhs2;
    4916         9171 :       if (kind != bitint_prec_huge)
    4917         5303 :         idx = size_int (bitint_big_endian ? nelts - 1 - i : i);
    4918         3868 :       else if (i >= 2)
    4919         1480 :         idx = size_int (bitint_big_endian ? nelts + 1 - fin - i : fin + i - 2);
    4920         9171 :       if (!last_ovf || i < cnt - 1)
    4921              :         {
    4922         8225 :           tree idx0 = idx, idx1 = idx;
    4923         8225 :           if (bitint_big_endian
    4924         8225 :               && CEIL ((unsigned) TYPE_PRECISION (type0), limb_prec) != nelts)
    4925              :             {
    4926            0 :               HOST_WIDE_INT diff
    4927            0 :                 = ((HOST_WIDE_INT) CEIL (TYPE_PRECISION (type0), limb_prec)
    4928            0 :                    - (HOST_WIDE_INT) nelts);
    4929            0 :               if (tree_fits_uhwi_p (idx))
    4930            0 :                 idx0 = size_int (tree_to_uhwi (idx) + diff);
    4931              :               else
    4932              :                 {
    4933            0 :                   idx0 = make_ssa_name (sizetype);
    4934            0 :                   g = gimple_build_assign (idx0, PLUS_EXPR, idx,
    4935            0 :                                            size_int (diff));
    4936            0 :                   insert_before (g);
    4937              :                 }
    4938              :             }
    4939         8225 :           if (type0 != TREE_TYPE (arg0))
    4940          334 :             rhs1 = handle_cast (type0, arg0, idx0);
    4941              :           else
    4942         7891 :             rhs1 = handle_operand (arg0, idx0);
    4943         8225 :           if (bitint_big_endian
    4944         8225 :               && CEIL ((unsigned) TYPE_PRECISION (type1), limb_prec) != nelts)
    4945              :             {
    4946            0 :               HOST_WIDE_INT diff
    4947            0 :                 = ((HOST_WIDE_INT) CEIL (TYPE_PRECISION (type1), limb_prec)
    4948            0 :                    - (HOST_WIDE_INT) nelts);
    4949            0 :               if (tree_fits_uhwi_p (idx))
    4950            0 :                 idx1 = size_int (tree_to_uhwi (idx) + diff);
    4951              :               else
    4952              :                 {
    4953            0 :                   idx1 = make_ssa_name (sizetype);
    4954            0 :                   g = gimple_build_assign (idx1, PLUS_EXPR, idx,
    4955            0 :                                            size_int (diff));
    4956            0 :                   insert_before (g);
    4957              :                 }
    4958              :             }
    4959         8225 :           if (type1 != TREE_TYPE (arg1))
    4960          250 :             rhs2 = handle_cast (type1, arg1, idx1);
    4961              :           else
    4962         7975 :             rhs2 = handle_operand (arg1, idx1);
    4963         8225 :           if (i == 0)
    4964         2733 :             data_cnt = m_data_cnt;
    4965         8225 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1)))
    4966         1983 :             rhs1 = add_cast (m_limb_type, rhs1);
    4967         8225 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs2)))
    4968         1983 :             rhs2 = add_cast (m_limb_type, rhs2);
    4969              :           last_rhs1 = rhs1;
    4970              :           last_rhs2 = rhs2;
    4971              :         }
    4972              :       else
    4973              :         {
    4974          946 :           m_data_cnt = data_cnt;
    4975          946 :           if (TYPE_UNSIGNED (type0) || prec0 >= 0)
    4976          421 :             rhs1 = build_zero_cst (m_limb_type);
    4977              :           else
    4978              :             {
    4979          525 :               rhs1 = add_cast (signed_type_for (m_limb_type), last_rhs1);
    4980          525 :               if (TREE_CODE (rhs1) == INTEGER_CST)
    4981           52 :                 rhs1 = build_int_cst (m_limb_type,
    4982           74 :                                       tree_int_cst_sgn (rhs1) < 0 ? -1 : 0);
    4983              :               else
    4984              :                 {
    4985          946 :                   tree lpm1 = build_int_cst (unsigned_type_node,
    4986          473 :                                              limb_prec - 1);
    4987          473 :                   gassign *a
    4988          473 :                     = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)),
    4989              :                                            RSHIFT_EXPR, rhs1, lpm1);
    4990          473 :                   insert_before (a);
    4991          473 :                   rhs1 = add_cast (m_limb_type, gimple_assign_lhs (a));
    4992              :                 }
    4993              :             }
    4994          946 :           if (TYPE_UNSIGNED (type1) || prec1 >= 0)
    4995          543 :             rhs2 = build_zero_cst (m_limb_type);
    4996              :           else
    4997              :             {
    4998          403 :               rhs2 = add_cast (signed_type_for (m_limb_type), last_rhs2);
    4999          403 :               if (TREE_CODE (rhs2) == INTEGER_CST)
    5000          114 :                 rhs2 = build_int_cst (m_limb_type,
    5001          153 :                                       tree_int_cst_sgn (rhs2) < 0 ? -1 : 0);
    5002              :               else
    5003              :                 {
    5004          578 :                   tree lpm1 = build_int_cst (unsigned_type_node,
    5005          289 :                                              limb_prec - 1);
    5006          289 :                   gassign *a
    5007          289 :                     = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs2)),
    5008              :                                            RSHIFT_EXPR, rhs2, lpm1);
    5009          289 :                   insert_before (a);
    5010          289 :                   rhs2 = add_cast (m_limb_type, gimple_assign_lhs (a));
    5011              :                 }
    5012              :             }
    5013              :         }
    5014         9171 :       tree rhs = handle_plus_minus (code, rhs1, rhs2, idx);
    5015         9171 :       if (ovf != boolean_false_node)
    5016              :         {
    5017         9171 :           if (tree_fits_uhwi_p (idx))
    5018              :             {
    5019         6783 :               unsigned limb = tree_to_uhwi (idx);
    5020         6783 :               if (bitint_big_endian)
    5021            0 :                 limb = nelts - 1 - limb;
    5022         6783 :               if (limb >= startlimb && limb <= endlimb)
    5023              :                 {
    5024         3370 :                   tree l = arith_overflow_extract_bits (start, end, rhs,
    5025              :                                                         limb, check_zero);
    5026         3370 :                   tree this_ovf = make_ssa_name (boolean_type_node);
    5027         3370 :                   if (ovf == NULL_TREE && !check_zero)
    5028              :                     {
    5029          907 :                       cmp = l;
    5030          907 :                       g = gimple_build_assign (make_ssa_name (m_limb_type),
    5031              :                                                PLUS_EXPR, l,
    5032              :                                                build_int_cst (m_limb_type, 1));
    5033          907 :                       insert_before (g);
    5034          907 :                       g = gimple_build_assign (this_ovf, GT_EXPR,
    5035              :                                                gimple_assign_lhs (g),
    5036              :                                                build_int_cst (m_limb_type, 1));
    5037              :                     }
    5038              :                   else
    5039         2463 :                     g = gimple_build_assign (this_ovf, NE_EXPR, l, cmp);
    5040         3370 :                   insert_before (g);
    5041         3370 :                   if (ovf == NULL_TREE)
    5042              :                     ovf = this_ovf;
    5043              :                   else
    5044              :                     {
    5045         1064 :                       tree b = make_ssa_name (boolean_type_node);
    5046         1064 :                       g = gimple_build_assign (b, BIT_IOR_EXPR, ovf, this_ovf);
    5047         1064 :                       insert_before (g);
    5048         1064 :                       ovf = b;
    5049              :                     }
    5050              :                 }
    5051              :             }
    5052         2388 :           else if (startlimb < fin)
    5053              :             {
    5054          854 :               if (m_first && startlimb + 2 < fin)
    5055              :                 {
    5056          324 :                   tree data_out;
    5057          324 :                   ovf = prepare_data_in_out (boolean_false_node, idx, &data_out);
    5058          324 :                   ovf_out = m_data.pop ();
    5059          324 :                   m_data.pop ();
    5060          324 :                   if (!check_zero)
    5061              :                     {
    5062          169 :                       cmp = prepare_data_in_out (cmp, idx, &data_out);
    5063          169 :                       cmp_out = m_data.pop ();
    5064          169 :                       m_data.pop ();
    5065              :                     }
    5066              :                 }
    5067          854 :               if (i != 0 || startlimb != fin - 1)
    5068              :                 {
    5069          839 :                   tree_code cmp_code;
    5070          839 :                   bool single_comparison
    5071          839 :                     = (startlimb + 2 >= fin || (startlimb & 1) != (i & 1));
    5072              :                   if (!single_comparison)
    5073              :                     cmp_code = GE_EXPR;
    5074          515 :                   else if ((startlimb & 1) == (i & 1))
    5075              :                     cmp_code = EQ_EXPR;
    5076              :                   else
    5077          412 :                     cmp_code = GT_EXPR;
    5078          839 :                   if (bitint_big_endian)
    5079            0 :                     g = gimple_build_cond (swap_tree_comparison (cmp_code),
    5080            0 :                                            idx, size_int (nelts - 1
    5081              :                                                           - startlimb),
    5082              :                                            NULL_TREE, NULL_TREE);
    5083              :                   else
    5084          839 :                     g = gimple_build_cond (cmp_code, idx, size_int (startlimb),
    5085              :                                            NULL_TREE, NULL_TREE);
    5086          839 :                   edge edge_true_true, edge_true_false, edge_false;
    5087          839 :                   gimple *g2 = NULL;
    5088          839 :                   if (!single_comparison)
    5089          324 :                     g2 = gimple_build_cond (NE_EXPR, idx,
    5090          324 :                                             size_int (bitint_big_endian
    5091              :                                                       ? nelts - 1 - startlimb
    5092              :                                                       : startlimb),
    5093              :                                             NULL_TREE, NULL_TREE);
    5094          839 :                   if_then_if_then_else (g, g2, profile_probability::likely (),
    5095              :                                         profile_probability::likely (),
    5096              :                                         edge_true_true, edge_true_false,
    5097              :                                         edge_false);
    5098          839 :                   unsigned tidx = startlimb + (cmp_code == GT_EXPR);
    5099          839 :                   tree l = arith_overflow_extract_bits (start, end, rhs, tidx,
    5100              :                                                         check_zero);
    5101          839 :                   tree this_ovf = make_ssa_name (boolean_type_node);
    5102          839 :                   gassign *a;
    5103          839 :                   if (cmp_code != GT_EXPR && !check_zero)
    5104              :                     {
    5105          173 :                       a = gimple_build_assign (make_ssa_name (m_limb_type),
    5106              :                                                PLUS_EXPR, l,
    5107              :                                                build_int_cst (m_limb_type, 1));
    5108          173 :                       insert_before (a);
    5109          173 :                       a = gimple_build_assign (this_ovf, GT_EXPR,
    5110              :                                                gimple_assign_lhs (a),
    5111              :                                                build_int_cst (m_limb_type, 1));
    5112              :                     }
    5113              :                   else
    5114          666 :                     a = gimple_build_assign (this_ovf, NE_EXPR, l, cmp);
    5115          839 :                   insert_before (a);
    5116          839 :                   if (cmp_code == GT_EXPR)
    5117              :                     {
    5118          412 :                       tree t = make_ssa_name (boolean_type_node);
    5119          412 :                       a = gimple_build_assign (t, BIT_IOR_EXPR, ovf, this_ovf);
    5120          412 :                       insert_before (a);
    5121          412 :                       this_ovf = t;
    5122              :                     }
    5123          839 :                   tree this_ovf2 = NULL_TREE;
    5124          839 :                   if (!single_comparison)
    5125              :                     {
    5126          324 :                       m_gsi = gsi_after_labels (edge_true_true->src);
    5127          324 :                       tree t = make_ssa_name (boolean_type_node);
    5128          324 :                       g = gimple_build_assign (t, NE_EXPR, rhs, cmp);
    5129          324 :                       insert_before (g);
    5130          324 :                       this_ovf2 = make_ssa_name (boolean_type_node);
    5131          324 :                       g = gimple_build_assign (this_ovf2, BIT_IOR_EXPR,
    5132              :                                                ovf, t);
    5133          324 :                       insert_before (g);
    5134              :                     }
    5135          839 :                   m_gsi = gsi_after_labels (edge_true_false->dest);
    5136          839 :                   tree t;
    5137          839 :                   if (i == 1 && ovf_out)
    5138              :                     t = ovf_out;
    5139              :                   else
    5140          515 :                     t = make_ssa_name (boolean_type_node);
    5141          839 :                   gphi *phi = create_phi_node (t, edge_true_false->dest);
    5142          839 :                   add_phi_arg (phi, this_ovf, edge_true_false,
    5143              :                                UNKNOWN_LOCATION);
    5144          839 :                   add_phi_arg (phi, ovf ? ovf
    5145              :                                     : boolean_false_node, edge_false,
    5146              :                                UNKNOWN_LOCATION);
    5147          839 :                   if (edge_true_true)
    5148          324 :                     add_phi_arg (phi, this_ovf2, edge_true_true,
    5149              :                                  UNKNOWN_LOCATION);
    5150          839 :                   ovf = t;
    5151          839 :                   if (!check_zero && cmp_code != GT_EXPR)
    5152              :                     {
    5153          173 :                       t = cmp_out ? cmp_out : make_ssa_name (m_limb_type);
    5154          173 :                       phi = create_phi_node (t, edge_true_false->dest);
    5155          173 :                       add_phi_arg (phi, l, edge_true_false, UNKNOWN_LOCATION);
    5156          173 :                       add_phi_arg (phi, cmp, edge_false, UNKNOWN_LOCATION);
    5157          173 :                       if (edge_true_true)
    5158          169 :                         add_phi_arg (phi, cmp, edge_true_true,
    5159              :                                      UNKNOWN_LOCATION);
    5160              :                       cmp = t;
    5161              :                     }
    5162              :                 }
    5163              :             }
    5164              :         }
    5165              : 
    5166         9171 :       if (var || obj)
    5167              :         {
    5168         8943 :           if (tree_fits_uhwi_p (idx)
    5169         6673 :               && (bitint_big_endian
    5170         6673 :                   ? nelts - 1 - tree_to_uhwi (idx)
    5171         6673 :                   : tree_to_uhwi (idx)) >= prec_limbs)
    5172              :             ;
    5173         7555 :           else if (!tree_fits_uhwi_p (idx)
    5174         2270 :                    && (unsigned) prec < (fin - (i == 0)) * limb_prec)
    5175              :             {
    5176         1458 :               bool single_comparison
    5177          729 :                 = (((unsigned) prec % limb_prec) == 0
    5178          571 :                    || prec_limbs + 1 >= fin
    5179         1231 :                    || (prec_limbs & 1) == (i & 1));
    5180          729 :               if (bitint_big_endian)
    5181            0 :                 g = gimple_build_cond (GE_EXPR, idx,
    5182            0 :                                        size_int (nelts - prec_limbs),
    5183              :                                        NULL_TREE, NULL_TREE);
    5184              :               else
    5185          729 :                 g = gimple_build_cond (LE_EXPR, idx, size_int (prec_limbs - 1),
    5186              :                                        NULL_TREE, NULL_TREE);
    5187          729 :               gimple *g2 = NULL;
    5188          729 :               if (!single_comparison)
    5189          251 :                 g2 = gimple_build_cond (EQ_EXPR, idx,
    5190          251 :                                         size_int (bitint_big_endian
    5191              :                                                   ? nelts - prec_limbs
    5192              :                                                   : prec_limbs - 1),
    5193              :                                         NULL_TREE, NULL_TREE);
    5194          729 :               edge edge_true_true, edge_true_false, edge_false;
    5195          729 :               if_then_if_then_else (g, g2, profile_probability::likely (),
    5196              :                                     profile_probability::unlikely (),
    5197              :                                     edge_true_true, edge_true_false,
    5198              :                                     edge_false);
    5199          729 :               tree idxl = idx;
    5200          729 :               if (bitint_big_endian && prec_limbs != nelts)
    5201              :                 {
    5202            0 :                   HOST_WIDE_INT diff = ((HOST_WIDE_INT) prec_limbs
    5203            0 :                                         - (HOST_WIDE_INT) nelts);
    5204            0 :                   if (tree_fits_uhwi_p (idx))
    5205            0 :                     idxl = size_int (tree_to_uhwi (idx) + diff);
    5206              :                   else
    5207              :                     {
    5208            0 :                       idxl = make_ssa_name (sizetype);
    5209            0 :                       g = gimple_build_assign (idxl, PLUS_EXPR, idx,
    5210            0 :                                                size_int (diff));
    5211            0 :                       insert_before (g);
    5212              :                     }
    5213              :                 }
    5214         1082 :               tree l = limb_access (type, var ? var : obj, idxl, true);
    5215          729 :               g = gimple_build_assign (l, rhs);
    5216          729 :               insert_before (g);
    5217          729 :               if (!single_comparison)
    5218              :                 {
    5219          251 :                   m_gsi = gsi_after_labels (edge_true_true->src);
    5220          251 :                   tree plm1idx = size_int (bitint_big_endian
    5221              :                                            ? 0 : prec_limbs - 1);
    5222          251 :                   tree plm1type = limb_access_type (type, plm1idx);
    5223          251 :                   l = limb_access (type, var ? var : obj, plm1idx, true);
    5224          251 :                   if (!useless_type_conversion_p (plm1type, TREE_TYPE (rhs)))
    5225          251 :                     rhs = add_cast (plm1type, rhs);
    5226          251 :                   if (!useless_type_conversion_p (TREE_TYPE (l),
    5227          251 :                                                   TREE_TYPE (rhs)))
    5228          251 :                     rhs = add_cast (TREE_TYPE (l), rhs);
    5229          251 :                   g = gimple_build_assign (l, rhs);
    5230          251 :                   insert_before (g);
    5231              :                 }
    5232          729 :               m_gsi = gsi_after_labels (edge_true_false->dest);
    5233          729 :             }
    5234              :           else
    5235              :             {
    5236         6826 :               tree idxl = idx;
    5237         6826 :               if (bitint_big_endian && prec_limbs != nelts)
    5238              :                 {
    5239            0 :                   HOST_WIDE_INT diff = ((HOST_WIDE_INT) prec_limbs
    5240            0 :                                         - (HOST_WIDE_INT) nelts);
    5241            0 :                   if (tree_fits_uhwi_p (idx))
    5242            0 :                     idxl = size_int (tree_to_uhwi (idx) + diff);
    5243              :                   else
    5244              :                     {
    5245            0 :                       idxl = make_ssa_name (sizetype);
    5246            0 :                       g = gimple_build_assign (idxl, PLUS_EXPR, idx,
    5247            0 :                                                size_int (diff));
    5248            0 :                       insert_before (g);
    5249              :                     }
    5250              :                 }
    5251        13623 :               tree l = limb_access (type, var ? var : obj, idxl, true);
    5252         6826 :               if (bitint_extended && tree_fits_uhwi_p (idxl))
    5253              :                 {
    5254            0 :                   tree atype = limb_access_type (type, idxl);
    5255            0 :                   if (!useless_type_conversion_p (atype, TREE_TYPE (rhs)))
    5256            0 :                     rhs = add_cast (atype, rhs);
    5257              :                 }
    5258         6826 :               if (!useless_type_conversion_p (TREE_TYPE (l), TREE_TYPE (rhs)))
    5259            0 :                 rhs = add_cast (TREE_TYPE (l), rhs);
    5260         6826 :               g = gimple_build_assign (l, rhs);
    5261         6826 :               insert_before (g);
    5262              :             }
    5263              :         }
    5264         9171 :       m_first = false;
    5265         9171 :       if (kind == bitint_prec_huge && i <= 1)
    5266              :         {
    5267         2388 :           if (i == 0)
    5268              :             {
    5269         1194 :               idx = make_ssa_name (sizetype);
    5270         1194 :               g = gimple_build_assign (idx, PLUS_EXPR, idx_first,
    5271              :                                        bitint_big_endian
    5272            0 :                                        ? size_int (-1) : size_one_node);
    5273         1194 :               insert_before (g);
    5274              :             }
    5275              :           else
    5276              :             {
    5277         1194 :               g = gimple_build_assign (idx_next, PLUS_EXPR, idx_first,
    5278         2388 :                                        size_int (bitint_big_endian ? -2 : 2));
    5279         1194 :               insert_before (g);
    5280         1194 :               if (bitint_big_endian)
    5281            0 :                 g = gimple_build_cond (NE_EXPR, idx_first,
    5282            0 :                                        size_int (nelts + 1 - fin),
    5283              :                                        NULL_TREE, NULL_TREE);
    5284              :               else
    5285         1194 :                 g = gimple_build_cond (NE_EXPR, idx_next, size_int (fin),
    5286              :                                        NULL_TREE, NULL_TREE);
    5287         1194 :               insert_before (g);
    5288         1194 :               m_gsi = gsi_for_stmt (final_stmt);
    5289         1194 :               m_bb = NULL;
    5290              :             }
    5291              :         }
    5292              :     }
    5293              : 
    5294         2733 :   finish_arith_overflow (var, obj, type, ovf, lhs, orig_obj, stmt,
    5295              :                          prec_limbs, code);
    5296              : }
    5297              : 
    5298              : /* Lower a .MUL_OVERFLOW call with at least one large/huge _BitInt
    5299              :    argument or return type _Complex large/huge _BitInt.  */
    5300              : 
    5301              : void
    5302         1479 : bitint_large_huge::lower_mul_overflow (tree obj, gimple *stmt)
    5303              : {
    5304         1479 :   tree arg0 = gimple_call_arg (stmt, 0);
    5305         1479 :   tree arg1 = gimple_call_arg (stmt, 1);
    5306         1479 :   tree lhs = gimple_call_lhs (stmt);
    5307         1479 :   if (!lhs)
    5308              :     {
    5309            0 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    5310            0 :       gsi_remove (&gsi, true);
    5311            0 :       return;
    5312              :     }
    5313         1479 :   gimple *final_stmt = gsi_stmt (m_gsi);
    5314         1479 :   tree type = TREE_TYPE (lhs);
    5315         1479 :   if (TREE_CODE (type) == COMPLEX_TYPE)
    5316         1464 :     type = TREE_TYPE (type);
    5317         1479 :   int prec = TYPE_PRECISION (type), prec0, prec1;
    5318         1479 :   arg0 = handle_operand_addr (arg0, stmt, NULL, &prec0);
    5319         1479 :   arg1 = handle_operand_addr (arg1, stmt, NULL, &prec1);
    5320         1479 :   int prec2 = ((prec0 < 0 ? -prec0 : prec0)
    5321         1479 :                + (prec1 < 0 ? -prec1 : prec1));
    5322         1479 :   if (prec0 == 1 || prec1 == 1)
    5323           35 :     --prec2;
    5324         1479 :   tree var = NULL_TREE;
    5325         1479 :   tree orig_obj = obj;
    5326         1479 :   bool force_var = false;
    5327         1479 :   if (obj == NULL_TREE
    5328          886 :       && BITINT_TYPE_P (type)
    5329          877 :       && bitint_precision_kind (type) >= bitint_prec_large
    5330          853 :       && m_names
    5331         2320 :       && bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs)))
    5332              :     {
    5333          841 :       int part = var_to_partition (m_map, lhs);
    5334          841 :       gcc_assert (m_vars[part] != NULL_TREE);
    5335          841 :       obj = m_vars[part];
    5336          841 :       if (TREE_TYPE (lhs) == type)
    5337            7 :         orig_obj = obj;
    5338              :     }
    5339          638 :   else if (obj != NULL_TREE && DECL_P (obj))
    5340              :     {
    5341         1755 :       for (int i = 0; i < 2; ++i)
    5342              :         {
    5343         1170 :           tree arg = i ? arg1 : arg0;
    5344         1170 :           if (TREE_CODE (arg) == ADDR_EXPR)
    5345         1170 :             arg = TREE_OPERAND (arg, 0);
    5346         1170 :           if (get_base_address (arg) == obj)
    5347              :             {
    5348              :               force_var = true;
    5349              :               break;
    5350              :             }
    5351              :         }
    5352              :     }
    5353         1479 :   if (obj == NULL_TREE
    5354         1479 :       || force_var
    5355         1434 :       || !BITINT_TYPE_P (type)
    5356         1434 :       || bitint_precision_kind (type) < bitint_prec_large
    5357         3747 :       || prec2 > (CEIL (prec, limb_prec) * limb_prec * (orig_obj ? 1 : 2)))
    5358              :     {
    5359          564 :       unsigned HOST_WIDE_INT nelts = CEIL (MAX (prec, prec2), limb_prec);
    5360          564 :       tree atype = build_array_type_nelts (m_limb_type, nelts);
    5361          564 :       var = create_tmp_var (atype);
    5362              :     }
    5363         1479 :   tree addr = build_fold_addr_expr (var ? var : obj);
    5364         1479 :   addr = force_gimple_operand_gsi (&m_gsi, addr, true,
    5365              :                                    NULL_TREE, true, GSI_SAME_STMT);
    5366         1479 :   tree sitype = lang_hooks.types.type_for_mode (SImode, 0);
    5367         1479 :   gimple *g
    5368         1479 :     = gimple_build_call_internal (IFN_MULBITINT, 6,
    5369              :                                   addr, build_int_cst (sitype,
    5370         1479 :                                                        MAX (prec2, prec)),
    5371         1479 :                                   arg0, build_int_cst (sitype, prec0),
    5372         1479 :                                   arg1, build_int_cst (sitype, prec1));
    5373         1479 :   insert_before (g);
    5374              : 
    5375         1479 :   unsigned start, end;
    5376         1479 :   bool check_zero;
    5377         1479 :   tree ovf = arith_overflow (MULT_EXPR, type, prec, prec0, prec1, prec2,
    5378              :                              &start, &end, &check_zero);
    5379         1479 :   if (ovf == NULL_TREE)
    5380              :     {
    5381         1477 :       unsigned startlimb = start / limb_prec;
    5382         1477 :       unsigned endlimb = (end - 1) / limb_prec;
    5383         1477 :       unsigned nelts = CEIL (MAX (prec, prec2), limb_prec);
    5384         1477 :       unsigned cnt;
    5385         1477 :       bool use_loop = false;
    5386         1477 :       if (startlimb == endlimb)
    5387              :         cnt = 1;
    5388         1190 :       else if (startlimb + 1 == endlimb)
    5389              :         cnt = 2;
    5390         1013 :       else if ((end % limb_prec) == 0)
    5391              :         {
    5392              :           cnt = 2;
    5393              :           use_loop = true;
    5394              :         }
    5395              :       else
    5396              :         {
    5397          767 :           cnt = 3;
    5398          767 :           use_loop = startlimb + 2 < endlimb;
    5399              :         }
    5400          767 :       if (cnt == 1)
    5401              :         {
    5402          507 :           tree l = limb_access (NULL_TREE, var ? var : obj,
    5403          287 :                                 size_int (bitint_big_endian
    5404              :                                           ? nelts - 1 - startlimb
    5405              :                                           :  startlimb), true);
    5406          287 :           gassign *a = gimple_build_assign (make_ssa_name (m_limb_type), l);
    5407          287 :           insert_before (a);
    5408          287 :           l = arith_overflow_extract_bits (start, end, gimple_assign_lhs (a),
    5409              :                                            startlimb, check_zero);
    5410          287 :           ovf = make_ssa_name (boolean_type_node);
    5411          287 :           if (check_zero)
    5412          247 :             a = gimple_build_assign (ovf, NE_EXPR, l,
    5413              :                                      build_zero_cst (m_limb_type));
    5414              :           else
    5415              :             {
    5416           40 :               a = gimple_build_assign (make_ssa_name (m_limb_type),
    5417              :                                        PLUS_EXPR, l,
    5418              :                                        build_int_cst (m_limb_type, 1));
    5419           40 :               insert_before (a);
    5420           40 :               a = gimple_build_assign (ovf, GT_EXPR, gimple_assign_lhs (a),
    5421              :                                        build_int_cst (m_limb_type, 1));
    5422              :             }
    5423          287 :           insert_before (a);
    5424              :         }
    5425              :       else
    5426              :         {
    5427         1190 :           basic_block edge_bb = NULL;
    5428         1190 :           gimple_stmt_iterator gsi = m_gsi;
    5429         1190 :           gsi_prev (&gsi);
    5430         1190 :           edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    5431         1190 :           edge_bb = e->src;
    5432         1190 :           m_gsi = gsi_end_bb (edge_bb);
    5433              : 
    5434         1190 :           tree cmp = build_zero_cst (m_limb_type);
    5435         5527 :           for (unsigned i = 0; i < cnt; i++)
    5436              :             {
    5437         3147 :               tree idx, idx_next = NULL_TREE;
    5438         3147 :               if (i == 0)
    5439         1190 :                 idx = size_int (bitint_big_endian
    5440              :                                 ? nelts - 1 - startlimb : startlimb);
    5441         1957 :               else if (i == 2)
    5442          767 :                 idx = size_int (bitint_big_endian
    5443              :                                 ? nelts - 1 - endlimb : endlimb);
    5444         1190 :               else if (use_loop)
    5445          665 :                 idx = create_loop (size_int (bitint_big_endian
    5446              :                                              ? nelts - startlimb - 2
    5447              :                                              : startlimb + 1), &idx_next);
    5448              :               else
    5449          525 :                 idx = size_int (bitint_big_endian
    5450              :                                 ? nelts - startlimb - 2 : startlimb + 1);
    5451         4988 :               tree l = limb_access (NULL_TREE, var ? var : obj, idx, true);
    5452         3147 :               gassign *a = gimple_build_assign (make_ssa_name (m_limb_type), l);
    5453         3147 :               insert_before (a);
    5454         3147 :               l = gimple_assign_lhs (a);
    5455         3147 :               if (i == 0 || i == 2)
    5456         2724 :                 l = arith_overflow_extract_bits (start, end, l,
    5457              :                                                  i == 0 ? startlimb : endlimb,
    5458              :                                                  check_zero);
    5459         1957 :               if (i == 0 && !check_zero)
    5460              :                 {
    5461          459 :                   cmp = l;
    5462          459 :                   a = gimple_build_assign (make_ssa_name (m_limb_type),
    5463              :                                            PLUS_EXPR, l,
    5464              :                                            build_int_cst (m_limb_type, 1));
    5465          459 :                   insert_before (a);
    5466          459 :                   g = gimple_build_cond (GT_EXPR, gimple_assign_lhs (a),
    5467              :                                          build_int_cst (m_limb_type, 1),
    5468              :                                          NULL_TREE, NULL_TREE);
    5469              :                 }
    5470              :               else
    5471         2688 :                 g = gimple_build_cond (NE_EXPR, l, cmp, NULL_TREE, NULL_TREE);
    5472         3147 :               insert_before (g);
    5473         3147 :               edge e1 = split_block (gsi_bb (m_gsi), g);
    5474         3147 :               e1->flags = EDGE_FALSE_VALUE;
    5475         3147 :               edge e2 = make_edge (e1->src, gimple_bb (final_stmt),
    5476              :                                    EDGE_TRUE_VALUE);
    5477         3147 :               e1->probability = profile_probability::likely ();
    5478         3147 :               e2->probability = e1->probability.invert ();
    5479         3147 :               if (i == 0)
    5480         1190 :                 set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    5481         3147 :               m_gsi = gsi_after_labels (e1->dest);
    5482         3147 :               if (i == 1 && use_loop)
    5483              :                 {
    5484          665 :                   g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    5485              :                                            bitint_big_endian
    5486            0 :                                            ? size_int (-1) : size_one_node);
    5487          665 :                   insert_before (g);
    5488          665 :                   if (bitint_big_endian)
    5489            0 :                     g = gimple_build_cond (NE_EXPR, idx,
    5490            0 :                                            size_int (nelts - endlimb
    5491              :                                                      - (cnt == 2)),
    5492              :                                            NULL_TREE, NULL_TREE);
    5493              :                   else
    5494          665 :                     g = gimple_build_cond (NE_EXPR, idx_next,
    5495          665 :                                            size_int (endlimb + (cnt == 2)),
    5496              :                                            NULL_TREE, NULL_TREE);
    5497          665 :                   insert_before (g);
    5498          665 :                   edge true_edge, false_edge;
    5499          665 :                   extract_true_false_edges_from_block (gsi_bb (m_gsi),
    5500              :                                                        &true_edge,
    5501              :                                                        &false_edge);
    5502          665 :                   m_gsi = gsi_after_labels (false_edge->dest);
    5503          665 :                   m_bb = NULL;
    5504              :                 }
    5505              :             }
    5506              : 
    5507         1190 :           ovf = make_ssa_name (boolean_type_node);
    5508         1190 :           basic_block bb = gimple_bb (final_stmt);
    5509         1190 :           gphi *phi = create_phi_node (ovf, bb);
    5510         1190 :           edge e1 = find_edge (gsi_bb (m_gsi), bb);
    5511         1190 :           edge_iterator ei;
    5512         5527 :           FOR_EACH_EDGE (e, ei, bb->preds)
    5513              :             {
    5514         4337 :               tree val = e == e1 ? boolean_false_node : boolean_true_node;
    5515         4337 :               add_phi_arg (phi, val, e, UNKNOWN_LOCATION);
    5516              :             }
    5517         1190 :           m_gsi = gsi_for_stmt (final_stmt);
    5518              :         }
    5519              :     }
    5520              : 
    5521         1479 :   finish_arith_overflow (var, obj, type, ovf, lhs, orig_obj, stmt,
    5522         1479 :                          CEIL (MAX (prec, prec2), limb_prec), MULT_EXPR);
    5523              : }
    5524              : 
    5525              : /* Lower REALPART_EXPR or IMAGPART_EXPR stmt extracting part of result from
    5526              :    .{ADD,SUB,MUL}_OVERFLOW call.  */
    5527              : 
    5528              : void
    5529         6023 : bitint_large_huge::lower_cplxpart_stmt (tree obj, gimple *stmt)
    5530              : {
    5531         6023 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    5532         6023 :   rhs1 = TREE_OPERAND (rhs1, 0);
    5533         6023 :   if (obj == NULL_TREE)
    5534              :     {
    5535         5930 :       int part = var_to_partition (m_map, gimple_assign_lhs (stmt));
    5536         5930 :       gcc_assert (m_vars[part] != NULL_TREE);
    5537              :       obj = m_vars[part];
    5538              :     }
    5539         6023 :   if (TREE_CODE (rhs1) == SSA_NAME
    5540         6023 :       && (m_names == NULL
    5541         6022 :           || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1))))
    5542              :     {
    5543         1549 :       lower_call (obj, SSA_NAME_DEF_STMT (rhs1));
    5544         1549 :       return;
    5545              :     }
    5546         4474 :   int part = var_to_partition (m_map, rhs1);
    5547         4474 :   gcc_assert (m_vars[part] != NULL_TREE);
    5548         4474 :   tree var = m_vars[part];
    5549         4474 :   unsigned HOST_WIDE_INT nelts
    5550         4474 :     = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (obj))) / limb_prec;
    5551         4474 :   tree atype = build_array_type_nelts (m_limb_type, nelts);
    5552         4474 :   if (!useless_type_conversion_p (atype, TREE_TYPE (obj)))
    5553          122 :     obj = build1 (VIEW_CONVERT_EXPR, atype, obj);
    5554         4474 :   tree off = build_int_cst (build_pointer_type (TREE_TYPE (var)),
    5555         4474 :                             gimple_assign_rhs_code (stmt) == REALPART_EXPR
    5556         4474 :                             ? 0 : nelts * m_limb_size);
    5557         4474 :   tree v2 = build2 (MEM_REF, atype, build_fold_addr_expr (var), off);
    5558         4474 :   gimple *g = gimple_build_assign (obj, v2);
    5559         4474 :   insert_before (g);
    5560              : }
    5561              : 
    5562              : /* Lower COMPLEX_EXPR or COMPLEX_CST stmt.  */
    5563              : 
    5564              : void
    5565           62 : bitint_large_huge::lower_complexexpr_stmt (gimple *stmt)
    5566              : {
    5567           62 :   tree lhs = gimple_assign_lhs (stmt);
    5568           62 :   tree rhs1 = gimple_assign_rhs1 (stmt), rhs2;
    5569           62 :   if (gimple_assign_rhs_code (stmt) == COMPLEX_EXPR)
    5570           61 :     rhs2 = gimple_assign_rhs2 (stmt);
    5571              :   else
    5572              :     {
    5573            1 :       rhs2 = TREE_IMAGPART (rhs1);
    5574            1 :       rhs1 = TREE_REALPART (rhs1);
    5575              :     }
    5576           62 :   int part = var_to_partition (m_map, lhs);
    5577           62 :   gcc_assert (m_vars[part] != NULL_TREE);
    5578           62 :   lhs = m_vars[part];
    5579           62 :   unsigned HOST_WIDE_INT nelts
    5580           62 :     = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (rhs1))) / limb_prec;
    5581           62 :   tree atype = build_array_type_nelts (m_limb_type, nelts);
    5582           62 :   tree zero = build_zero_cst (build_pointer_type (TREE_TYPE (lhs)));
    5583           62 :   tree v1 = build2 (MEM_REF, atype, build_fold_addr_expr (lhs), zero);
    5584           62 :   tree v2;
    5585           62 :   if (TREE_CODE (rhs1) == SSA_NAME)
    5586              :     {
    5587           28 :       part = var_to_partition (m_map, rhs1);
    5588           28 :       gcc_assert (m_vars[part] != NULL_TREE);
    5589              :       v2 = m_vars[part];
    5590              :     }
    5591           34 :   else if (integer_zerop (rhs1))
    5592           34 :     v2 = build_zero_cst (atype);
    5593              :   else
    5594            0 :     v2 = tree_output_constant_def (rhs1);
    5595           62 :   if (!useless_type_conversion_p (atype, TREE_TYPE (v2)))
    5596           18 :     v2 = build1 (VIEW_CONVERT_EXPR, atype, v2);
    5597           62 :   gimple *g = gimple_build_assign (v1, v2);
    5598           62 :   insert_before (g);
    5599           62 :   tree off = fold_convert (build_pointer_type (TREE_TYPE (lhs)),
    5600              :                            TYPE_SIZE_UNIT (atype));
    5601           62 :   v1 = build2 (MEM_REF, atype, build_fold_addr_expr (lhs), off);
    5602           62 :   if (TREE_CODE (rhs2) == SSA_NAME)
    5603              :     {
    5604           10 :       part = var_to_partition (m_map, rhs2);
    5605           10 :       gcc_assert (m_vars[part] != NULL_TREE);
    5606              :       v2 = m_vars[part];
    5607              :     }
    5608           52 :   else if (integer_zerop (rhs2))
    5609           51 :     v2 = build_zero_cst (atype);
    5610              :   else
    5611            1 :     v2 = tree_output_constant_def (rhs2);
    5612           62 :   if (!useless_type_conversion_p (atype, TREE_TYPE (v2)))
    5613           11 :     v2 = build1 (VIEW_CONVERT_EXPR, atype, v2);
    5614           62 :   g = gimple_build_assign (v1, v2);
    5615           62 :   insert_before (g);
    5616           62 : }
    5617              : 
    5618              : /* Lower a .{CLZ,CTZ,CLRSB,FFS,PARITY,POPCOUNT} call with one large/huge _BitInt
    5619              :    argument.  */
    5620              : 
    5621              : void
    5622          156 : bitint_large_huge::lower_bit_query (gimple *stmt)
    5623              : {
    5624          156 :   tree arg0 = gimple_call_arg (stmt, 0);
    5625          156 :   tree arg1 = (gimple_call_num_args (stmt) == 2
    5626          156 :                ? gimple_call_arg (stmt, 1) : NULL_TREE);
    5627          156 :   tree lhs = gimple_call_lhs (stmt);
    5628          156 :   gimple *g;
    5629              : 
    5630          156 :   if (!lhs)
    5631              :     {
    5632            0 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    5633            0 :       gsi_remove (&gsi, true);
    5634            0 :       return;
    5635              :     }
    5636          156 :   tree type = TREE_TYPE (arg0);
    5637          156 :   gcc_assert (BITINT_TYPE_P (type));
    5638          156 :   bitint_prec_kind kind = bitint_precision_kind (type);
    5639          156 :   gcc_assert (kind >= bitint_prec_large);
    5640          156 :   enum internal_fn ifn = gimple_call_internal_fn (stmt);
    5641          156 :   enum built_in_function fcode = END_BUILTINS;
    5642          156 :   gcc_assert (TYPE_PRECISION (unsigned_type_node) == limb_prec
    5643              :               || TYPE_PRECISION (long_unsigned_type_node) == limb_prec
    5644              :               || TYPE_PRECISION (long_long_unsigned_type_node) == limb_prec);
    5645          156 :   switch (ifn)
    5646              :     {
    5647           54 :     case IFN_CLZ:
    5648           54 :       if (TYPE_PRECISION (unsigned_type_node) == limb_prec)
    5649              :         fcode = BUILT_IN_CLZ;
    5650           54 :       else if (TYPE_PRECISION (long_unsigned_type_node) == limb_prec)
    5651              :         fcode = BUILT_IN_CLZL;
    5652              :       else
    5653            0 :         fcode = BUILT_IN_CLZLL;
    5654              :       break;
    5655           11 :     case IFN_FFS:
    5656              :       /* .FFS (X) is .CTZ (X, -1) + 1, though under the hood
    5657              :          we don't add the addend at the end.  */
    5658           11 :       arg1 = integer_zero_node;
    5659              :       /* FALLTHRU */
    5660           66 :     case IFN_CTZ:
    5661           66 :       if (TYPE_PRECISION (unsigned_type_node) == limb_prec)
    5662              :         fcode = BUILT_IN_CTZ;
    5663           66 :       else if (TYPE_PRECISION (long_unsigned_type_node) == limb_prec)
    5664              :         fcode = BUILT_IN_CTZL;
    5665              :       else
    5666            0 :         fcode = BUILT_IN_CTZLL;
    5667           66 :       m_upwards = true;
    5668           66 :       break;
    5669            9 :     case IFN_CLRSB:
    5670            9 :       if (TYPE_PRECISION (unsigned_type_node) == limb_prec)
    5671              :         fcode = BUILT_IN_CLRSB;
    5672            9 :       else if (TYPE_PRECISION (long_unsigned_type_node) == limb_prec)
    5673              :         fcode = BUILT_IN_CLRSBL;
    5674              :       else
    5675            0 :         fcode = BUILT_IN_CLRSBLL;
    5676              :       break;
    5677           16 :     case IFN_PARITY:
    5678           16 :       if (TYPE_PRECISION (unsigned_type_node) == limb_prec)
    5679              :         fcode = BUILT_IN_PARITY;
    5680           16 :       else if (TYPE_PRECISION (long_unsigned_type_node) == limb_prec)
    5681              :         fcode = BUILT_IN_PARITYL;
    5682              :       else
    5683            0 :         fcode = BUILT_IN_PARITYLL;
    5684           16 :       m_upwards = true;
    5685           16 :       break;
    5686           11 :     case IFN_POPCOUNT:
    5687           11 :       if (TYPE_PRECISION (unsigned_type_node) == limb_prec)
    5688              :         fcode = BUILT_IN_POPCOUNT;
    5689           11 :       else if (TYPE_PRECISION (long_unsigned_type_node) == limb_prec)
    5690              :         fcode = BUILT_IN_POPCOUNTL;
    5691              :       else
    5692            0 :         fcode = BUILT_IN_POPCOUNTLL;
    5693           11 :       m_upwards = true;
    5694           11 :       break;
    5695            0 :     default:
    5696            0 :       gcc_unreachable ();
    5697              :     }
    5698          156 :   tree fndecl = builtin_decl_explicit (fcode), res = NULL_TREE;
    5699          156 :   unsigned cnt = 0, rem = 0, end = 0, prec = TYPE_PRECISION (type);
    5700          156 :   unsigned nelts = CEIL (prec, limb_prec);
    5701          156 :   struct bq_details { edge e; tree val, addend; } *bqp = NULL;
    5702          156 :   basic_block edge_bb = NULL;
    5703          156 :   if (m_upwards)
    5704              :     {
    5705           93 :       tree idx = NULL_TREE, idx_first = NULL_TREE, idx_next = NULL_TREE;
    5706           93 :       if (kind == bitint_prec_large)
    5707              :         cnt = nelts;
    5708              :       else
    5709              :         {
    5710           66 :           rem = (prec % (2 * limb_prec));
    5711           66 :           end = (prec - rem) / limb_prec;
    5712           66 :           cnt = 2 + CEIL (rem, limb_prec);
    5713           66 :           idx = idx_first = create_loop (bitint_big_endian
    5714           66 :                                          ? size_int (nelts - 1)
    5715              :                                          : size_zero_node, &idx_next);
    5716              :         }
    5717              : 
    5718           93 :       if (ifn == IFN_CTZ || ifn == IFN_FFS)
    5719              :         {
    5720           66 :           gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    5721           66 :           gsi_prev (&gsi);
    5722           66 :           edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    5723           66 :           edge_bb = e->src;
    5724           66 :           if (kind == bitint_prec_large)
    5725           32 :             m_gsi = gsi_end_bb (edge_bb);
    5726           66 :           bqp = XALLOCAVEC (struct bq_details, cnt);
    5727              :         }
    5728              :       else
    5729           27 :         m_after_stmt = stmt;
    5730           93 :       if (kind != bitint_prec_large)
    5731           66 :         m_upwards_2limb = end;
    5732              : 
    5733          325 :       for (unsigned i = 0; i < cnt; i++)
    5734              :         {
    5735          232 :           m_data_cnt = 0;
    5736          232 :           if (kind == bitint_prec_large)
    5737           83 :             idx = size_int (bitint_big_endian ? nelts - 1 - i : i);
    5738          149 :           else if (i >= 2)
    5739           17 :             idx = size_int (bitint_big_endian
    5740              :                             ? nelts - 1 - end - (i > 2) : end + (i > 2));
    5741              : 
    5742          232 :           tree rhs1 = handle_operand (arg0, idx);
    5743          232 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1)))
    5744              :             {
    5745           32 :               if (!TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    5746            5 :                 rhs1 = add_cast (unsigned_type_for (TREE_TYPE (rhs1)), rhs1);
    5747           32 :               rhs1 = add_cast (m_limb_type, rhs1);
    5748              :             }
    5749              : 
    5750          232 :           tree in, out, tem;
    5751          232 :           if (ifn == IFN_PARITY)
    5752           43 :             in = prepare_data_in_out (build_zero_cst (m_limb_type), idx, &out);
    5753          189 :           else if (ifn == IFN_FFS)
    5754           29 :             in = prepare_data_in_out (integer_one_node, idx, &out);
    5755              :           else
    5756          160 :             in = prepare_data_in_out (integer_zero_node, idx, &out);
    5757              : 
    5758          232 :           switch (ifn)
    5759              :             {
    5760          158 :             case IFN_CTZ:
    5761          158 :             case IFN_FFS:
    5762          158 :               g = gimple_build_cond (NE_EXPR, rhs1,
    5763              :                                      build_zero_cst (m_limb_type),
    5764              :                                      NULL_TREE, NULL_TREE);
    5765          158 :               insert_before (g);
    5766          158 :               edge e1, e2;
    5767          158 :               e1 = split_block (gsi_bb (m_gsi), g);
    5768          158 :               e1->flags = EDGE_FALSE_VALUE;
    5769          158 :               e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE);
    5770          158 :               e1->probability = profile_probability::unlikely ();
    5771          158 :               e2->probability = e1->probability.invert ();
    5772          158 :               if (i == 0)
    5773           66 :                 set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    5774          158 :               m_gsi = gsi_after_labels (e1->dest);
    5775          158 :               bqp[i].e = e2;
    5776          158 :               bqp[i].val = rhs1;
    5777          158 :               if (tree_fits_uhwi_p (idx))
    5778           58 :                 bqp[i].addend
    5779           58 :                   = build_int_cst (integer_type_node,
    5780              :                                    (bitint_big_endian
    5781           58 :                                     ? nelts - 1 - tree_to_uhwi (idx)
    5782           58 :                                     : tree_to_uhwi (idx)) * limb_prec
    5783           58 :                                    + (ifn == IFN_FFS));
    5784              :               else
    5785              :                 {
    5786          100 :                   bqp[i].addend = in;
    5787          100 :                   if (i == 1)
    5788           50 :                     res = out;
    5789              :                   else
    5790           50 :                     res = make_ssa_name (integer_type_node);
    5791          100 :                   g = gimple_build_assign (res, PLUS_EXPR, in,
    5792              :                                            build_int_cst (integer_type_node,
    5793          100 :                                                           limb_prec));
    5794          100 :                   insert_before (g);
    5795          100 :                   m_data[m_data_cnt] = res;
    5796              :                 }
    5797              :               break;
    5798           43 :             case IFN_PARITY:
    5799           43 :               if (!integer_zerop (in))
    5800              :                 {
    5801           37 :                   if (kind == bitint_prec_huge && i == 1)
    5802           10 :                     res = out;
    5803              :                   else
    5804           27 :                     res = make_ssa_name (m_limb_type);
    5805           37 :                   g = gimple_build_assign (res, BIT_XOR_EXPR, in, rhs1);
    5806           37 :                   insert_before (g);
    5807              :                 }
    5808              :               else
    5809              :                 res = rhs1;
    5810           43 :               m_data[m_data_cnt] = res;
    5811           43 :               break;
    5812           31 :             case IFN_POPCOUNT:
    5813           31 :               g = gimple_build_call (fndecl, 1, rhs1);
    5814           31 :               tem = make_ssa_name (integer_type_node);
    5815           31 :               gimple_call_set_lhs (g, tem);
    5816           31 :               insert_before (g);
    5817           31 :               if (!integer_zerop (in))
    5818              :                 {
    5819           26 :                   if (kind == bitint_prec_huge && i == 1)
    5820            6 :                     res = out;
    5821              :                   else
    5822           20 :                     res = make_ssa_name (integer_type_node);
    5823           26 :                   g = gimple_build_assign (res, PLUS_EXPR, in, tem);
    5824           26 :                   insert_before (g);
    5825              :                 }
    5826              :               else
    5827              :                 res = tem;
    5828           31 :               m_data[m_data_cnt] = res;
    5829           31 :               break;
    5830            0 :             default:
    5831            0 :               gcc_unreachable ();
    5832              :             }
    5833              : 
    5834          232 :           m_first = false;
    5835          232 :           if (kind == bitint_prec_huge && i <= 1)
    5836              :             {
    5837          132 :               if (i == 0)
    5838              :                 {
    5839           66 :                   idx = make_ssa_name (sizetype);
    5840           66 :                   g = gimple_build_assign (idx, PLUS_EXPR, idx_first,
    5841              :                                            bitint_big_endian
    5842            0 :                                            ? size_int (-1) : size_one_node);
    5843           66 :                   insert_before (g);
    5844              :                 }
    5845              :               else
    5846              :                 {
    5847           66 :                   g = gimple_build_assign (idx_next, PLUS_EXPR, idx_first,
    5848          132 :                                            size_int (bitint_big_endian
    5849              :                                                      ? -2 : 2));
    5850           66 :                   insert_before (g);
    5851           66 :                   if (bitint_big_endian)
    5852            0 :                     g = gimple_build_cond (NE_EXPR, idx_first,
    5853            0 :                                            size_int (cnt - 1),
    5854              :                                            NULL_TREE, NULL_TREE);
    5855              :                   else
    5856           66 :                     g = gimple_build_cond (NE_EXPR, idx_next, size_int (end),
    5857              :                                            NULL_TREE, NULL_TREE);
    5858           66 :                   insert_before (g);
    5859           66 :                   if (ifn == IFN_CTZ || ifn == IFN_FFS)
    5860           50 :                     m_gsi = gsi_after_labels (edge_bb);
    5861              :                   else
    5862           16 :                     m_gsi = gsi_for_stmt (stmt);
    5863           66 :                   m_bb = NULL;
    5864              :                 }
    5865              :             }
    5866              :         }
    5867              :     }
    5868              :   else
    5869              :     {
    5870           63 :       tree idx = NULL_TREE, idx_next = NULL_TREE, first = NULL_TREE;
    5871           63 :       int sub_one = 0;
    5872           63 :       if (kind == bitint_prec_large)
    5873              :         cnt = nelts;
    5874              :       else
    5875              :         {
    5876           45 :           rem = prec % limb_prec;
    5877           45 :           if (rem == 0 && (!TYPE_UNSIGNED (type) || ifn == IFN_CLRSB))
    5878              :             rem = limb_prec;
    5879           45 :           end = (prec - rem) / limb_prec;
    5880           45 :           cnt = 1 + (rem != 0);
    5881           45 :           if (ifn == IFN_CLRSB)
    5882            5 :             sub_one = 1;
    5883              :         }
    5884              : 
    5885           63 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    5886           63 :       gsi_prev (&gsi);
    5887           63 :       edge e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    5888           63 :       edge_bb = e->src;
    5889           63 :       m_gsi = gsi_end_bb (edge_bb);
    5890              : 
    5891           63 :       if (ifn == IFN_CLZ)
    5892           54 :         bqp = XALLOCAVEC (struct bq_details, cnt);
    5893              :       else
    5894              :         {
    5895            9 :           gsi = gsi_for_stmt (stmt);
    5896            9 :           gsi_prev (&gsi);
    5897            9 :           e = split_block (gsi_bb (gsi), gsi_stmt (gsi));
    5898            9 :           edge_bb = e->src;
    5899            9 :           bqp = XALLOCAVEC (struct bq_details, 2 * cnt);
    5900              :         }
    5901              : 
    5902          175 :       for (unsigned i = 0; i < cnt; i++)
    5903              :         {
    5904          112 :           m_data_cnt = 0;
    5905          112 :           if (kind == bitint_prec_large)
    5906           55 :             idx = size_int (bitint_big_endian ? i : cnt - i - 1);
    5907           57 :           else if (i == cnt - 1)
    5908           45 :             idx = create_loop (size_int (bitint_big_endian ? i : end - 1),
    5909              :                                &idx_next);
    5910              :           else
    5911           12 :             idx = bitint_big_endian ? size_zero_node : size_int (end);
    5912              : 
    5913          112 :           tree rhs1 = handle_operand (arg0, idx);
    5914          112 :           if (!useless_type_conversion_p (m_limb_type, TREE_TYPE (rhs1)))
    5915              :             {
    5916           20 :               if (ifn == IFN_CLZ && !TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    5917            0 :                 rhs1 = add_cast (unsigned_type_for (TREE_TYPE (rhs1)), rhs1);
    5918           20 :               else if (ifn == IFN_CLRSB && TYPE_UNSIGNED (TREE_TYPE (rhs1)))
    5919            0 :                 rhs1 = add_cast (signed_type_for (TREE_TYPE (rhs1)), rhs1);
    5920           20 :               rhs1 = add_cast (m_limb_type, rhs1);
    5921              :             }
    5922              : 
    5923          112 :           if (ifn == IFN_CLZ)
    5924              :             {
    5925           90 :               g = gimple_build_cond (NE_EXPR, rhs1,
    5926              :                                      build_zero_cst (m_limb_type),
    5927              :                                      NULL_TREE, NULL_TREE);
    5928           90 :               insert_before (g);
    5929           90 :               edge e1 = split_block (gsi_bb (m_gsi), g);
    5930           90 :               e1->flags = EDGE_FALSE_VALUE;
    5931           90 :               edge e2 = make_edge (e1->src, gimple_bb (stmt), EDGE_TRUE_VALUE);
    5932           90 :               e1->probability = profile_probability::unlikely ();
    5933           90 :               e2->probability = e1->probability.invert ();
    5934           90 :               if (i == 0)
    5935           54 :                 set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    5936           90 :               m_gsi = gsi_after_labels (e1->dest);
    5937           90 :               bqp[i].e = e2;
    5938           90 :               bqp[i].val = rhs1;
    5939              :             }
    5940              :           else
    5941              :             {
    5942           22 :               if (i == 0)
    5943              :                 {
    5944            9 :                   first = rhs1;
    5945            9 :                   gassign *a = gimple_build_assign (make_ssa_name (m_limb_type),
    5946              :                                                     PLUS_EXPR, rhs1,
    5947              :                                                     build_int_cst (m_limb_type,
    5948              :                                                                    1));
    5949            9 :                   insert_before (a);
    5950            9 :                   g = gimple_build_cond (GT_EXPR, gimple_assign_lhs (a),
    5951              :                                          build_int_cst (m_limb_type, 1),
    5952              :                                          NULL_TREE, NULL_TREE);
    5953            9 :                   insert_before (g);
    5954              :                 }
    5955              :               else
    5956              :                 {
    5957           13 :                   gassign *a = gimple_build_assign (make_ssa_name (m_limb_type),
    5958              :                                                     BIT_XOR_EXPR, rhs1, first);
    5959           13 :                   insert_before (a);
    5960           13 :                   tree stype = signed_type_for (m_limb_type);
    5961           13 :                   g = gimple_build_cond (LT_EXPR,
    5962              :                                          add_cast (stype,
    5963              :                                                    gimple_assign_lhs (a)),
    5964              :                                          build_zero_cst (stype),
    5965              :                                          NULL_TREE, NULL_TREE);
    5966           13 :                   insert_before (g);
    5967           13 :                   edge e1 = split_block (gsi_bb (m_gsi), g);
    5968           13 :                   e1->flags = EDGE_FALSE_VALUE;
    5969           13 :                   edge e2 = make_edge (e1->src, gimple_bb (stmt),
    5970              :                                        EDGE_TRUE_VALUE);
    5971           13 :                   e1->probability = profile_probability::unlikely ();
    5972           13 :                   e2->probability = e1->probability.invert ();
    5973           13 :                   if (i == 1)
    5974            9 :                     set_immediate_dominator (CDI_DOMINATORS, e2->dest,
    5975              :                                              e2->src);
    5976           13 :                   m_gsi = gsi_after_labels (e1->dest);
    5977           13 :                   bqp[2 * i].e = e2;
    5978           13 :                   g = gimple_build_cond (NE_EXPR, rhs1, first,
    5979              :                                          NULL_TREE, NULL_TREE);
    5980           13 :                   insert_before (g);
    5981              :                 }
    5982           22 :               edge e1 = split_block (gsi_bb (m_gsi), g);
    5983           22 :               e1->flags = EDGE_FALSE_VALUE;
    5984           22 :               edge e2 = make_edge (e1->src, edge_bb, EDGE_TRUE_VALUE);
    5985           22 :               e1->probability = profile_probability::unlikely ();
    5986           22 :               e2->probability = e1->probability.invert ();
    5987           22 :               if (i == 0)
    5988            9 :                 set_immediate_dominator (CDI_DOMINATORS, e2->dest, e2->src);
    5989           22 :               m_gsi = gsi_after_labels (e1->dest);
    5990           22 :               bqp[2 * i + 1].e = e2;
    5991           22 :               bqp[i].val = rhs1;
    5992              :             }
    5993          112 :           if (tree_fits_uhwi_p (idx))
    5994          134 :             bqp[i].addend
    5995           67 :               = build_int_cst (integer_type_node,
    5996           67 :                                (int) prec
    5997           67 :                                - (((int) (bitint_big_endian
    5998            0 :                                           ? nelts - 1 - tree_to_uhwi (idx)
    5999           67 :                                           : tree_to_uhwi (idx)) + 1)
    6000           67 :                                   * limb_prec) - sub_one);
    6001              :           else
    6002              :             {
    6003           45 :               tree in, out;
    6004           45 :               in = build_int_cst (integer_type_node, rem - sub_one);
    6005           45 :               m_first = true;
    6006           45 :               in = prepare_data_in_out (in, idx, &out);
    6007           45 :               out = m_data[m_data_cnt + 1];
    6008           45 :               bqp[i].addend = in;
    6009           45 :               g = gimple_build_assign (out, PLUS_EXPR, in,
    6010              :                                        build_int_cst (integer_type_node,
    6011           45 :                                                       limb_prec));
    6012           45 :               insert_before (g);
    6013           45 :               m_data[m_data_cnt] = out;
    6014              :             }
    6015              : 
    6016          112 :           m_first = false;
    6017          112 :           if (kind == bitint_prec_huge && i == cnt - 1)
    6018              :             {
    6019           90 :               g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    6020              :                                        bitint_big_endian
    6021           45 :                                        ? size_one_node : size_int (-1));
    6022           45 :               insert_before (g);
    6023           45 :               g = gimple_build_cond (NE_EXPR, idx,
    6024              :                                      bitint_big_endian
    6025            0 :                                      ? size_int (nelts - 1) : size_zero_node,
    6026              :                                      NULL_TREE, NULL_TREE);
    6027           45 :               insert_before (g);
    6028           45 :               edge true_edge, false_edge;
    6029           45 :               extract_true_false_edges_from_block (gsi_bb (m_gsi),
    6030              :                                                    &true_edge, &false_edge);
    6031           45 :               m_gsi = gsi_after_labels (false_edge->dest);
    6032           45 :               m_bb = NULL;
    6033              :             }
    6034              :         }
    6035              :     }
    6036          156 :   switch (ifn)
    6037              :     {
    6038          120 :     case IFN_CLZ:
    6039          120 :     case IFN_CTZ:
    6040          120 :     case IFN_FFS:
    6041          120 :       gphi *phi1, *phi2, *phi3;
    6042          120 :       basic_block bb;
    6043          120 :       bb = gsi_bb (m_gsi);
    6044          120 :       remove_edge (find_edge (bb, gimple_bb (stmt)));
    6045          120 :       phi1 = create_phi_node (make_ssa_name (m_limb_type),
    6046              :                               gimple_bb (stmt));
    6047          120 :       phi2 = create_phi_node (make_ssa_name (integer_type_node),
    6048              :                               gimple_bb (stmt));
    6049          488 :       for (unsigned i = 0; i < cnt; i++)
    6050              :         {
    6051          248 :           add_phi_arg (phi1, bqp[i].val, bqp[i].e, UNKNOWN_LOCATION);
    6052          248 :           add_phi_arg (phi2, bqp[i].addend, bqp[i].e, UNKNOWN_LOCATION);
    6053              :         }
    6054          120 :       if (arg1 == NULL_TREE)
    6055              :         {
    6056           90 :           g = gimple_build_builtin_unreachable (m_loc);
    6057           90 :           insert_before (g);
    6058           90 :           if (bb->loop_father->num)
    6059              :             {
    6060           19 :               remove_bb_from_loops (bb);
    6061           19 :               add_bb_to_loop (bb, get_loop (cfun, 0));
    6062              :             }
    6063              :         }
    6064          120 :       m_gsi = gsi_for_stmt (stmt);
    6065          120 :       g = gimple_build_call (fndecl, 1, gimple_phi_result (phi1));
    6066          120 :       gimple_call_set_lhs (g, make_ssa_name (integer_type_node));
    6067          120 :       insert_before (g);
    6068          120 :       if (arg1 == NULL_TREE)
    6069           90 :         g = gimple_build_assign (lhs, PLUS_EXPR,
    6070              :                                  gimple_phi_result (phi2),
    6071              :                                  gimple_call_lhs (g));
    6072              :       else
    6073              :         {
    6074           30 :           gassign *a = gimple_build_assign (make_ssa_name (integer_type_node),
    6075              :                                             PLUS_EXPR, gimple_phi_result (phi2),
    6076              :                                             gimple_call_lhs (g));
    6077           30 :           insert_before (a);
    6078           30 :           edge e1 = split_block (gimple_bb (stmt), a);
    6079           30 :           edge e2 = make_edge (bb, e1->dest, EDGE_FALLTHRU);
    6080           30 :           e2->probability = profile_probability::always ();
    6081           30 :           set_immediate_dominator (CDI_DOMINATORS, e1->dest,
    6082              :                                    get_immediate_dominator (CDI_DOMINATORS,
    6083              :                                                             e1->src));
    6084           30 :           phi3 = create_phi_node (make_ssa_name (integer_type_node), e1->dest);
    6085           30 :           add_phi_arg (phi3, gimple_assign_lhs (a), e1, UNKNOWN_LOCATION);
    6086           30 :           add_phi_arg (phi3, arg1, e2, UNKNOWN_LOCATION);
    6087           30 :           m_gsi = gsi_for_stmt (stmt);
    6088           30 :           g = gimple_build_assign (lhs, gimple_phi_result (phi3));
    6089              :         }
    6090          120 :       gsi_replace (&m_gsi, g, true);
    6091          120 :       break;
    6092            9 :     case IFN_CLRSB:
    6093            9 :       bb = gsi_bb (m_gsi);
    6094            9 :       remove_edge (find_edge (bb, edge_bb));
    6095            9 :       edge e;
    6096            9 :       e = make_edge (bb, gimple_bb (stmt), EDGE_FALLTHRU);
    6097            9 :       e->probability = profile_probability::always ();
    6098            9 :       set_immediate_dominator (CDI_DOMINATORS, gimple_bb (stmt),
    6099              :                                get_immediate_dominator (CDI_DOMINATORS,
    6100              :                                                         edge_bb));
    6101            9 :       phi1 = create_phi_node (make_ssa_name (m_limb_type),
    6102              :                               edge_bb);
    6103            9 :       phi2 = create_phi_node (make_ssa_name (integer_type_node),
    6104              :                               edge_bb);
    6105            9 :       phi3 = create_phi_node (make_ssa_name (integer_type_node),
    6106              :                               gimple_bb (stmt));
    6107           40 :       for (unsigned i = 0; i < cnt; i++)
    6108              :         {
    6109           22 :           add_phi_arg (phi1, bqp[i].val, bqp[2 * i + 1].e, UNKNOWN_LOCATION);
    6110           22 :           add_phi_arg (phi2, bqp[i].addend, bqp[2 * i + 1].e,
    6111              :                        UNKNOWN_LOCATION);
    6112           22 :           tree a = bqp[i].addend;
    6113           22 :           if (i && kind == bitint_prec_large)
    6114            8 :             a = int_const_binop (PLUS_EXPR, a, integer_minus_one_node);
    6115           22 :           if (i)
    6116           13 :             add_phi_arg (phi3, a, bqp[2 * i].e, UNKNOWN_LOCATION);
    6117              :         }
    6118            9 :       add_phi_arg (phi3, build_int_cst (integer_type_node, prec - 1), e,
    6119              :                    UNKNOWN_LOCATION);
    6120            9 :       m_gsi = gsi_after_labels (edge_bb);
    6121            9 :       g = gimple_build_call (fndecl, 1,
    6122              :                              add_cast (signed_type_for (m_limb_type),
    6123              :                                        gimple_phi_result (phi1)));
    6124            9 :       gimple_call_set_lhs (g, make_ssa_name (integer_type_node));
    6125            9 :       insert_before (g);
    6126            9 :       gassign *a;
    6127            9 :       a = gimple_build_assign (make_ssa_name (integer_type_node),
    6128              :                                PLUS_EXPR, gimple_call_lhs (g),
    6129              :                                gimple_phi_result (phi2));
    6130            9 :       insert_before (a);
    6131            9 :       if (kind != bitint_prec_large)
    6132              :         {
    6133            5 :           a = gimple_build_assign (make_ssa_name (integer_type_node),
    6134              :                                    PLUS_EXPR, gimple_assign_lhs (a),
    6135              :                                    integer_one_node);
    6136            5 :           insert_before (a);
    6137              :         }
    6138            9 :       add_phi_arg (phi3, gimple_assign_lhs (a),
    6139              :                    find_edge (edge_bb, gimple_bb (stmt)), UNKNOWN_LOCATION);
    6140            9 :       m_gsi = gsi_for_stmt (stmt);
    6141            9 :       g = gimple_build_assign (lhs, gimple_phi_result (phi3));
    6142            9 :       gsi_replace (&m_gsi, g, true);
    6143            9 :       break;
    6144           16 :     case IFN_PARITY:
    6145           16 :       g = gimple_build_call (fndecl, 1, res);
    6146           16 :       gimple_call_set_lhs (g, lhs);
    6147           16 :       gsi_replace (&m_gsi, g, true);
    6148           16 :       break;
    6149           11 :     case IFN_POPCOUNT:
    6150           11 :       g = gimple_build_assign (lhs, res);
    6151           11 :       gsi_replace (&m_gsi, g, true);
    6152           11 :       break;
    6153            0 :     default:
    6154            0 :       gcc_unreachable ();
    6155              :     }
    6156              : }
    6157              : 
    6158              : /* Lower a .{BSWAP,BITREVERSE} call with one large/huge _BitInt argument.  */
    6159              : 
    6160              : void
    6161           47 : bitint_large_huge::lower_bswap_bitreverse (tree obj, gimple *stmt)
    6162              : {
    6163           47 :   tree arg = gimple_call_arg (stmt, 0);
    6164           47 :   tree lhs = gimple_call_lhs (stmt);
    6165           47 :   gimple *g;
    6166              : 
    6167           47 :   if (!lhs)
    6168              :     {
    6169            0 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    6170            0 :       gsi_remove (&gsi, true);
    6171            0 :       return;
    6172              :     }
    6173           47 :   tree type = TREE_TYPE (arg);
    6174           47 :   gcc_assert (BITINT_TYPE_P (type));
    6175           47 :   bitint_prec_kind kind = bitint_precision_kind (type);
    6176           47 :   gcc_assert (kind >= bitint_prec_large);
    6177           47 :   if (!obj)
    6178              :     {
    6179           34 :       int part = var_to_partition (m_map, lhs);
    6180           34 :       gcc_assert (m_vars[part] != NULL_TREE);
    6181              :       obj = m_vars[part];
    6182              :     }
    6183           47 :   enum internal_fn ifn = gimple_call_internal_fn (stmt);
    6184           47 :   enum built_in_function bcode = END_BUILTINS;
    6185           47 :   switch (limb_prec)
    6186              :     {
    6187            0 :     case 16:
    6188            0 :       bcode = ifn == IFN_BSWAP ? BUILT_IN_BSWAP16 : BUILT_IN_BITREVERSE16;
    6189              :       break;
    6190            0 :     case 32:
    6191            0 :       bcode = ifn == IFN_BSWAP ? BUILT_IN_BSWAP32 : BUILT_IN_BITREVERSE32;
    6192              :       break;
    6193           47 :     case 64:
    6194           47 :       bcode = ifn == IFN_BSWAP ? BUILT_IN_BSWAP64 : BUILT_IN_BITREVERSE64;
    6195              :       break;
    6196            0 :     case 128:
    6197            0 :       bcode = ifn == IFN_BSWAP ? BUILT_IN_BSWAP128 : BUILT_IN_BITREVERSE128;
    6198              :       break;
    6199            0 :     default:
    6200            0 :       gcc_unreachable ();
    6201              :     }
    6202           47 :   tree fndecl = builtin_decl_explicit (bcode);
    6203           47 :   unsigned prec = TYPE_PRECISION (type);
    6204           94 :   tree p = build_int_cst (sizetype,
    6205           47 :                           prec / limb_prec - (prec % limb_prec == 0));
    6206              :   /* For .BSWAP/.BITREVERSE, we can use handle_operand with non-INTEGER_CST
    6207              :      idx even to access the most significant partial limb.  */
    6208           47 :   m_var_msb = true;
    6209              :   /* For IFN .BSWAP or .BITREVERSE and
    6210              :      FN corresponding __builtin_bswapN or __builtin_bitreverseN where N
    6211              :      is limb_prec, lower
    6212              :        dst = IFN (src);
    6213              :      as
    6214              :        size_t p = prec / limb_prec - (prec % limb_prec == 0);
    6215              :        if constexpr ((prec % limb_prec) == 0)
    6216              :          {
    6217              :            for (idx = 0; idx <= p; ++idx)
    6218              :              dst[p - idx] = FN (src[idx]);
    6219              :          }
    6220              :        else
    6221              :          {
    6222              :            unsigned n1 = prec % limb_prec;
    6223              :            unsigned n2 = limb_prec - n1;
    6224              :            dst[p] = FN (src[0]) >> n2;
    6225              :            for (idx = p - 1; (ssize_t) idx >= 0; --idx)
    6226              :              dst[idx] = FN ((src[p - idx] << n2) | (src[p - idx - 1] >> n1));
    6227              :          }  */
    6228           47 :   if (prec % limb_prec == 0)
    6229              :     {
    6230            9 :       tree idx_next;
    6231            9 :       tree idx = create_loop (size_zero_node, &idx_next);
    6232            9 :       tree pmidx = make_ssa_name (sizetype);
    6233            9 :       g = gimple_build_assign (pmidx, MINUS_EXPR, p, idx);
    6234            9 :       insert_before (g);
    6235            9 :       m_data_cnt = 0;
    6236            9 :       tree t = handle_operand (arg, idx);
    6237            9 :       m_first = false;
    6238            9 :       g = gimple_build_call (fndecl, 1, t);
    6239            9 :       t = make_ssa_name (m_limb_type);
    6240            9 :       gimple_call_set_lhs (g, t);
    6241            9 :       insert_before (g);
    6242            9 :       tree l = limb_access (TREE_TYPE (lhs), obj, pmidx, true);
    6243            9 :       g = gimple_build_assign (l, t);
    6244            9 :       insert_before (g);
    6245            9 :       g = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_one_node);
    6246            9 :       insert_before (g);
    6247            9 :       g = gimple_build_cond (LE_EXPR, idx_next, p, NULL_TREE, NULL_TREE);
    6248            9 :       insert_before (g);
    6249              :     }
    6250              :   else
    6251              :     {
    6252           38 :       tree n1 = build_int_cst (unsigned_type_node, prec % limb_prec);
    6253           76 :       tree n2 = build_int_cst (unsigned_type_node,
    6254           38 :                                limb_prec - (prec % limb_prec));
    6255           38 :       m_data_cnt = 0;
    6256           38 :       tree t = handle_operand (arg, bitint_big_endian ? p : size_zero_node);
    6257           38 :       gassign *a;
    6258           38 :       m_first = false;
    6259              :       /* Nothing is needed to bswap 8 bits or bitreverse 1 bit, so just
    6260              :          mask off higher bits in that case.  */
    6261           71 :       if ((prec % limb_prec) != (ifn == IFN_BSWAP ? 8 : 1))
    6262              :         {
    6263           26 :           g = gimple_build_call (fndecl, 1, t);
    6264           26 :           t = make_ssa_name (m_limb_type);
    6265           26 :           gimple_call_set_lhs (g, t);
    6266           26 :           insert_before (g);
    6267           26 :           a = gimple_build_assign (make_ssa_name (m_limb_type), RSHIFT_EXPR,
    6268              :                                    t, n2);
    6269              :         }
    6270              :       else
    6271           12 :         a = gimple_build_assign (make_ssa_name (m_limb_type), BIT_AND_EXPR,
    6272              :                                  t, build_int_cst (m_limb_type,
    6273              :                                                    ifn == IFN_BSWAP
    6274           22 :                                                    ? 0xff : 1));
    6275           38 :       insert_before (a);
    6276           38 :       t = gimple_assign_lhs (a);
    6277           38 :       tree l = limb_access (TREE_TYPE (lhs), obj,
    6278              :                             bitint_big_endian ? size_zero_node : p, true);
    6279           38 :       a = gimple_build_assign (l, t);
    6280           38 :       insert_before (a);
    6281           38 :       tree pm1 = build_int_cst (sizetype, prec / limb_prec - 1);
    6282           38 :       tree idx_next;
    6283           38 :       tree idx = create_loop (pm1, &idx_next);
    6284           38 :       tree pmidx = make_ssa_name (sizetype);
    6285           38 :       a = gimple_build_assign (pmidx, MINUS_EXPR, p, idx);
    6286           38 :       insert_before (a);
    6287           38 :       m_data_cnt = 0;
    6288           76 :       t = handle_operand (arg, bitint_big_endian ? idx : pmidx);
    6289           38 :       m_data_cnt = 0;
    6290           38 :       a = gimple_build_assign (make_ssa_name (m_limb_type), LSHIFT_EXPR,
    6291              :                                t, n2);
    6292           38 :       insert_before (a);
    6293           38 :       t = gimple_assign_lhs (a);
    6294           38 :       tree t2 = make_ssa_name (sizetype);
    6295           38 :       if (bitint_big_endian)
    6296            0 :         a = gimple_build_assign (t2, PLUS_EXPR, idx, size_one_node);
    6297              :       else
    6298           38 :         a = gimple_build_assign (t2, PLUS_EXPR, pmidx, size_int (-1));
    6299           38 :       insert_before (a);
    6300           38 :       t2 = handle_operand (arg, t2);
    6301           38 :       a = gimple_build_assign (make_ssa_name (m_limb_type), RSHIFT_EXPR,
    6302              :                                t2, n1);
    6303           38 :       insert_before (a);
    6304           38 :       t2 = gimple_assign_lhs (a);
    6305           38 :       a = gimple_build_assign (make_ssa_name (m_limb_type), BIT_IOR_EXPR,
    6306              :                                t, t2);
    6307           38 :       insert_before (a);
    6308           38 :       t = gimple_assign_lhs (a);
    6309           38 :       g = gimple_build_call (fndecl, 1, t);
    6310           38 :       t = make_ssa_name (m_limb_type);
    6311           38 :       gimple_call_set_lhs (g, t);
    6312           38 :       insert_before (g);
    6313           76 :       l = limb_access (TREE_TYPE (lhs), obj,
    6314              :                        bitint_big_endian ? pmidx : idx, true);
    6315           38 :       a = gimple_build_assign (l, t);
    6316           38 :       insert_before (a);
    6317           38 :       a = gimple_build_assign (idx_next, PLUS_EXPR, idx, size_int (-1));
    6318           38 :       insert_before (a);
    6319           38 :       g = gimple_build_cond (NE_EXPR, idx, size_zero_node, NULL_TREE,
    6320              :                              NULL_TREE);
    6321           38 :       insert_before (g);
    6322              :     }
    6323           47 :   gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    6324           47 :   if (bitint_extended == bitint_ext_full
    6325            0 :       && abi_limb_prec > limb_prec
    6326            0 :       && (CEIL (prec, abi_limb_prec) * abi_limb_prec
    6327            0 :           > CEIL (prec, limb_prec) * limb_prec))
    6328              :     {
    6329            0 :       m_gsi = gsi;
    6330            0 :       tree p2 = build_int_cst (sizetype,
    6331              :                                CEIL (prec, abi_limb_prec)
    6332            0 :                                * abi_limb_prec / limb_prec - 1);
    6333            0 :       tree l = limb_access (TREE_TYPE (lhs), obj, p2, true);
    6334            0 :       g = gimple_build_assign (l, build_zero_cst (m_limb_type));
    6335            0 :       insert_before (g);
    6336              :     }
    6337              : }
    6338              : 
    6339              : /* Lower a .CLMUL call with two large/huge _BitInt arguments.  */
    6340              : 
    6341              : void
    6342           30 : bitint_large_huge::lower_clmul (tree obj, gimple *stmt)
    6343              : {
    6344           30 :   tree arg1 = gimple_call_arg (stmt, 0);
    6345           30 :   tree arg2 = gimple_call_arg (stmt, 1);
    6346           30 :   tree lhs = gimple_call_lhs (stmt);
    6347           30 :   gimple *g;
    6348              : 
    6349           30 :   if (!lhs)
    6350              :     {
    6351            0 :       gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    6352            0 :       gsi_remove (&gsi, true);
    6353            0 :       return;
    6354              :     }
    6355           60 :   if (wi::popcount (get_nonzero_bits (arg1))
    6356           48 :       < wi::popcount (get_nonzero_bits (arg2)))
    6357            0 :     std::swap (arg1, arg2);
    6358           30 :   tree type = TREE_TYPE (arg1);
    6359           30 :   gcc_assert (BITINT_TYPE_P (type));
    6360           30 :   bitint_prec_kind kind = bitint_precision_kind (type);
    6361           30 :   gcc_assert (kind >= bitint_prec_large);
    6362           30 :   if (!obj)
    6363              :     {
    6364           20 :       int part = var_to_partition (m_map, lhs);
    6365           20 :       gcc_assert (m_vars[part] != NULL_TREE);
    6366              :       obj = m_vars[part];
    6367              :     }
    6368              :   /* For .CLMUL, we can use handle_operand with non-INTEGER_CST
    6369              :      idx even to access the most significant partial limb.  */
    6370           30 :   m_var_msb = true;
    6371           30 :   unsigned prec = TYPE_PRECISION (type);
    6372              :   /* Lower
    6373              :        dst = .CLMUL (src1, src2);
    6374              :      as
    6375              :        size_t p = prec / limb_prec - (prec % limb_prec == 0);
    6376              :        dst = {};
    6377              :        for (idx = 0; idx <= p; ++idx)
    6378              :          {
    6379              :            limb_type t = src2[idx];
    6380              :            size_t i = 0, j = 0;
    6381              :            do
    6382              :              {
    6383              :                if (t & 1)
    6384              :                  {
    6385              :                    size_t idx3 = idx + j;
    6386              :                    size_t k = -i & (limb_prec - 1);
    6387              :                    r[idx] ^= (src1[0] << i);
    6388              :                    for (idx2 = idx + 1; idx2 <= p; ++idx2)
    6389              :                      r[idx2] ^= (src1[idx2 - idx] << i)
    6390              :                                 | (src1[idx2 - idx3] >> k);
    6391              :                  }
    6392              :                t >>= 1;
    6393              :                ++i;
    6394              :                j = 1;
    6395              :              }
    6396              :            while (t);
    6397              :          }  */
    6398           60 :   tree p = build_int_cst (sizetype,
    6399           30 :                           prec / limb_prec - (prec % limb_prec == 0));
    6400           30 :   tree zero = build_zero_cst (TREE_TYPE (obj));
    6401           30 :   g = gimple_build_assign (obj, zero);
    6402           30 :   insert_before (g);
    6403           30 :   tree idx_next;
    6404           30 :   tree idx = create_loop (bitint_big_endian ? p : size_zero_node, &idx_next);
    6405           30 :   m_data_cnt = 0;
    6406           30 :   tree t_init = handle_operand (arg2, idx);
    6407           30 :   m_first = false;
    6408           30 :   tree i_next;
    6409           30 :   tree i = create_loop (size_zero_node, &i_next);
    6410           30 :   tree j = make_ssa_name (sizetype);
    6411           30 :   gphi *phi = create_phi_node (j, m_bb);
    6412           30 :   add_phi_arg (phi, size_zero_node, find_edge (m_preheader_bb, m_bb),
    6413              :                UNKNOWN_LOCATION);
    6414           30 :   add_phi_arg (phi, size_one_node, find_edge (m_bb, m_bb), UNKNOWN_LOCATION);
    6415           30 :   tree t = make_ssa_name (m_limb_type);
    6416           30 :   phi = create_phi_node (t, m_bb);
    6417           30 :   add_phi_arg (phi, t_init, find_edge (m_preheader_bb, m_bb),
    6418              :                UNKNOWN_LOCATION);
    6419           30 :   tree t_next = make_ssa_name (m_limb_type);
    6420           30 :   add_phi_arg (phi, t_next, find_edge (m_bb, m_bb), UNKNOWN_LOCATION);
    6421           30 :   tree t1 = make_ssa_name (m_limb_type);
    6422           30 :   g = gimple_build_assign (t1, BIT_AND_EXPR, t, build_one_cst (m_limb_type));
    6423           30 :   insert_before (g);
    6424           30 :   g = gimple_build_cond (NE_EXPR, t1, build_zero_cst (m_limb_type),
    6425              :                          NULL_TREE, NULL_TREE);
    6426           30 :   edge edge_true, edge_false;
    6427           30 :   if_then (g, profile_probability::even (), edge_true, edge_false);
    6428           30 :   tree idx3 = make_ssa_name (sizetype), idx4 = idx;
    6429           60 :   g = gimple_build_assign (idx3, bitint_big_endian ? MINUS_EXPR : PLUS_EXPR,
    6430              :                            idx, j);
    6431           30 :   insert_before (g);
    6432           30 :   if (bitint_big_endian)
    6433              :     {
    6434            0 :       g = gimple_build_assign (make_ssa_name (sizetype), MINUS_EXPR, idx3, p);
    6435            0 :       insert_before (g);
    6436            0 :       idx3 = gimple_assign_lhs (g);
    6437            0 :       idx4 = make_ssa_name (sizetype);
    6438            0 :       g = gimple_build_assign (idx4, MINUS_EXPR, idx, p);
    6439            0 :       insert_before (g);
    6440              :     }
    6441           30 :   g = gimple_build_assign (make_ssa_name (sizetype), NEGATE_EXPR, i);
    6442           30 :   insert_before (g);
    6443           30 :   tree k = make_ssa_name (sizetype);
    6444           30 :   g = gimple_build_assign (k, BIT_AND_EXPR, gimple_assign_lhs (g),
    6445           30 :                            size_int (limb_prec - 1));
    6446           30 :   insert_before (g);
    6447           30 :   unsigned data_cnt = m_data_cnt;
    6448           30 :   m_first = true;
    6449           30 :   tree s1 = handle_operand (arg1, bitint_big_endian ? p : size_zero_node);
    6450           30 :   m_first = false;
    6451           30 :   m_data_cnt = data_cnt;
    6452           30 :   g = gimple_build_assign (make_ssa_name (m_limb_type), LSHIFT_EXPR, s1, i);
    6453           30 :   insert_before (g);
    6454           30 :   s1 = gimple_assign_lhs (g);
    6455           30 :   tree r = limb_access (TREE_TYPE (lhs), obj, idx, false);
    6456           30 :   g = gimple_build_assign (make_ssa_name (m_limb_type), r);
    6457           30 :   insert_before (g);
    6458           30 :   g = gimple_build_assign (make_ssa_name (m_limb_type), BIT_XOR_EXPR,
    6459              :                            gimple_assign_lhs (g), s1);
    6460           30 :   insert_before (g);
    6461           30 :   r = limb_access (TREE_TYPE (lhs), obj, idx, true);
    6462           30 :   g = gimple_build_assign (r, gimple_assign_lhs (g));
    6463           30 :   insert_before (g);
    6464           30 :   tree idxp1 = make_ssa_name (sizetype);
    6465           30 :   g = gimple_build_assign (idxp1, PLUS_EXPR, idx,
    6466            0 :                            bitint_big_endian ? size_int (-1) : size_one_node);
    6467           30 :   insert_before (g);
    6468           30 :   if (bitint_big_endian)
    6469            0 :     g = gimple_build_cond (NE_EXPR, idxp1, size_int (-1),
    6470              :                            NULL_TREE, NULL_TREE);
    6471              :   else
    6472           30 :     g = gimple_build_cond (LE_EXPR, idxp1, p, NULL_TREE, NULL_TREE);
    6473           30 :   edge edge_true2, edge_false2;
    6474           30 :   if_then (g, profile_probability::likely (), edge_true2, edge_false2);
    6475           30 :   tree idx2_next;
    6476           30 :   tree idx2 = create_loop (idxp1, &idx2_next);
    6477           30 :   tree idx2midx = make_ssa_name (sizetype);
    6478           30 :   g = gimple_build_assign (idx2midx, MINUS_EXPR, idx2, idx4);
    6479           30 :   insert_before (g);
    6480           30 :   tree idx2midx3 = make_ssa_name (sizetype);
    6481           30 :   g = gimple_build_assign (idx2midx3, MINUS_EXPR, idx2, idx3);
    6482           30 :   insert_before (g);
    6483           30 :   m_data_cnt = data_cnt;
    6484           30 :   tree s2 = handle_operand (arg1, idx2midx);
    6485           30 :   g = gimple_build_assign (make_ssa_name (m_limb_type), LSHIFT_EXPR,
    6486              :                            s2, i);
    6487           30 :   insert_before (g);
    6488           30 :   s2 = gimple_assign_lhs (g);
    6489           30 :   m_data_cnt = data_cnt;
    6490           30 :   tree s3 = handle_operand (arg1, idx2midx3);
    6491           30 :   g = gimple_build_assign (make_ssa_name (m_limb_type), RSHIFT_EXPR,
    6492              :                            s3, k);
    6493           30 :   insert_before (g);
    6494           30 :   g = gimple_build_assign (make_ssa_name (m_limb_type), BIT_IOR_EXPR,
    6495              :                            s2, gimple_assign_lhs (g));
    6496           30 :   insert_before (g);
    6497           30 :   s2 = gimple_assign_lhs (g);
    6498           30 :   r = limb_access (TREE_TYPE (lhs), obj, idx2, false);
    6499           30 :   g = gimple_build_assign (make_ssa_name (m_limb_type), r);
    6500           30 :   insert_before (g);
    6501           30 :   g = gimple_build_assign (make_ssa_name (m_limb_type), BIT_XOR_EXPR,
    6502              :                            gimple_assign_lhs (g), s2);
    6503           30 :   insert_before (g);
    6504           30 :   r = limb_access (TREE_TYPE (lhs), obj, idx2, true);
    6505           30 :   g = gimple_build_assign (r, gimple_assign_lhs (g));
    6506           30 :   insert_before (g);
    6507           30 :   g = gimple_build_assign (idx2_next, PLUS_EXPR, idx2,
    6508            0 :                            bitint_big_endian ? size_int (-1) : size_one_node);
    6509           30 :   insert_before (g);
    6510           30 :   if (bitint_big_endian)
    6511            0 :     g = gimple_build_cond (NE_EXPR, idx2_next, size_int (-1),
    6512              :                            NULL_TREE, NULL_TREE);
    6513              :   else
    6514           30 :     g = gimple_build_cond (LE_EXPR, idx2_next, p, NULL_TREE, NULL_TREE);
    6515           30 :   insert_before (g);
    6516           30 :   m_gsi = gsi_after_labels (edge_false->dest);
    6517           30 :   g = gimple_build_assign (t_next, RSHIFT_EXPR, t, integer_one_node);
    6518           30 :   insert_before (g);
    6519           30 :   g = gimple_build_assign (i_next, PLUS_EXPR, i, size_one_node);
    6520           30 :   insert_before (g);
    6521           30 :   g = gimple_build_cond (NE_EXPR, t_next, build_zero_cst (m_limb_type),
    6522              :                          NULL_TREE, NULL_TREE);
    6523           30 :   insert_before (g);
    6524           30 :   if ((EDGE_SUCC (edge_false->dest, 0)->flags & EDGE_FALSE_VALUE) != 0)
    6525           30 :     m_gsi = gsi_after_labels (EDGE_SUCC (edge_false->dest, 0)->dest);
    6526              :   else
    6527            0 :     m_gsi = gsi_after_labels (EDGE_SUCC (edge_false->dest, 1)->dest);
    6528           30 :   g = gimple_build_assign (idx_next, PLUS_EXPR, idx,
    6529            0 :                            bitint_big_endian ? size_int (-1) : size_one_node);
    6530           30 :   insert_before (g);
    6531           30 :   if (bitint_big_endian)
    6532            0 :     g = gimple_build_cond (NE_EXPR, idx_next, size_int (-1),
    6533              :                            NULL_TREE, NULL_TREE);
    6534              :   else
    6535           30 :     g = gimple_build_cond (LE_EXPR, idx_next, p, NULL_TREE, NULL_TREE);
    6536           30 :   insert_before (g);
    6537           30 :   m_gsi = gsi_for_stmt (stmt);
    6538           30 :   if (bitint_extended && prec % limb_prec != 0)
    6539              :     {
    6540              :       /* The most significant limb has been updated either in the
    6541              :          loop or in the if after it.  To simplify the code, just
    6542              :          read it back from memory and extend.  */
    6543            0 :       idx = bitint_big_endian ? size_zero_node : p;
    6544            0 :       tree l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    6545            0 :       tree type = limb_access_type (TREE_TYPE (lhs), idx);
    6546            0 :       tree v = make_ssa_name (m_limb_type);
    6547            0 :       g = gimple_build_assign (v, l);
    6548            0 :       insert_before (g);
    6549            0 :       v = add_cast (type, v);
    6550            0 :       l = limb_access (TREE_TYPE (lhs), obj, idx, true);
    6551            0 :       v = add_cast (m_limb_type, v);
    6552            0 :       g = gimple_build_assign (l, v);
    6553            0 :       insert_before (g);
    6554              :     }
    6555           30 :   if (bitint_extended == bitint_ext_full
    6556            0 :       && abi_limb_prec > limb_prec
    6557            0 :       && (CEIL (prec, abi_limb_prec) * abi_limb_prec
    6558            0 :           > CEIL (prec, limb_prec) * limb_prec))
    6559              :     {
    6560            0 :       tree p2 = build_int_cst (sizetype,
    6561              :                                CEIL (prec, abi_limb_prec)
    6562            0 :                                * abi_limb_prec / limb_prec - 1);
    6563            0 :       tree l = limb_access (TREE_TYPE (lhs), obj, p2, true);
    6564            0 :       g = gimple_build_assign (l, build_zero_cst (m_limb_type));
    6565            0 :       insert_before (g);
    6566              :     }
    6567              : }
    6568              : 
    6569              : /* Lower a call statement with one or more large/huge _BitInt
    6570              :    arguments or large/huge _BitInt return value.  */
    6571              : 
    6572              : void
    6573         9374 : bitint_large_huge::lower_call (tree obj, gimple *stmt)
    6574              : {
    6575         9374 :   gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    6576         9374 :   unsigned int nargs = gimple_call_num_args (stmt);
    6577         9374 :   if (gimple_call_internal_p (stmt))
    6578         4445 :     switch (gimple_call_internal_fn (stmt))
    6579              :       {
    6580         2733 :       case IFN_ADD_OVERFLOW:
    6581         2733 :       case IFN_SUB_OVERFLOW:
    6582         2733 :       case IFN_UBSAN_CHECK_ADD:
    6583         2733 :       case IFN_UBSAN_CHECK_SUB:
    6584         2733 :         lower_addsub_overflow (obj, stmt);
    6585         7178 :         return;
    6586         1479 :       case IFN_MUL_OVERFLOW:
    6587         1479 :       case IFN_UBSAN_CHECK_MUL:
    6588         1479 :         lower_mul_overflow (obj, stmt);
    6589         1479 :         return;
    6590          156 :       case IFN_CLZ:
    6591          156 :       case IFN_CTZ:
    6592          156 :       case IFN_CLRSB:
    6593          156 :       case IFN_FFS:
    6594          156 :       case IFN_PARITY:
    6595          156 :       case IFN_POPCOUNT:
    6596          156 :         lower_bit_query (stmt);
    6597          156 :         return;
    6598           47 :       case IFN_BSWAP:
    6599           47 :       case IFN_BITREVERSE:
    6600           47 :         lower_bswap_bitreverse (obj, stmt);
    6601           47 :         return;
    6602           30 :       case IFN_CLMUL:
    6603           30 :         lower_clmul (obj, stmt);
    6604           30 :         return;
    6605              :       default:
    6606              :         break;
    6607              :       }
    6608         4929 :   bool returns_twice = (gimple_call_flags (stmt) & ECF_RETURNS_TWICE) != 0;
    6609        11493 :   for (unsigned int i = 0; i < nargs; ++i)
    6610              :     {
    6611         6564 :       tree arg = gimple_call_arg (stmt, i);
    6612        10779 :       if (TREE_CODE (arg) != SSA_NAME
    6613         2446 :           || !BITINT_TYPE_P (TREE_TYPE (arg))
    6614         8948 :           || bitint_precision_kind (TREE_TYPE (arg)) <= bitint_prec_middle)
    6615         4215 :         continue;
    6616         2349 :       if (SSA_NAME_IS_DEFAULT_DEF (arg)
    6617         2349 :           && (!SSA_NAME_VAR (arg) || VAR_P (SSA_NAME_VAR (arg))))
    6618              :         {
    6619            1 :           tree var = create_tmp_reg (TREE_TYPE (arg));
    6620            1 :           arg = get_or_create_ssa_default_def (cfun, var);
    6621              :         }
    6622              :       else
    6623              :         {
    6624         2348 :           int p = var_to_partition (m_map, arg);
    6625         2348 :           tree v = m_vars[p];
    6626         2348 :           gcc_assert (v != NULL_TREE);
    6627         2348 :           if (!types_compatible_p (TREE_TYPE (arg), TREE_TYPE (v)))
    6628         2328 :             v = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (arg), v);
    6629         2348 :           arg = make_ssa_name (TREE_TYPE (arg));
    6630         2348 :           gimple *g = gimple_build_assign (arg, v);
    6631         2348 :           gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    6632         2348 :           if (returns_twice && bb_has_abnormal_pred (gimple_bb (stmt)))
    6633              :             {
    6634           11 :               m_returns_twice_calls.safe_push (stmt);
    6635           11 :               returns_twice = false;
    6636              :             }
    6637              :         }
    6638         2349 :       gimple_call_set_arg (stmt, i, arg);
    6639         2349 :       if (m_preserved == NULL)
    6640          413 :         m_preserved = BITMAP_ALLOC (NULL);
    6641         2349 :       bitmap_set_bit (m_preserved, SSA_NAME_VERSION (arg));
    6642              :     }
    6643         4929 :   tree lhs = gimple_call_lhs (stmt);
    6644         4929 :   if (lhs
    6645         4798 :       && TREE_CODE (lhs) == SSA_NAME
    6646         4798 :       && BITINT_TYPE_P (TREE_TYPE (lhs))
    6647         9649 :       && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large)
    6648              :     {
    6649         4694 :       int p = var_to_partition (m_map, lhs);
    6650         4694 :       tree v = m_vars[p];
    6651         4694 :       gcc_assert (v != NULL_TREE);
    6652         4694 :       if (!types_compatible_p (TREE_TYPE (lhs), TREE_TYPE (v)))
    6653         4694 :         v = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), v);
    6654         4694 :       gimple_call_set_lhs (stmt, v);
    6655         4694 :       SSA_NAME_DEF_STMT (lhs) = gimple_build_nop ();
    6656              :     }
    6657         4929 :   update_stmt (stmt);
    6658              : }
    6659              : 
    6660              : /* Lower __asm STMT which involves large/huge _BitInt values.  */
    6661              : 
    6662              : void
    6663            3 : bitint_large_huge::lower_asm (gimple *stmt)
    6664              : {
    6665            3 :   gasm *g = as_a <gasm *> (stmt);
    6666            3 :   unsigned noutputs = gimple_asm_noutputs (g);
    6667            3 :   unsigned ninputs = gimple_asm_ninputs (g);
    6668              : 
    6669            5 :   for (unsigned i = 0; i < noutputs; ++i)
    6670              :     {
    6671            2 :       tree t = gimple_asm_output_op (g, i);
    6672            2 :       tree s = TREE_VALUE (t);
    6673            2 :       if (TREE_CODE (s) == SSA_NAME
    6674            1 :           && BITINT_TYPE_P (TREE_TYPE (s))
    6675            3 :           && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large)
    6676              :         {
    6677            1 :           int part = var_to_partition (m_map, s);
    6678            1 :           gcc_assert (m_vars[part] != NULL_TREE);
    6679            1 :           TREE_VALUE (t) = m_vars[part];
    6680              :         }
    6681              :     }
    6682            8 :   for (unsigned i = 0; i < ninputs; ++i)
    6683              :     {
    6684            5 :       tree t = gimple_asm_input_op (g, i);
    6685            5 :       tree s = TREE_VALUE (t);
    6686            5 :       if (TREE_CODE (s) == SSA_NAME
    6687            4 :           && BITINT_TYPE_P (TREE_TYPE (s))
    6688            9 :           && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large)
    6689              :         {
    6690            4 :           if (SSA_NAME_IS_DEFAULT_DEF (s)
    6691            4 :               && (!SSA_NAME_VAR (s) || VAR_P (SSA_NAME_VAR (s))))
    6692              :             {
    6693            1 :               TREE_VALUE (t) = create_tmp_var (TREE_TYPE (s), "bitint");
    6694            1 :               mark_addressable (TREE_VALUE (t));
    6695              :             }
    6696              :           else
    6697              :             {
    6698            3 :               int part = var_to_partition (m_map, s);
    6699            3 :               gcc_assert (m_vars[part] != NULL_TREE);
    6700            3 :               TREE_VALUE (t) = m_vars[part];
    6701              :             }
    6702              :         }
    6703              :     }
    6704            3 :   update_stmt (stmt);
    6705            3 : }
    6706              : 
    6707              : /* Lower statement STMT which involves large/huge _BitInt values
    6708              :    into code accessing individual limbs.  */
    6709              : 
    6710              : void
    6711        44977 : bitint_large_huge::lower_stmt (gimple *stmt)
    6712              : {
    6713        44977 :   m_first = true;
    6714        44977 :   m_lhs = NULL_TREE;
    6715        44977 :   m_data.truncate (0);
    6716        44977 :   m_data_cnt = 0;
    6717        44977 :   m_gsi = gsi_for_stmt (stmt);
    6718        44977 :   m_after_stmt = NULL;
    6719        44977 :   m_bb = NULL;
    6720        44977 :   m_init_gsi = m_gsi;
    6721        44977 :   gsi_prev (&m_init_gsi);
    6722        44977 :   m_preheader_bb = NULL;
    6723        44977 :   m_upwards_2limb = 0;
    6724        44977 :   m_upwards = false;
    6725        44977 :   m_var_msb = false;
    6726        44977 :   m_cast_conditional = false;
    6727        44977 :   m_bitfld_load = 0;
    6728        44977 :   m_loc = gimple_location (stmt);
    6729        44977 :   if (is_gimple_call (stmt))
    6730              :     {
    6731         7687 :       lower_call (NULL_TREE, stmt);
    6732         7687 :       return;
    6733              :     }
    6734        37290 :   if (gimple_code (stmt) == GIMPLE_ASM)
    6735              :     {
    6736            3 :       lower_asm (stmt);
    6737            3 :       return;
    6738              :     }
    6739        37287 :   tree lhs = NULL_TREE, cmp_op1 = NULL_TREE, cmp_op2 = NULL_TREE;
    6740        37287 :   tree_code cmp_code = comparison_op (stmt, &cmp_op1, &cmp_op2);
    6741        37287 :   bool eq_p = (cmp_code == EQ_EXPR || cmp_code == NE_EXPR);
    6742        37287 :   bool mergeable_cast_p = false;
    6743        37287 :   bool final_cast_p = false;
    6744        37287 :   if (gimple_assign_cast_p (stmt))
    6745              :     {
    6746         5472 :       lhs = gimple_assign_lhs (stmt);
    6747         5472 :       tree rhs1 = gimple_assign_rhs1 (stmt);
    6748         5472 :       if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR)
    6749           46 :         rhs1 = TREE_OPERAND (rhs1, 0);
    6750         9699 :       if (BITINT_TYPE_P (TREE_TYPE (lhs))
    6751         1245 :           && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large
    6752         6680 :           && INTEGRAL_TYPE_P (TREE_TYPE (rhs1)))
    6753              :         mergeable_cast_p = true;
    6754         4554 :       else if (BITINT_TYPE_P (TREE_TYPE (rhs1))
    6755         4264 :                && bitint_precision_kind (TREE_TYPE (rhs1)) >= bitint_prec_large
    6756         8673 :                && (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    6757           36 :                    || POINTER_TYPE_P (TREE_TYPE (lhs))
    6758           35 :                    || gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR))
    6759              :         {
    6760         4264 :           final_cast_p = true;
    6761         4264 :           if (((TREE_CODE (TREE_TYPE (lhs)) == INTEGER_TYPE
    6762          582 :                 && TYPE_PRECISION (TREE_TYPE (lhs)) > MAX_FIXED_MODE_SIZE)
    6763         4264 :                || (!INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    6764           36 :                    && !POINTER_TYPE_P (TREE_TYPE (lhs))))
    6765         4299 :               && gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR)
    6766              :             {
    6767              :               /* Handle VIEW_CONVERT_EXPRs to not generally supported
    6768              :                  huge INTEGER_TYPEs like uint256_t or uint512_t.  These
    6769              :                  are usually emitted from memcpy folding and backends
    6770              :                  support moves with them but that is usually it.
    6771              :                  Similarly handle VCEs to vector/complex types etc.  */
    6772           35 :               gcc_assert (TREE_CODE (rhs1) == SSA_NAME);
    6773           35 :               if (SSA_NAME_IS_DEFAULT_DEF (rhs1)
    6774           35 :                   && (!SSA_NAME_VAR (rhs1) || VAR_P (SSA_NAME_VAR (rhs1))))
    6775              :                 {
    6776            0 :                   tree var = create_tmp_reg (TREE_TYPE (lhs));
    6777            0 :                   rhs1 = get_or_create_ssa_default_def (cfun, var);
    6778            0 :                   gimple_assign_set_rhs1 (stmt, rhs1);
    6779            0 :                   gimple_assign_set_rhs_code (stmt, SSA_NAME);
    6780              :                 }
    6781           35 :               else if (m_names == NULL
    6782           35 :                        || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1)))
    6783              :                 {
    6784            0 :                   gimple *g = SSA_NAME_DEF_STMT (rhs1);
    6785            0 :                   gcc_assert (gimple_assign_load_p (g));
    6786            0 :                   tree mem = gimple_assign_rhs1 (g);
    6787            0 :                   tree ltype = TREE_TYPE (lhs);
    6788            0 :                   addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (mem));
    6789            0 :                   if (as != TYPE_ADDR_SPACE (ltype))
    6790            0 :                     ltype
    6791            0 :                       = build_qualified_type (ltype,
    6792            0 :                                               TYPE_QUALS (ltype).with_as (as));
    6793            0 :                   rhs1 = build1 (VIEW_CONVERT_EXPR, ltype, unshare_expr (mem));
    6794            0 :                   gimple_assign_set_rhs1 (stmt, rhs1);
    6795              :                 }
    6796              :               else
    6797              :                 {
    6798           35 :                   int part = var_to_partition (m_map, rhs1);
    6799           35 :                   gcc_assert (m_vars[part] != NULL_TREE);
    6800           35 :                   rhs1 = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs),
    6801              :                                  m_vars[part]);
    6802           35 :                   gimple_assign_set_rhs1 (stmt, rhs1);
    6803              :                 }
    6804           35 :               update_stmt (stmt);
    6805           35 :               return;
    6806              :             }
    6807         4229 :           if (TREE_CODE (rhs1) == SSA_NAME
    6808         4229 :               && (m_names == NULL
    6809         4192 :                   || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1))))
    6810              :             {
    6811         1723 :               gassign *g = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (rhs1));
    6812         1723 :               if (g
    6813         1723 :                   && gimple_assign_rhs_code (g) == IMAGPART_EXPR)
    6814              :                 {
    6815         1640 :                   tree rhs2 = TREE_OPERAND (gimple_assign_rhs1 (g), 0);
    6816         1640 :                   if (TREE_CODE (rhs2) == SSA_NAME
    6817         1640 :                       && (m_names == NULL
    6818         1603 :                           || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs2))))
    6819              :                     {
    6820         1640 :                       gimple *g2 = SSA_NAME_DEF_STMT (rhs2);
    6821         1640 :                       int ovf = optimizable_arith_overflow (g2);
    6822         1640 :                       if (ovf == 2)
    6823              :                         /* If .{ADD,SUB,MUL}_OVERFLOW has both REALPART_EXPR
    6824              :                            and IMAGPART_EXPR uses, where the latter is cast to
    6825              :                            non-_BitInt, it will be optimized when handling
    6826              :                            the REALPART_EXPR.  */
    6827              :                         return;
    6828           91 :                       if (ovf == 1)
    6829              :                         {
    6830           91 :                           lower_call (NULL_TREE, g2);
    6831           91 :                           return;
    6832              :                         }
    6833              :                     }
    6834              :                 }
    6835              :             }
    6836              :         }
    6837          145 :       else if (BITINT_TYPE_P (TREE_TYPE (lhs))
    6838          145 :                && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large
    6839          145 :                && !INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    6840          145 :                && !POINTER_TYPE_P (TREE_TYPE (rhs1))
    6841          290 :                && gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR)
    6842              :         {
    6843           10 :           int part = var_to_partition (m_map, lhs);
    6844           10 :           gcc_assert (m_vars[part] != NULL_TREE);
    6845           10 :           lhs = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (rhs1), m_vars[part]);
    6846           10 :           insert_before (gimple_build_assign (lhs, rhs1));
    6847           10 :           return;
    6848              :         }
    6849              :     }
    6850        35602 :   if (gimple_store_p (stmt))
    6851              :     {
    6852         9322 :       tree rhs1 = gimple_assign_rhs1 (stmt);
    6853         9322 :       if (TREE_CODE (rhs1) == SSA_NAME
    6854         9322 :           && (m_names == NULL
    6855         8239 :               || !bitmap_bit_p (m_names, SSA_NAME_VERSION (rhs1))))
    6856              :         {
    6857         1745 :           gimple *g = SSA_NAME_DEF_STMT (rhs1);
    6858         1745 :           m_loc = gimple_location (g);
    6859         1745 :           lhs = gimple_assign_lhs (stmt);
    6860         1745 :           if (is_gimple_assign (g) && !mergeable_op (g))
    6861          672 :             switch (gimple_assign_rhs_code (g))
    6862              :               {
    6863          119 :               case LSHIFT_EXPR:
    6864          119 :               case RSHIFT_EXPR:
    6865          119 :                 lower_shift_stmt (lhs, g);
    6866          512 :               handled:
    6867          512 :                 m_gsi = gsi_for_stmt (stmt);
    6868          512 :                 unlink_stmt_vdef (stmt);
    6869         1024 :                 if (tree vdef = gimple_vdef (stmt))
    6870          512 :                   if (TREE_CODE (vdef) == SSA_NAME)
    6871          512 :                     release_ssa_name (vdef);
    6872          512 :                 gsi_remove (&m_gsi, true);
    6873          512 :                 return;
    6874          209 :               case MULT_EXPR:
    6875          209 :               case TRUNC_DIV_EXPR:
    6876          209 :               case EXACT_DIV_EXPR:
    6877          209 :               case TRUNC_MOD_EXPR:
    6878          209 :                 lower_muldiv_stmt (lhs, g);
    6879          209 :                 goto handled;
    6880           44 :               case FIX_TRUNC_EXPR:
    6881           44 :                 lower_float_conv_stmt (lhs, g);
    6882           44 :                 goto handled;
    6883           93 :               case REALPART_EXPR:
    6884           93 :               case IMAGPART_EXPR:
    6885           93 :                 lower_cplxpart_stmt (lhs, g);
    6886           93 :                 goto handled;
    6887            8 :               case VIEW_CONVERT_EXPR:
    6888            8 :                 {
    6889            8 :                   tree rhs1 = gimple_assign_rhs1 (g);
    6890            8 :                   rhs1 = TREE_OPERAND (rhs1, 0);
    6891            8 :                   if (!INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    6892            7 :                       && !POINTER_TYPE_P (TREE_TYPE (rhs1)))
    6893              :                     {
    6894            7 :                       tree ltype = TREE_TYPE (rhs1);
    6895            7 :                       addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (lhs));
    6896            7 :                       ltype
    6897            7 :                         = build_qualified_type (ltype,
    6898            7 :                                                 TYPE_QUALS (TREE_TYPE (lhs))
    6899              :                                                 .with_as (as));
    6900            7 :                       lhs = build1 (VIEW_CONVERT_EXPR, ltype, lhs);
    6901            7 :                       gimple_assign_set_lhs (stmt, lhs);
    6902            7 :                       gimple_assign_set_rhs1 (stmt, rhs1);
    6903            7 :                       gimple_assign_set_rhs_code (stmt, TREE_CODE (rhs1));
    6904            7 :                       update_stmt (stmt);
    6905            7 :                       return;
    6906              :                     }
    6907              :                 }
    6908              :                 break;
    6909              :               default:
    6910              :                 break;
    6911              :               }
    6912         1073 :           else if (optimizable_arith_overflow (g) == 3)
    6913              :             {
    6914           24 :               lower_call (lhs, g);
    6915           24 :               goto handled;
    6916              :             }
    6917         1049 :           else if (is_gimple_call (g) && gimple_call_internal_p (g))
    6918           23 :             switch (gimple_call_internal_fn (g))
    6919              :               {
    6920           23 :               case IFN_BSWAP:
    6921           23 :               case IFN_BITREVERSE:
    6922           23 :               case IFN_CLMUL:
    6923           23 :                 lower_call (lhs, g);
    6924           23 :                 goto handled;
    6925              :               default:
    6926              :                 break;
    6927              :               }
    6928              : 
    6929         1226 :           m_loc = gimple_location (stmt);
    6930              :         }
    6931              :     }
    6932        35083 :   if (mergeable_op (stmt)
    6933        22855 :       || gimple_store_p (stmt)
    6934        22855 :       || gimple_assign_load_p (stmt)
    6935              :       || eq_p
    6936        18018 :       || mergeable_cast_p
    6937        45493 :       || (is_gimple_assign (stmt)
    6938        10001 :           && gimple_assign_rhs_code (stmt) == PAREN_EXPR))
    6939              :     {
    6940        24675 :       lhs = lower_mergeable_stmt (stmt, cmp_code, cmp_op1, cmp_op2);
    6941        24675 :       if (!eq_p)
    6942              :         return;
    6943              :     }
    6944        10408 :   else if (cmp_code != ERROR_MARK)
    6945          745 :     lhs = lower_comparison_stmt (stmt, cmp_code, cmp_op1, cmp_op2);
    6946        17422 :   if (cmp_code != ERROR_MARK)
    6947              :     {
    6948         7759 :       if (gimple_code (stmt) == GIMPLE_COND)
    6949              :         {
    6950         6982 :           gcond *cstmt = as_a <gcond *> (stmt);
    6951         6982 :           gimple_cond_set_lhs (cstmt, lhs);
    6952         6982 :           gimple_cond_set_rhs (cstmt, boolean_false_node);
    6953         6982 :           gimple_cond_set_code (cstmt, cmp_code);
    6954         6982 :           update_stmt (stmt);
    6955         6982 :           return;
    6956              :         }
    6957          777 :       if (gimple_assign_rhs_code (stmt) == COND_EXPR)
    6958              :         {
    6959            0 :           tree cond = build2 (cmp_code, boolean_type_node, lhs,
    6960              :                               boolean_false_node);
    6961            0 :           gimple_assign_set_rhs1 (stmt, cond);
    6962            0 :           lhs = gimple_assign_lhs (stmt);
    6963            0 :           gcc_assert (!BITINT_TYPE_P (TREE_TYPE (lhs))
    6964              :                       || (bitint_precision_kind (TREE_TYPE (lhs))
    6965              :                           <= bitint_prec_middle));
    6966            0 :           update_stmt (stmt);
    6967            0 :           return;
    6968              :         }
    6969          777 :       gimple_assign_set_rhs1 (stmt, lhs);
    6970          777 :       gimple_assign_set_rhs2 (stmt, boolean_false_node);
    6971          777 :       gimple_assign_set_rhs_code (stmt, cmp_code);
    6972          777 :       update_stmt (stmt);
    6973          777 :       return;
    6974              :     }
    6975         9663 :   if (final_cast_p)
    6976              :     {
    6977         2589 :       tree lhs_type = TREE_TYPE (lhs);
    6978              :       /* Add support for 3 or more limbs filled in from normal integral
    6979              :          type if this assert fails.  If no target chooses limb mode smaller
    6980              :          than half of largest supported normal integral type, this will not
    6981              :          be needed.  */
    6982         2589 :       gcc_assert (TYPE_PRECISION (lhs_type) <= 2 * limb_prec);
    6983         2589 :       gassign *g;
    6984         2552 :       if ((BITINT_TYPE_P (lhs_type)
    6985           37 :            && bitint_precision_kind (lhs_type) == bitint_prec_middle)
    6986         5163 :           || POINTER_TYPE_P (lhs_type))
    6987           16 :         lhs_type = build_nonstandard_integer_type (TYPE_PRECISION (lhs_type),
    6988           16 :                                                    TYPE_UNSIGNED (lhs_type));
    6989         2589 :       m_data_cnt = 0;
    6990         2589 :       tree rhs1 = gimple_assign_rhs1 (stmt);
    6991         2589 :       unsigned int prec = TYPE_PRECISION (TREE_TYPE (rhs1));
    6992         2589 :       unsigned int cnt = CEIL (prec, limb_prec);
    6993         2589 :       tree r1 = handle_operand (rhs1, size_int (bitint_big_endian
    6994              :                                                 ? cnt - 1 : 0));
    6995         2589 :       if (!useless_type_conversion_p (lhs_type, TREE_TYPE (r1)))
    6996         2479 :         r1 = add_cast (lhs_type, r1);
    6997         2589 :       if (TYPE_PRECISION (lhs_type) > limb_prec)
    6998              :         {
    6999           71 :           m_data_cnt = 0;
    7000           71 :           m_first = false;
    7001           71 :           tree r2 = handle_operand (rhs1, size_int (bitint_big_endian
    7002              :                                                     ? cnt - 2 : 1));
    7003           71 :           r2 = add_cast (lhs_type, r2);
    7004           71 :           g = gimple_build_assign (make_ssa_name (lhs_type), LSHIFT_EXPR, r2,
    7005              :                                    build_int_cst (unsigned_type_node,
    7006           71 :                                                   limb_prec));
    7007           71 :           insert_before (g);
    7008           71 :           g = gimple_build_assign (make_ssa_name (lhs_type), BIT_IOR_EXPR, r1,
    7009              :                                    gimple_assign_lhs (g));
    7010           71 :           insert_before (g);
    7011           71 :           r1 = gimple_assign_lhs (g);
    7012              :         }
    7013         2589 :       if (lhs_type != TREE_TYPE (lhs))
    7014           16 :         g = gimple_build_assign (lhs, NOP_EXPR, r1);
    7015              :       else
    7016         2573 :         g = gimple_build_assign (lhs, r1);
    7017         2589 :       gsi_replace (&m_gsi, g, true);
    7018         2589 :       return;
    7019              :     }
    7020         7074 :   if (is_gimple_assign (stmt))
    7021         7074 :     switch (gimple_assign_rhs_code (stmt))
    7022              :       {
    7023          563 :       case LSHIFT_EXPR:
    7024          563 :       case RSHIFT_EXPR:
    7025          563 :         lower_shift_stmt (NULL_TREE, stmt);
    7026          563 :         return;
    7027          236 :       case MULT_EXPR:
    7028          236 :       case TRUNC_DIV_EXPR:
    7029          236 :       case EXACT_DIV_EXPR:
    7030          236 :       case TRUNC_MOD_EXPR:
    7031          236 :         lower_muldiv_stmt (NULL_TREE, stmt);
    7032          236 :         return;
    7033          283 :       case FIX_TRUNC_EXPR:
    7034          283 :       case FLOAT_EXPR:
    7035          283 :         lower_float_conv_stmt (NULL_TREE, stmt);
    7036          283 :         return;
    7037         5930 :       case REALPART_EXPR:
    7038         5930 :       case IMAGPART_EXPR:
    7039         5930 :         lower_cplxpart_stmt (NULL_TREE, stmt);
    7040         5930 :         return;
    7041           62 :       case COMPLEX_EXPR:
    7042           62 :       case COMPLEX_CST:
    7043           62 :         lower_complexexpr_stmt (stmt);
    7044           62 :         return;
    7045              :       default:
    7046              :         break;
    7047              :       }
    7048            0 :   gcc_unreachable ();
    7049              : }
    7050              : 
    7051              : /* Helper for walk_non_aliased_vuses.  Determine if we arrived at
    7052              :    the desired memory state.  */
    7053              : 
    7054              : void *
    7055         2192 : vuse_eq (ao_ref *, tree vuse1, void *data)
    7056              : {
    7057         2192 :   tree vuse2 = (tree) data;
    7058         2192 :   if (vuse1 == vuse2)
    7059          821 :     return data;
    7060              : 
    7061              :   return NULL;
    7062              : }
    7063              : 
    7064              : /* Return true if STMT uses a library function and needs to take
    7065              :    address of its inputs.  We need to avoid bit-fields in those
    7066              :    cases.  Similarly, we need to avoid overlap between destination
    7067              :    and source limb arrays.  */
    7068              : 
    7069              : bool
    7070        15991 : stmt_needs_operand_addr (gimple *stmt)
    7071              : {
    7072        15991 :   if (is_gimple_assign (stmt))
    7073        10729 :     switch (gimple_assign_rhs_code (stmt))
    7074              :       {
    7075          587 :       case MULT_EXPR:
    7076          587 :       case TRUNC_DIV_EXPR:
    7077          587 :       case EXACT_DIV_EXPR:
    7078          587 :       case TRUNC_MOD_EXPR:
    7079          587 :       case FLOAT_EXPR:
    7080          587 :         return true;
    7081              :       default:
    7082              :         break;
    7083              :       }
    7084         5262 :   else if (is_gimple_call (stmt) && gimple_call_internal_p (stmt))
    7085           46 :     switch (gimple_call_internal_fn (stmt))
    7086              :       {
    7087           17 :       case IFN_MUL_OVERFLOW:
    7088           17 :       case IFN_UBSAN_CHECK_MUL:
    7089           17 :         return true;
    7090              :       /* These three actually don't take address, but reshuffle
    7091              :          all bytes or bits, so need similar treatment.  */
    7092            4 :       case IFN_BSWAP:
    7093            4 :       case IFN_BITREVERSE:
    7094            4 :       case IFN_CLMUL:
    7095            4 :         return true;
    7096              :       default:
    7097              :         break;
    7098              :       }
    7099              :   return false;
    7100              : }
    7101              : 
    7102              : /* Dominator walker used to discover which large/huge _BitInt
    7103              :    loads could be sunk into all their uses.  */
    7104              : 
    7105          666 : class bitint_dom_walker : public dom_walker
    7106              : {
    7107              : public:
    7108          333 :   bitint_dom_walker (bitmap names, bitmap loads)
    7109          666 :     : dom_walker (CDI_DOMINATORS), m_names (names), m_loads (loads) {}
    7110              : 
    7111              :   edge before_dom_children (basic_block) final override;
    7112              : 
    7113              : private:
    7114              :   bitmap m_names, m_loads;
    7115              : };
    7116              : 
    7117              : edge
    7118         4913 : bitint_dom_walker::before_dom_children (basic_block bb)
    7119              : {
    7120         4913 :   gphi *phi = get_virtual_phi (bb);
    7121         4913 :   tree vop;
    7122         4913 :   if (phi)
    7123          815 :     vop = gimple_phi_result (phi);
    7124         4098 :   else if (bb == ENTRY_BLOCK_PTR_FOR_FN (cfun))
    7125              :     vop = NULL_TREE;
    7126              :   else
    7127         3765 :     vop = (tree) get_immediate_dominator (CDI_DOMINATORS, bb)->aux;
    7128              : 
    7129         4913 :   auto_vec<tree, 16> worklist;
    7130         9826 :   for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
    7131        21293 :        !gsi_end_p (gsi); gsi_next (&gsi))
    7132              :     {
    7133        16380 :       gimple *stmt = gsi_stmt (gsi);
    7134        16380 :       if (is_gimple_debug (stmt))
    7135         2871 :         continue;
    7136              : 
    7137        16458 :       if (!vop && gimple_vuse (stmt))
    7138              :         vop = gimple_vuse (stmt);
    7139              : 
    7140        15991 :       tree cvop = vop;
    7141        29910 :       if (gimple_vdef (stmt))
    7142              :         vop = gimple_vdef (stmt);
    7143              : 
    7144        15991 :       tree lhs = gimple_get_lhs (stmt);
    7145        18473 :       if (lhs
    7146        11519 :           && TREE_CODE (lhs) == SSA_NAME
    7147         9239 :           && BITINT_TYPE_P (TREE_TYPE (lhs))
    7148         6193 :           && bitint_precision_kind (TREE_TYPE (lhs)) >= bitint_prec_large
    7149        21994 :           && !bitmap_bit_p (m_names, SSA_NAME_VERSION (lhs)))
    7150              :         /* If lhs of stmt is large/huge _BitInt SSA_NAME not in m_names,
    7151              :            it means it will be handled in a loop or straight line code
    7152              :            at the location of its (ultimate) immediate use, so for
    7153              :            vop checking purposes check these only at the ultimate
    7154              :            immediate use.  */
    7155         2482 :         continue;
    7156              : 
    7157        13509 :       ssa_op_iter oi;
    7158        13509 :       use_operand_p use_p;
    7159        22954 :       FOR_EACH_SSA_USE_OPERAND (use_p, stmt, oi, SSA_OP_USE)
    7160              :         {
    7161         9445 :           tree s = USE_FROM_PTR (use_p);
    7162        15164 :           if (BITINT_TYPE_P (TREE_TYPE (s))
    7163         9445 :               && bitint_precision_kind (TREE_TYPE (s)) >= bitint_prec_large)
    7164         3529 :             worklist.safe_push (s);
    7165              :         }
    7166              : 
    7167        13509 :       bool needs_operand_addr = stmt_needs_operand_addr (stmt);
    7168        33547 :       while (worklist.length () > 0)
    7169              :         {
    7170         6529 :           tree s = worklist.pop ();
    7171              : 
    7172         6529 :           if (!bitmap_bit_p (m_names, SSA_NAME_VERSION (s)))
    7173              :             {
    7174         2482 :               gimple *g = SSA_NAME_DEF_STMT (s);
    7175         2482 :               needs_operand_addr |= stmt_needs_operand_addr (g);
    7176         5721 :               FOR_EACH_SSA_USE_OPERAND (use_p, g, oi, SSA_OP_USE)
    7177              :                 {
    7178         3239 :                   tree s2 = USE_FROM_PTR (use_p);
    7179         3429 :                   if (BITINT_TYPE_P (TREE_TYPE (s2))
    7180         3239 :                       && (bitint_precision_kind (TREE_TYPE (s2))
    7181              :                           >= bitint_prec_large))
    7182         3000 :                     worklist.safe_push (s2);
    7183              :                 }
    7184         3476 :               continue;
    7185         2482 :             }
    7186         4047 :           if (!SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s)
    7187         4047 :               && gimple_assign_cast_p (SSA_NAME_DEF_STMT (s)))
    7188              :             {
    7189          226 :               tree rhs = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s));
    7190          396 :               if (TREE_CODE (rhs) == SSA_NAME
    7191          226 :                   && bitmap_bit_p (m_loads, SSA_NAME_VERSION (rhs)))
    7192              :                 s = rhs;
    7193              :               else
    7194          170 :                 continue;
    7195              :             }
    7196         3821 :           else if (!bitmap_bit_p (m_loads, SSA_NAME_VERSION (s)))
    7197          822 :             continue;
    7198              : 
    7199         3055 :           gimple *g = SSA_NAME_DEF_STMT (s);
    7200         3055 :           tree rhs1 = gimple_assign_rhs1 (g);
    7201         3055 :           if (needs_operand_addr
    7202          218 :               && TREE_CODE (rhs1) == COMPONENT_REF
    7203         3072 :               && DECL_BIT_FIELD_TYPE (TREE_OPERAND (rhs1, 1)))
    7204              :             {
    7205            4 :               tree fld = TREE_OPERAND (rhs1, 1);
    7206              :               /* For little-endian, we can allow as inputs bit-fields
    7207              :                  which start at a limb boundary.  */
    7208            6 :               if (!bitint_big_endian
    7209            4 :                   && DECL_OFFSET_ALIGN (fld) >= TYPE_ALIGN (TREE_TYPE (rhs1))
    7210            4 :                   && tree_fits_uhwi_p (DECL_FIELD_BIT_OFFSET (fld))
    7211            4 :                   && (tree_to_uhwi (DECL_FIELD_BIT_OFFSET (fld))
    7212            4 :                       % limb_prec) == 0)
    7213              :                 ;
    7214              :               else
    7215              :                 {
    7216            2 :                   bitmap_clear_bit (m_loads, SSA_NAME_VERSION (s));
    7217            2 :                   continue;
    7218              :                 }
    7219              :             }
    7220              : 
    7221         3053 :           ao_ref ref;
    7222         3053 :           ao_ref_init (&ref, rhs1);
    7223         3053 :           tree lvop = gimple_vuse (g);
    7224         3053 :           unsigned limit = 64;
    7225         3053 :           tree vuse = cvop;
    7226         3053 :           if (vop != cvop
    7227         1339 :               && is_gimple_assign (stmt)
    7228         1337 :               && gimple_store_p (stmt)
    7229         4390 :               && (needs_operand_addr
    7230         1144 :                   || !operand_equal_p (lhs, gimple_assign_rhs1 (g), 0)))
    7231              :             vuse = vop;
    7232         3053 :           if (vuse != lvop
    7233         3053 :               && walk_non_aliased_vuses (&ref, vuse, false, vuse_eq,
    7234              :                                          NULL, NULL, NULL, limit, lvop) == NULL)
    7235          532 :             bitmap_clear_bit (m_loads, SSA_NAME_VERSION (s));
    7236              :         }
    7237              :     }
    7238              : 
    7239         4913 :   bb->aux = (void *) vop;
    7240         4913 :   return NULL;
    7241         4913 : }
    7242              : 
    7243              : }
    7244              : 
    7245              : /* Replacement for normal processing of STMT in tree-ssa-coalesce.cc
    7246              :    build_ssa_conflict_graph.
    7247              :    The differences are:
    7248              :    1) don't process assignments with large/huge _BitInt lhs not in NAMES
    7249              :    2) for large/huge _BitInt multiplication/division/modulo process def
    7250              :       only after processing uses rather than before to make uses conflict
    7251              :       with the definition
    7252              :    3) for large/huge _BitInt uses not in NAMES mark the uses of their
    7253              :       SSA_NAME_DEF_STMT (recursively), because those uses will be sunk into
    7254              :       the final statement.  */
    7255              : 
    7256              : void
    7257        90202 : build_bitint_stmt_ssa_conflicts (gimple *stmt, live_track *live,
    7258              :                                  ssa_conflicts *graph, bitmap names,
    7259              :                                  void (*def) (live_track *, tree,
    7260              :                                               ssa_conflicts *),
    7261              :                                  void (*use) (live_track *, tree),
    7262              :                                  void (*clear) (live_track *, tree))
    7263              : {
    7264        90202 :   bool muldiv_p = false;
    7265        90202 :   tree lhs = NULL_TREE;
    7266        90202 :   if (gassign *stmt_a = dyn_cast<gassign *> (stmt))
    7267              :     {
    7268        49157 :       lhs = gimple_assign_lhs (stmt_a);
    7269        49157 :       if (TREE_CODE (lhs) == SSA_NAME)
    7270              :         {
    7271        35302 :           tree type = TREE_TYPE (lhs);
    7272        35302 :           if (TREE_CODE (type) == COMPLEX_TYPE)
    7273           75 :             type = TREE_TYPE (type);
    7274        13552 :           if (BITINT_TYPE_P (type)
    7275        35307 :               && bitint_precision_kind (type) >= bitint_prec_large)
    7276              :             {
    7277        21069 :               if (!bitmap_bit_p (names, SSA_NAME_VERSION (lhs)))
    7278         5275 :                 return;
    7279              : 
    7280              :               /* A copy between 2 partitions does not introduce an interference
    7281              :                  by itself.  If they did, you would never be able to coalesce
    7282              :                  two things which are copied.  If the two variables really do
    7283              :                  conflict, they will conflict elsewhere in the program.
    7284              : 
    7285              :                  This is handled by simply removing the SRC of the copy from
    7286              :                  the live list, and processing the stmt normally.
    7287              : 
    7288              :                  Don't do this if lhs is not in names though, in such cases
    7289              :                  it is actually used at some point later in the basic
    7290              :                  block.  */
    7291        15794 :               if (gimple_assign_copy_p (stmt_a))
    7292              :                 {
    7293         1806 :                   tree rhs1 = gimple_assign_rhs1 (stmt_a);
    7294         1806 :                   if (TREE_CODE (rhs1) == SSA_NAME)
    7295          108 :                     clear (live, rhs1);
    7296              :                 }
    7297              : 
    7298        15794 :               switch (gimple_assign_rhs_code (stmt))
    7299              :                 {
    7300          236 :                 case MULT_EXPR:
    7301          236 :                 case TRUNC_DIV_EXPR:
    7302          236 :                 case EXACT_DIV_EXPR:
    7303          236 :                 case TRUNC_MOD_EXPR:
    7304          236 :                   muldiv_p = true;
    7305              :                 default:
    7306              :                   break;
    7307              :                 }
    7308              :             }
    7309              :         }
    7310              :     }
    7311        41045 :   else if (is_gimple_call (stmt) && gimple_call_internal_p (stmt))
    7312         4420 :     switch (gimple_call_internal_fn (stmt))
    7313              :       {
    7314         2699 :       case IFN_ADD_OVERFLOW:
    7315         2699 :       case IFN_SUB_OVERFLOW:
    7316         2699 :       case IFN_UBSAN_CHECK_ADD:
    7317         2699 :       case IFN_UBSAN_CHECK_SUB:
    7318         2699 :         if (bitint_big_endian)
    7319              :           {
    7320            0 :             lhs = gimple_call_lhs (stmt);
    7321            0 :             if (lhs)
    7322        84927 :               muldiv_p = true;
    7323              :           }
    7324              :         break;
    7325         1540 :       case IFN_MUL_OVERFLOW:
    7326         1540 :       case IFN_UBSAN_CHECK_MUL:
    7327         1540 :       case IFN_BSWAP:
    7328         1540 :       case IFN_BITREVERSE:
    7329         1540 :       case IFN_CLMUL:
    7330         1540 :         lhs = gimple_call_lhs (stmt);
    7331         1540 :         if (lhs)
    7332        84927 :           muldiv_p = true;
    7333              :         break;
    7334              :       default:
    7335              :         break;
    7336              :       }
    7337              : 
    7338       169854 :   auto_vec<tree, 16> worklist;
    7339        84927 :   ssa_op_iter iter;
    7340        84927 :   tree var;
    7341              :   /* On little-endian, mergeable ops process limbs from 0 up so except
    7342              :      for multiplication/division/modulo there is no risk in using the
    7343              :      same underlying variable for lhs and some operand, even when casts
    7344              :      are involved, the lhs limb is stored only after processing the source
    7345              :      limbs with the same index.
    7346              :      For multiplication/division/modulo, the libgcc library function requires
    7347              :      no aliasing between result and sources.
    7348              :      On big-endian, even mergeable ops limb processing can be problematic
    7349              :      though, because it can apply various index corrections e.g. when there
    7350              :      is a cast from operand with different number of limbs.  So, make the
    7351              :      lhs conflict with all the operands which are (for now virtually) used on
    7352              :      the current stmt if there is any mismatch in the number of limbs between
    7353              :      operands and the lhs.  */
    7354        84927 :   if (bitint_big_endian && lhs && !muldiv_p)
    7355              :     {
    7356            0 :       tree ltype = TREE_TYPE (lhs);
    7357            0 :       if (TREE_CODE (ltype) == COMPLEX_TYPE)
    7358              :         muldiv_p = true;
    7359            0 :       else if (TREE_CODE (lhs) == SSA_NAME
    7360            0 :                && BITINT_TYPE_P (ltype)
    7361            0 :                && bitint_precision_kind (ltype) >= bitint_prec_large)
    7362              :         {
    7363            0 :           unsigned lnelts = CEIL (TYPE_PRECISION (ltype), limb_prec);
    7364            0 :           FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE)
    7365              :             {
    7366            0 :               tree type = TREE_TYPE (var);
    7367            0 :               if (TREE_CODE (type) == COMPLEX_TYPE)
    7368            0 :                 type = TREE_TYPE (type);
    7369            0 :               if (BITINT_TYPE_P (type)
    7370            0 :                   && bitint_precision_kind (type) >= bitint_prec_large)
    7371              :                 {
    7372            0 :                   if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
    7373              :                     {
    7374            0 :                       unsigned nelts = CEIL (TYPE_PRECISION (type), limb_prec);
    7375            0 :                       if (TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE
    7376            0 :                           || lnelts != nelts)
    7377              :                         {
    7378            0 :                           muldiv_p = true;
    7379              :                           break;
    7380              :                         }
    7381              :                     }
    7382              :                   else
    7383            0 :                     worklist.safe_push (var);
    7384              :                 }
    7385              :             }
    7386              : 
    7387            0 :           while (!muldiv_p && worklist.length () > 0)
    7388              :             {
    7389            0 :               tree s = worklist.pop ();
    7390            0 :               FOR_EACH_SSA_TREE_OPERAND (var, SSA_NAME_DEF_STMT (s), iter,
    7391              :                                          SSA_OP_USE)
    7392              :                 {
    7393            0 :                   tree type = TREE_TYPE (var);
    7394            0 :                   if (TREE_CODE (type) == COMPLEX_TYPE)
    7395            0 :                     type = TREE_TYPE (type);
    7396            0 :                   if (BITINT_TYPE_P (type)
    7397            0 :                       && bitint_precision_kind (type) >= bitint_prec_large)
    7398              :                     {
    7399            0 :                       if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
    7400              :                         {
    7401            0 :                           unsigned nelts = CEIL (TYPE_PRECISION (type),
    7402              :                                                  limb_prec);
    7403            0 :                           if (TREE_CODE (TREE_TYPE (var)) == COMPLEX_TYPE
    7404            0 :                               || lnelts != nelts)
    7405              :                             {
    7406              :                               muldiv_p = true;
    7407              :                               break;
    7408              :                             }
    7409              :                         }
    7410              :                       else
    7411            0 :                         worklist.safe_push (var);
    7412              :                     }
    7413              :                 }
    7414              :             }
    7415            0 :           worklist.truncate (0);
    7416              :         }
    7417              :     }
    7418              : 
    7419        84927 :   if (!muldiv_p)
    7420              :     {
    7421              :       /* For stmts with more than one SSA_NAME definition pretend all the
    7422              :          SSA_NAME outputs but the first one are live at this point, so
    7423              :          that conflicts are added in between all those even when they are
    7424              :          actually not really live after the asm, because expansion might
    7425              :          copy those into pseudos after the asm and if multiple outputs
    7426              :          share the same partition, it might overwrite those that should
    7427              :          be live.  E.g.
    7428              :          asm volatile (".." : "=r" (a) : "=r" (b) : "0" (a), "1" (a));
    7429              :          return a;
    7430              :          See PR70593.  */
    7431        83151 :       bool first = true;
    7432       121290 :       FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF)
    7433        38139 :         if (first)
    7434              :           first = false;
    7435              :         else
    7436            0 :           use (live, var);
    7437              : 
    7438       121290 :       FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_DEF)
    7439        38139 :         def (live, var, graph);
    7440              :     }
    7441              : 
    7442       144952 :   FOR_EACH_SSA_TREE_OPERAND (var, stmt, iter, SSA_OP_USE)
    7443              :     {
    7444        60025 :       tree type = TREE_TYPE (var);
    7445        60025 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    7446         6315 :         type = TREE_TYPE (type);
    7447        20924 :       if (BITINT_TYPE_P (type)
    7448        60042 :           && bitint_precision_kind (type) >= bitint_prec_large)
    7449              :         {
    7450        38007 :           if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
    7451        32583 :             use (live, var);
    7452              :           else
    7453         5424 :             worklist.safe_push (var);
    7454              :         }
    7455              :     }
    7456              : 
    7457        93427 :   while (worklist.length () > 0)
    7458              :     {
    7459         8500 :       tree s = worklist.pop ();
    7460        17966 :       FOR_EACH_SSA_TREE_OPERAND (var, SSA_NAME_DEF_STMT (s), iter, SSA_OP_USE)
    7461              :         {
    7462         9466 :           tree type = TREE_TYPE (var);
    7463         9466 :           if (TREE_CODE (type) == COMPLEX_TYPE)
    7464         1695 :             type = TREE_TYPE (type);
    7465          577 :           if (BITINT_TYPE_P (type)
    7466         9472 :               && bitint_precision_kind (type) >= bitint_prec_large)
    7467              :             {
    7468         8756 :               if (bitmap_bit_p (names, SSA_NAME_VERSION (var)))
    7469         5680 :                 use (live, var);
    7470              :               else
    7471         3076 :                 worklist.safe_push (var);
    7472              :             }
    7473              :         }
    7474              :     }
    7475              : 
    7476        84927 :   if (muldiv_p)
    7477         1776 :     def (live, lhs, graph);
    7478              : }
    7479              : 
    7480              : /* If STMT is .{ADD,SUB,MUL}_OVERFLOW with INTEGER_CST arguments,
    7481              :    return the largest bitint_prec_kind of them, otherwise return
    7482              :    bitint_prec_small.  */
    7483              : 
    7484              : static bitint_prec_kind
    7485       212407 : arith_overflow_arg_kind (gimple *stmt)
    7486              : {
    7487       212407 :   bitint_prec_kind ret = bitint_prec_small;
    7488       212407 :   if (is_gimple_call (stmt) && gimple_call_internal_p (stmt))
    7489        89431 :     switch (gimple_call_internal_fn (stmt))
    7490              :       {
    7491              :       case IFN_ADD_OVERFLOW:
    7492              :       case IFN_SUB_OVERFLOW:
    7493              :       case IFN_MUL_OVERFLOW:
    7494       226002 :         for (int i = 0; i < 2; ++i)
    7495              :           {
    7496       150668 :             tree a = gimple_call_arg (stmt, i);
    7497       150668 :             if (TREE_CODE (a) == INTEGER_CST
    7498       150668 :                 && BITINT_TYPE_P (TREE_TYPE (a)))
    7499              :               {
    7500         5951 :                 bitint_prec_kind kind = bitint_precision_kind (TREE_TYPE (a));
    7501       150668 :                 ret = MAX (ret, kind);
    7502              :               }
    7503              :           }
    7504              :         break;
    7505              :       default:
    7506              :         break;
    7507              :       }
    7508       212407 :   return ret;
    7509              : }
    7510              : 
    7511              : /* Lower a call to __builtin_bitcompressg (ARG0, ARG1) or
    7512              :    __builtin_bitexpandg (ARG0, ARG1) for large/huge _BitInt types.  */
    7513              : 
    7514              : static void
    7515           26 : lower_bitcompress_bitexpand (gimple *stmt)
    7516              : {
    7517           26 :   location_t loc = gimple_location (stmt);
    7518           26 :   tree arg0 = gimple_call_arg (stmt, 0);
    7519           26 :   tree arg1 = gimple_call_arg (stmt, 1);
    7520           26 :   tree lhs = gimple_call_lhs (stmt);
    7521           26 :   gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    7522           26 :   internal_fn ifn = gimple_call_internal_fn (stmt);
    7523           26 :   gcc_assert (ifn == IFN_BITCOMPRESS || ifn == IFN_BITEXPAND);
    7524           26 :   tree type = TREE_TYPE (arg0);
    7525           26 :   unsigned prec = TYPE_PRECISION (type);
    7526           26 :   unsigned log2prec = ceil_log2 (prec);
    7527           26 :   if (!lhs)
    7528              :     {
    7529            0 :       gsi_remove (&gsi, true);
    7530           12 :       return;
    7531              :     }
    7532           26 :   calculate_dominance_info (CDI_DOMINATORS);
    7533              :   /* Based on "Compress, or Generalized Extract" in Hacker's Delight:
    7534              :      T
    7535              :      bitcompressg (T x, T m)
    7536              :      {
    7537              :        int prec = __builtin_popcountg ((T) ~(T) 0);
    7538              :        x &= m;
    7539              :        T mk = ~m << 1;
    7540              :        for (int i = 1; i < prec; i <<= 1)
    7541              :          {
    7542              :            T mp = mk;
    7543              :            for (int j = 1; j < prec; j <<= 1)
    7544              :              mp ^= mp << j;
    7545              :            T mv = mp & m;
    7546              :            m = (m ^ mv) | (mv >> i);
    7547              :            T t = x & mv;
    7548              :            x = (x ^ t) | (t >> i);
    7549              :            mk = mk & ~mp;
    7550              :          }
    7551              :        return x;
    7552              :      }
    7553              :      and based on "Expand, or Generalized Insert" in Hacker's Delight:
    7554              :      T
    7555              :      bitexpandg (T x, T m)
    7556              :      {
    7557              :        int prec = __builtin_popcountg ((T) ~(T) 0);
    7558              :        int log2prec = ceil_log2 (prec);
    7559              :        T m0 = m;
    7560              :        T mk = ~m << 1;
    7561              :        T array[log2prec];
    7562              :        for (int i = 0; i < log2prec; i++)
    7563              :          {
    7564              :            T mp = mk;
    7565              :            for (int j = 1; j < prec; j <<= 1)
    7566              :              mp ^= mp << j;
    7567              :            T mv = mp & m;
    7568              :            array[i] = mv;
    7569              :            m = (m ^ mv) | (mv >> (1 << i));
    7570              :            mk = mk & ~mp;
    7571              :          }
    7572              :        for (int i = log2prec - 1; i >= 0; i--)
    7573              :          {
    7574              :            T mv = array[i];
    7575              :            T t = x << (((T) 1) << i);
    7576              :            x = (x & ~mv) | (t & mv);
    7577              :          }
    7578              :        return x & m0;
    7579              :      }  */
    7580           26 :   tree x = arg0;
    7581           26 :   tree m = arg1;
    7582           26 :   gimple *g;
    7583           26 :   if (TREE_CODE (x) != SSA_NAME || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (x))
    7584              :     {
    7585            0 :       x = make_ssa_name (type);
    7586            0 :       g = gimple_build_assign (x, arg0);
    7587            0 :       gimple_set_location (g, loc);
    7588            0 :       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7589              :     }
    7590           26 :   if (TREE_CODE (m) != SSA_NAME || SSA_NAME_OCCURS_IN_ABNORMAL_PHI (m))
    7591              :     {
    7592            0 :       m = make_ssa_name (type);
    7593            0 :       g = gimple_build_assign (m, arg1);
    7594            0 :       gimple_set_location (g, loc);
    7595            0 :       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7596              :     }
    7597           26 :   tree m0 = m;
    7598           26 :   tree array = NULL_TREE;
    7599           26 :   if (ifn == IFN_BITCOMPRESS)
    7600              :     {
    7601           12 :       g = gimple_build_assign (make_ssa_name (type),
    7602              :                                BIT_AND_EXPR, x, m);
    7603           12 :       gimple_set_location (g, loc);
    7604           12 :       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7605           12 :       x = gimple_assign_lhs (g);
    7606              :     }
    7607              :   else
    7608              :     {
    7609           14 :       tree atype = build_array_type_nelts (type, log2prec);
    7610           14 :       array = create_tmp_var (atype);
    7611              :     }
    7612           26 :   g = gimple_build_assign (make_ssa_name (type), BIT_NOT_EXPR, m);
    7613           26 :   gimple_set_location (g, loc);
    7614           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7615           26 :   tree mk = make_ssa_name (type);
    7616           26 :   g = gimple_build_assign (mk, LSHIFT_EXPR, gimple_assign_lhs (g),
    7617              :                            build_int_cst (unsigned_type_node, 1));
    7618           26 :   gimple_set_location (g, loc);
    7619           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7620           26 :   edge preheader_edge, latch_edge, exit_edge;
    7621           26 :   auto create_loop_after
    7622           66 :     = [] (basic_block bb, gimple *g, edge *e1, edge *e2, edge *e3) {
    7623           66 :     *e1 = split_block (bb, g);
    7624           66 :     *e2 = split_block ((*e1)->dest, (gimple *) NULL);
    7625           66 :     *e3 = make_edge ((*e1)->dest, (*e1)->dest, EDGE_TRUE_VALUE);
    7626           66 :     (*e3)->probability = profile_probability::very_unlikely ();
    7627           66 :     (*e2)->flags = EDGE_FALSE_VALUE;
    7628           66 :     (*e2)->probability = (*e3)->probability.invert ();
    7629           66 :     gimple_stmt_iterator gsi = gsi_after_labels ((*e1)->dest);
    7630           66 :     class loop *loop = alloc_loop ();
    7631           66 :     loop->header = (*e1)->dest;
    7632           66 :     add_loop (loop, (*e1)->src->loop_father);
    7633           66 :     return gsi;
    7634              :   };
    7635          196 :   auto add_loop_phi = [] (tree init, tree *next, edge e1, edge e3) {
    7636          170 :     tree res = make_ssa_name (TREE_TYPE (init));
    7637          170 :     gphi *phi = create_phi_node (res, e1->dest);
    7638          170 :     add_phi_arg (phi, init, e1, UNKNOWN_LOCATION);
    7639          170 :     *next = make_ssa_name (TREE_TYPE (init));
    7640          170 :     add_phi_arg (phi, *next, e3, UNKNOWN_LOCATION);
    7641          170 :     return res;
    7642              :   };
    7643           26 :   gsi = create_loop_after (gimple_bb (g), g, &preheader_edge,
    7644              :                            &exit_edge, &latch_edge);
    7645           26 :   tree i_next, m_next, mk_next, x_next = NULL_TREE;
    7646           26 :   tree i = add_loop_phi (build_int_cst (integer_type_node,
    7647           26 :                                         ifn == IFN_BITCOMPRESS),
    7648              :                          &i_next, preheader_edge, latch_edge);
    7649           26 :   m = add_loop_phi (m, &m_next, preheader_edge, latch_edge);
    7650           26 :   mk = add_loop_phi (mk, &mk_next, preheader_edge, latch_edge);
    7651           26 :   if (ifn == IFN_BITCOMPRESS)
    7652           12 :     x = add_loop_phi (x, &x_next, preheader_edge, latch_edge);
    7653           26 :   gsi = create_loop_after (gsi_bb (gsi), NULL, &preheader_edge,
    7654              :                            &exit_edge, &latch_edge);
    7655           26 :   tree j_next, mp_next;
    7656           26 :   tree j = add_loop_phi (build_int_cst (integer_type_node, 1), &j_next,
    7657              :                          preheader_edge, latch_edge);
    7658           26 :   tree mp = add_loop_phi (mk, &mp_next, preheader_edge, latch_edge);
    7659           26 :   g = gimple_build_assign (make_ssa_name (type), LSHIFT_EXPR, mp, j);
    7660           26 :   gimple_set_location (g, loc);
    7661           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7662           26 :   g = gimple_build_assign (mp_next, BIT_XOR_EXPR, mp, gimple_assign_lhs (g));
    7663           26 :   gimple_set_location (g, loc);
    7664           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7665           26 :   g = gimple_build_assign (j_next, PLUS_EXPR, j, j);
    7666           26 :   gimple_set_location (g, loc);
    7667           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7668           26 :   g = gimple_build_cond (LT_EXPR, j_next,
    7669           26 :                          build_int_cst (integer_type_node, prec),
    7670              :                          NULL_TREE, NULL_TREE);
    7671           26 :   gimple_set_location (g, loc);
    7672           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7673           26 :   gsi = gsi_after_labels (exit_edge->dest);
    7674           26 :   mp = mp_next;
    7675           26 :   tree mv = make_ssa_name (type);
    7676           26 :   g = gimple_build_assign (mv, BIT_AND_EXPR, mp, m);
    7677           26 :   gimple_set_location (g, loc);
    7678           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7679           26 :   tree shiftcnt = i;
    7680           26 :   if (ifn == IFN_BITEXPAND)
    7681              :     {
    7682           14 :       tree aref = build4 (ARRAY_REF, type, array, i, NULL_TREE, NULL_TREE);
    7683           14 :       g = gimple_build_assign (aref, mv);
    7684           14 :       gimple_set_location (g, loc);
    7685           14 :       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7686           14 :       shiftcnt = make_ssa_name (integer_type_node);
    7687           14 :       g = gimple_build_assign (shiftcnt, LSHIFT_EXPR, integer_one_node, i);
    7688           14 :       gimple_set_location (g, loc);
    7689           14 :       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7690              :     }
    7691           26 :   tree tem = make_ssa_name (type);
    7692           26 :   g = gimple_build_assign (tem, BIT_XOR_EXPR, m, mv);
    7693           26 :   gimple_set_location (g, loc);
    7694           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7695           26 :   g = gimple_build_assign (make_ssa_name (type), RSHIFT_EXPR, mv, shiftcnt);
    7696           26 :   gimple_set_location (g, loc);
    7697           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7698           26 :   g = gimple_build_assign (m_next, BIT_IOR_EXPR, tem, gimple_assign_lhs (g));
    7699           26 :   gimple_set_location (g, loc);
    7700           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7701           26 :   if (ifn == IFN_BITCOMPRESS)
    7702              :     {
    7703           12 :       tree t = make_ssa_name (type);
    7704           12 :       g = gimple_build_assign (t, BIT_AND_EXPR, x, mv);
    7705           12 :       gimple_set_location (g, loc);
    7706           12 :       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7707           12 :       tem = make_ssa_name (type);
    7708           12 :       g = gimple_build_assign (tem, BIT_XOR_EXPR, x, t);
    7709           12 :       gimple_set_location (g, loc);
    7710           12 :       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7711           12 :       g = gimple_build_assign (make_ssa_name (type), RSHIFT_EXPR, t, shiftcnt);
    7712           12 :       gimple_set_location (g, loc);
    7713           12 :       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7714           12 :       g = gimple_build_assign (x_next, BIT_IOR_EXPR, tem, gimple_assign_lhs (g));
    7715           12 :       gimple_set_location (g, loc);
    7716           12 :       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7717              :     }
    7718           26 :   g = gimple_build_assign (make_ssa_name (type), BIT_NOT_EXPR, mp);
    7719           26 :   gimple_set_location (g, loc);
    7720           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7721           26 :   g = gimple_build_assign (mk_next, BIT_AND_EXPR, mk, gimple_assign_lhs (g));
    7722           26 :   gimple_set_location (g, loc);
    7723           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7724           26 :   g = gimple_build_assign (i_next, PLUS_EXPR, i,
    7725              :                            ifn == IFN_BITCOMPRESS ? i : integer_one_node);
    7726           26 :   gimple_set_location (g, loc);
    7727           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7728           26 :   g = gimple_build_cond (LT_EXPR, i_next,
    7729              :                          build_int_cst (integer_type_node,
    7730              :                                         ifn == IFN_BITCOMPRESS
    7731           38 :                                         ? prec : log2prec),
    7732              :                          NULL_TREE, NULL_TREE);
    7733           26 :   gimple_set_location (g, loc);
    7734           26 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7735           26 :   gsi = gsi_for_stmt (stmt);
    7736           26 :   if (ifn == IFN_BITCOMPRESS)
    7737              :     {
    7738           12 :       g = gimple_build_assign (lhs, x_next);
    7739           12 :       gimple_set_location (g, loc);
    7740           12 :       gsi_replace (&gsi, g, true);
    7741           12 :       return;
    7742              :     }
    7743           14 :   gsi = create_loop_after (gsi_bb (gsi), NULL, &preheader_edge,
    7744              :                            &exit_edge, &latch_edge);
    7745           14 :   i = add_loop_phi (build_int_cst (integer_type_node, log2prec - 1),
    7746              :                     &i_next, preheader_edge, latch_edge);
    7747           14 :   x = add_loop_phi (x, &x_next, preheader_edge, latch_edge);
    7748           14 :   tree aref = build4 (ARRAY_REF, type, array, i, NULL_TREE, NULL_TREE);
    7749           14 :   mv = make_ssa_name (type);
    7750           14 :   g = gimple_build_assign (mv, aref);
    7751           14 :   gimple_set_location (g, loc);
    7752           14 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7753           14 :   shiftcnt = make_ssa_name (integer_type_node);
    7754           14 :   g = gimple_build_assign (shiftcnt, LSHIFT_EXPR, integer_one_node, i);
    7755           14 :   gimple_set_location (g, loc);
    7756           14 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7757           14 :   tree t = make_ssa_name (type);
    7758           14 :   g = gimple_build_assign (t, LSHIFT_EXPR, x, shiftcnt);
    7759           14 :   gimple_set_location (g, loc);
    7760           14 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7761           14 :   g = gimple_build_assign (make_ssa_name (type), BIT_NOT_EXPR, mv);
    7762           14 :   gimple_set_location (g, loc);
    7763           14 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7764           14 :   tem = make_ssa_name (type);
    7765           14 :   g = gimple_build_assign (tem, BIT_AND_EXPR, x, gimple_assign_lhs (g));
    7766           14 :   gimple_set_location (g, loc);
    7767           14 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7768           14 :   g = gimple_build_assign (make_ssa_name (type), BIT_AND_EXPR, t, mv);
    7769           14 :   gimple_set_location (g, loc);
    7770           14 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7771           14 :   g = gimple_build_assign (x_next, BIT_IOR_EXPR, tem, gimple_assign_lhs (g));
    7772           14 :   gimple_set_location (g, loc);
    7773           14 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7774           14 :   g = gimple_build_assign (i_next, PLUS_EXPR, i, integer_minus_one_node);
    7775           14 :   gimple_set_location (g, loc);
    7776           14 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7777           14 :   g = gimple_build_cond (GE_EXPR, i_next, integer_zero_node,
    7778              :                          NULL_TREE, NULL_TREE);
    7779           14 :   gimple_set_location (g, loc);
    7780           14 :   gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    7781           14 :   gsi = gsi_for_stmt (stmt);
    7782           14 :   g = gimple_build_assign (lhs, BIT_AND_EXPR, x_next, m0);
    7783           14 :   gimple_set_location (g, loc);
    7784           14 :   gsi_replace (&gsi, g, true);
    7785              : }
    7786              : 
    7787              : /* Return true if given the current large_huge.m_names bitmap it is planned
    7788              :    to merge STMT lowering with lowering of some
    7789              :    {PLUS,MINUS,NEGATE,LSHIFT}_EXPR.  */
    7790              : 
    7791              : static bool
    7792          750 : requires_upwards_2limb (struct bitint_large_huge &large_huge, gimple *stmt)
    7793              : {
    7794          750 :   if (!mergeable_op (stmt) && !gimple_assign_cast_p (stmt))
    7795              :     return false;
    7796          704 :   switch (gimple_assign_rhs_code (stmt))
    7797              :     {
    7798              :     case PLUS_EXPR:
    7799              :     case MINUS_EXPR:
    7800              :     case NEGATE_EXPR:
    7801              :     case LSHIFT_EXPR:
    7802              :       /* These all require m_upwards_2limb.  */
    7803              :       return true;
    7804              :     default:
    7805              :       break;
    7806              :     }
    7807         1436 :   for (unsigned i = 0; i < gimple_num_ops (stmt) - 1; ++i)
    7808              :     {
    7809          746 :       tree rhs = gimple_assign_rhs1_ptr (stmt)[i];
    7810          746 :       if (gimple_assign_rhs_code (stmt) == VIEW_CONVERT_EXPR)
    7811            2 :         rhs = TREE_OPERAND (rhs, 0);
    7812         1354 :       if (TREE_CODE (rhs) != SSA_NAME
    7813          745 :           || !BITINT_TYPE_P (TREE_TYPE (rhs))
    7814          524 :           || bitint_precision_kind (TREE_TYPE (rhs)) < bitint_prec_large
    7815          409 :           || gimple_bb (SSA_NAME_DEF_STMT (rhs)) != gimple_bb (stmt)
    7816         1075 :           || (large_huge.m_names
    7817          282 :               && bitmap_bit_p (large_huge.m_names, SSA_NAME_VERSION (rhs))))
    7818          608 :         continue;
    7819          138 :       if (requires_upwards_2limb (large_huge, SSA_NAME_DEF_STMT (rhs)))
    7820              :         return true;
    7821              :     }
    7822              :   return false;
    7823              : }
    7824              : 
    7825              : /* Entry point for _BitInt(N) operation lowering during optimization.  */
    7826              : 
    7827              : static unsigned int
    7828      1532070 : gimple_lower_bitint (void)
    7829              : {
    7830      1532070 :   small_max_prec = mid_min_prec = large_min_prec = huge_min_prec = 0;
    7831      1532070 :   limb_prec = abi_limb_prec = 0;
    7832      1532070 :   bitint_big_endian = false;
    7833      1532070 :   bool loop_init_done = false;
    7834              : 
    7835      1532070 :   unsigned int i;
    7836     65565065 :   for (i = 0; i < num_ssa_names; ++i)
    7837              :     {
    7838     64040774 :       tree s = ssa_name (i);
    7839     64040774 :       if (s == NULL)
    7840     13645097 :         continue;
    7841     50395677 :       tree type = TREE_TYPE (s);
    7842     50395677 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    7843              :         {
    7844       201695 :           if (arith_overflow_arg_kind (SSA_NAME_DEF_STMT (s))
    7845              :               != bitint_prec_small)
    7846              :             break;
    7847       201575 :           type = TREE_TYPE (type);
    7848              :         }
    7849     50377065 :       if (BITINT_TYPE_P (type)
    7850     50395564 :           && bitint_precision_kind (type) != bitint_prec_small)
    7851              :         break;
    7852              :       /* We need to also rewrite stores of large/huge _BitInt INTEGER_CSTs
    7853              :          into memory.  Such functions could have no large/huge SSA_NAMEs.  */
    7854     50387987 :       if (SSA_NAME_IS_VIRTUAL_OPERAND (s))
    7855              :         {
    7856     22067489 :           auto *g = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (s));
    7857     11229078 :           if (g && gimple_store_p (g))
    7858              :             {
    7859     11229078 :               tree t = gimple_assign_rhs1 (g);
    7860     22455313 :               if (BITINT_TYPE_P (TREE_TYPE (t))
    7861     11229078 :                   && (bitint_precision_kind (TREE_TYPE (t))
    7862              :                       >= bitint_prec_large))
    7863              :                 break;
    7864              :             }
    7865              :         }
    7866              :       /* Similarly, e.g. with -frounding-math casts from _BitInt INTEGER_CSTs
    7867              :          to floating point types need to be rewritten.  */
    7868     28320498 :       else if (SCALAR_FLOAT_TYPE_P (type))
    7869              :         {
    7870     65902855 :           auto *g = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (s));
    7871      2741460 :           if (g && gimple_assign_rhs_code (g) == FLOAT_EXPR)
    7872              :             {
    7873       129933 :               tree t = gimple_assign_rhs1 (g);
    7874       129933 :               if (TREE_CODE (t) == INTEGER_CST
    7875          110 :                   && BITINT_TYPE_P (TREE_TYPE (t))
    7876       129934 :                   && (bitint_precision_kind (TREE_TYPE (t))
    7877              :                       != bitint_prec_small))
    7878              :                 break;
    7879              :             }
    7880              :         }
    7881              :     }
    7882      3064140 :   if (i == num_ssa_names)
    7883              :     return 0;
    7884              : 
    7885         7779 :   basic_block bb;
    7886         7779 :   auto_vec<gimple *, 4> switch_statements;
    7887        49251 :   FOR_EACH_BB_FN (bb, cfun)
    7888              :     {
    7889       123573 :       if (gswitch *swtch = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb)))
    7890              :         {
    7891           34 :           tree idx = gimple_switch_index (swtch);
    7892           42 :           if (!BITINT_TYPE_P (TREE_TYPE (idx))
    7893           34 :               || bitint_precision_kind (TREE_TYPE (idx)) < bitint_prec_large)
    7894           21 :             continue;
    7895              : 
    7896           13 :           if (optimize)
    7897            8 :             group_case_labels_stmt (swtch);
    7898           13 :           if (gimple_switch_num_labels (swtch) == 1)
    7899              :             {
    7900            0 :               single_succ_edge (bb)->flags |= EDGE_FALLTHRU;
    7901            0 :               gimple_stmt_iterator gsi = gsi_for_stmt (swtch);
    7902            0 :               gsi_remove (&gsi, true);
    7903              :             }
    7904              :           else
    7905           13 :             switch_statements.safe_push (swtch);
    7906              :         }
    7907              :     }
    7908              : 
    7909         7779 :   if (!switch_statements.is_empty ())
    7910              :     {
    7911           13 :       bool expanded = false;
    7912           13 :       gimple *stmt;
    7913           13 :       unsigned int j;
    7914           13 :       i = 0;
    7915           26 :       FOR_EACH_VEC_ELT (switch_statements, j, stmt)
    7916              :         {
    7917           13 :           gswitch *swtch = as_a<gswitch *> (stmt);
    7918           13 :           tree_switch_conversion::switch_decision_tree dt (swtch);
    7919           13 :           expanded |= dt.analyze_switch_statement ();
    7920           13 :         }
    7921              : 
    7922           13 :       if (expanded)
    7923              :         {
    7924           13 :           free_dominance_info (CDI_DOMINATORS);
    7925           13 :           free_dominance_info (CDI_POST_DOMINATORS);
    7926           13 :           mark_virtual_operands_for_renaming (cfun);
    7927           13 :           cleanup_tree_cfg (TODO_update_ssa);
    7928              :         }
    7929              :     }
    7930              : 
    7931         7779 :   if (flag_sanitize & (SANITIZE_ADDRESS | SANITIZE_HWADDRESS))
    7932              :     {
    7933           14 :       hash_map<tree, tree> shadow_vars_mapping;
    7934           14 :       bool need_commit_edge_insert = false;
    7935           14 :       bool any_asan_poison = false;
    7936          129 :       for (unsigned j = 0; j < num_ssa_names; ++j)
    7937              :         {
    7938          115 :           tree s = ssa_name (j);
    7939          115 :           if (s == NULL)
    7940           31 :             continue;
    7941           84 :           tree type = TREE_TYPE (s);
    7942           37 :           if (BITINT_TYPE_P (type)
    7943           47 :               && gimple_call_internal_p (SSA_NAME_DEF_STMT (s),
    7944              :                                          IFN_ASAN_POISON)
    7945          112 :               && bitint_precision_kind (type) >= bitint_prec_large)
    7946              :             {
    7947           28 :               any_asan_poison = true;
    7948           28 :               gimple_stmt_iterator gsi = gsi_for_stmt (SSA_NAME_DEF_STMT (s));
    7949           28 :               asan_expand_poison_ifn (&gsi, &need_commit_edge_insert,
    7950              :                                       shadow_vars_mapping);
    7951              :             }
    7952              :         }
    7953           14 :       if (any_asan_poison)
    7954              :         {
    7955           14 :           if (need_commit_edge_insert)
    7956            0 :             gsi_commit_edge_inserts ();
    7957           14 :           i = 0;
    7958           14 :           free_dominance_info (CDI_DOMINATORS);
    7959           14 :           free_dominance_info (CDI_POST_DOMINATORS);
    7960           14 :           mark_virtual_operands_for_renaming (cfun);
    7961           14 :           cleanup_tree_cfg (TODO_update_ssa);
    7962              :         }
    7963           14 :     }
    7964              : 
    7965         7779 :   struct bitint_large_huge large_huge;
    7966         7779 :   bool has_large_huge_parm_result = false;
    7967         7779 :   bool has_large_huge = false;
    7968         7779 :   unsigned int ret = 0, first_large_huge = ~0U;
    7969         7779 :   bool edge_insertions = false;
    7970         7779 :   bool need_vops_update = false;
    7971       135611 :   for (; i < num_ssa_names; ++i)
    7972              :     {
    7973       127832 :       tree s = ssa_name (i);
    7974       127832 :       if (s == NULL)
    7975         4358 :         continue;
    7976       123474 :       tree type = TREE_TYPE (s);
    7977       123474 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    7978              :         {
    7979         5377 :           if (arith_overflow_arg_kind (SSA_NAME_DEF_STMT (s))
    7980              :               >= bitint_prec_large)
    7981         1958 :             has_large_huge = true;
    7982         5377 :           type = TREE_TYPE (type);
    7983              :         }
    7984        74341 :       if (BITINT_TYPE_P (type)
    7985       123501 :           && bitint_precision_kind (type) >= bitint_prec_large)
    7986              :         {
    7987        38944 :           if (first_large_huge == ~0U)
    7988         6191 :             first_large_huge = i;
    7989        38944 :           gimple *stmt = SSA_NAME_DEF_STMT (s), *g;
    7990        38944 :           gimple_stmt_iterator gsi;
    7991        38944 :           tree_code rhs_code;
    7992              :           /* Unoptimize certain constructs to simpler alternatives to
    7993              :              avoid having to lower all of them.  */
    7994        38944 :           if (is_gimple_assign (stmt) && gimple_bb (stmt))
    7995        23357 :             switch (rhs_code = gimple_assign_rhs_code (stmt))
    7996              :               {
    7997              :               default:
    7998              :                 break;
    7999          445 :               case MULT_EXPR:
    8000          445 :               case TRUNC_DIV_EXPR:
    8001          445 :               case EXACT_DIV_EXPR:
    8002          445 :               case TRUNC_MOD_EXPR:
    8003          445 :                 if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s))
    8004              :                   {
    8005            2 :                     location_t loc = gimple_location (stmt);
    8006            2 :                     gsi = gsi_for_stmt (stmt);
    8007            2 :                     tree rhs1 = gimple_assign_rhs1 (stmt);
    8008            2 :                     tree rhs2 = gimple_assign_rhs2 (stmt);
    8009              :                     /* For multiplication and division with (ab)
    8010              :                        lhs and one or both operands force the operands
    8011              :                        into new SSA_NAMEs to avoid coalescing failures.  */
    8012            2 :                     if (TREE_CODE (rhs1) == SSA_NAME
    8013            2 :                         && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1))
    8014              :                       {
    8015            2 :                         first_large_huge = 0;
    8016            2 :                         tree t = make_ssa_name (TREE_TYPE (rhs1));
    8017            2 :                         g = gimple_build_assign (t, SSA_NAME, rhs1);
    8018            2 :                         gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8019            2 :                         gimple_set_location (g, loc);
    8020            2 :                         gimple_assign_set_rhs1 (stmt, t);
    8021            2 :                         if (rhs1 == rhs2)
    8022              :                           {
    8023            0 :                             gimple_assign_set_rhs2 (stmt, t);
    8024            0 :                             rhs2 = t;
    8025              :                           }
    8026            2 :                         update_stmt (stmt);
    8027              :                       }
    8028            2 :                     if (TREE_CODE (rhs2) == SSA_NAME
    8029            2 :                         && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs2))
    8030              :                       {
    8031            0 :                         first_large_huge = 0;
    8032            0 :                         tree t = make_ssa_name (TREE_TYPE (rhs2));
    8033            0 :                         g = gimple_build_assign (t, SSA_NAME, rhs2);
    8034            0 :                         gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8035            0 :                         gimple_set_location (g, loc);
    8036            0 :                         gimple_assign_set_rhs2 (stmt, t);
    8037            0 :                         update_stmt (stmt);
    8038              :                       }
    8039              :                   }
    8040              :                 break;
    8041            3 :               case LROTATE_EXPR:
    8042            3 :               case RROTATE_EXPR:
    8043            3 :                 {
    8044            3 :                   first_large_huge = 0;
    8045            3 :                   location_t loc = gimple_location (stmt);
    8046            3 :                   gsi = gsi_for_stmt (stmt);
    8047            3 :                   tree lhs = gimple_assign_lhs (stmt);
    8048            3 :                   if (has_zero_uses (lhs))
    8049              :                     {
    8050            0 :                       gsi_remove (&gsi, true);
    8051            0 :                       release_ssa_name (lhs);
    8052            0 :                       break;
    8053              :                     }
    8054            3 :                   tree rhs1 = gimple_assign_rhs1 (stmt);
    8055            3 :                   tree type = TREE_TYPE (rhs1);
    8056            3 :                   tree n = gimple_assign_rhs2 (stmt), m;
    8057            3 :                   tree p = build_int_cst (TREE_TYPE (n),
    8058            3 :                                           TYPE_PRECISION (type));
    8059            3 :                   if (TREE_CODE (n) == INTEGER_CST)
    8060              :                     {
    8061            0 :                       if (integer_zerop (n))
    8062              :                         m = n;
    8063              :                       else
    8064            0 :                         m = fold_build2 (MINUS_EXPR, TREE_TYPE (n), p, n);
    8065              :                     }
    8066              :                   else
    8067              :                     {
    8068            3 :                       tree tem = make_ssa_name (TREE_TYPE (n));
    8069            3 :                       g = gimple_build_assign (tem, MINUS_EXPR, p, n);
    8070            3 :                       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8071            3 :                       gimple_set_location (g, loc);
    8072            3 :                       m = make_ssa_name (TREE_TYPE (n));
    8073            3 :                       g = gimple_build_assign (m, TRUNC_MOD_EXPR, tem, p);
    8074            3 :                       gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8075            3 :                       gimple_set_location (g, loc);
    8076              :                     }
    8077            3 :                   if (!TYPE_UNSIGNED (type))
    8078              :                     {
    8079            0 :                       tree utype = build_bitint_type (TYPE_PRECISION (type),
    8080              :                                                       1);
    8081            0 :                       if (TREE_CODE (rhs1) == INTEGER_CST)
    8082            0 :                         rhs1 = fold_convert (utype, rhs1);
    8083              :                       else
    8084              :                         {
    8085            0 :                           tree t = make_ssa_name (utype);
    8086            0 :                           g = gimple_build_assign (t, NOP_EXPR, rhs1);
    8087            0 :                           gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8088            0 :                           gimple_set_location (g, loc);
    8089            0 :                           rhs1 = t;
    8090              :                         }
    8091              :                     }
    8092            3 :                   gassign *a
    8093            4 :                     = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)),
    8094              :                                            rhs_code == LROTATE_EXPR
    8095              :                                            ? LSHIFT_EXPR : RSHIFT_EXPR,
    8096              :                                            rhs1, n);
    8097            3 :                   gsi_insert_before (&gsi, a, GSI_SAME_STMT);
    8098            3 :                   gimple_set_location (a, loc);
    8099            3 :                   tree op1 = gimple_assign_lhs (a);
    8100            4 :                   a = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)),
    8101              :                                            rhs_code == LROTATE_EXPR
    8102              :                                            ? RSHIFT_EXPR : LSHIFT_EXPR,
    8103              :                                            rhs1, m);
    8104            3 :                   gsi_insert_before (&gsi, a, GSI_SAME_STMT);
    8105            3 :                   gimple_set_location (a, loc);
    8106            3 :                   tree op2 = gimple_assign_lhs (a);
    8107            3 :                   if (!TYPE_UNSIGNED (type))
    8108              :                     {
    8109            0 :                       a = gimple_build_assign (make_ssa_name (TREE_TYPE (op1)),
    8110              :                                                BIT_IOR_EXPR, op1, op2);
    8111            0 :                       gsi_insert_before (&gsi, a, GSI_SAME_STMT);
    8112            0 :                       gimple_set_location (a, loc);
    8113            0 :                       a = gimple_build_assign (lhs, NOP_EXPR,
    8114              :                                                gimple_assign_lhs (a));
    8115              :                     }
    8116              :                   else
    8117            3 :                     a = gimple_build_assign (lhs, BIT_IOR_EXPR, op1, op2);
    8118            3 :                   gsi_replace (&gsi, a, true);
    8119            3 :                   gimple_set_location (a, loc);
    8120              :                 }
    8121            3 :                 break;
    8122           18 :               case ABS_EXPR:
    8123           18 :               case ABSU_EXPR:
    8124           18 :               case MIN_EXPR:
    8125           18 :               case MAX_EXPR:
    8126           18 :               case COND_EXPR:
    8127           18 :                 first_large_huge = 0;
    8128           18 :                 gsi = gsi_for_stmt (stmt);
    8129           18 :                 tree lhs = gimple_assign_lhs (stmt);
    8130           18 :                 if (has_zero_uses (lhs))
    8131              :                   {
    8132            1 :                     gsi_remove (&gsi, true);
    8133            1 :                     release_ssa_name (lhs);
    8134            1 :                     break;
    8135              :                   }
    8136           17 :                 tree rhs1 = gimple_assign_rhs1 (stmt), rhs2 = NULL_TREE;
    8137           17 :                 location_t loc = gimple_location (stmt);
    8138           17 :                 if (rhs_code == ABS_EXPR)
    8139            4 :                   g = gimple_build_cond (LT_EXPR, rhs1,
    8140            4 :                                          build_zero_cst (TREE_TYPE (rhs1)),
    8141              :                                          NULL_TREE, NULL_TREE);
    8142           13 :                 else if (rhs_code == ABSU_EXPR)
    8143              :                   {
    8144            4 :                     rhs2 = make_ssa_name (TREE_TYPE (lhs));
    8145            4 :                     g = gimple_build_assign (rhs2, NOP_EXPR, rhs1);
    8146            4 :                     gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8147            4 :                     gimple_set_location (g, loc);
    8148            4 :                     g = gimple_build_cond (LT_EXPR, rhs1,
    8149            4 :                                            build_zero_cst (TREE_TYPE (rhs1)),
    8150              :                                            NULL_TREE, NULL_TREE);
    8151            4 :                     rhs1 = rhs2;
    8152              :                   }
    8153            9 :                 else if (rhs_code == MIN_EXPR || rhs_code == MAX_EXPR)
    8154              :                   {
    8155            9 :                     rhs2 = gimple_assign_rhs2 (stmt);
    8156            9 :                     if (TREE_CODE (rhs1) == INTEGER_CST)
    8157            0 :                       std::swap (rhs1, rhs2);
    8158            9 :                     g = gimple_build_cond (LT_EXPR, rhs1, rhs2,
    8159              :                                            NULL_TREE, NULL_TREE);
    8160            9 :                     if (rhs_code == MAX_EXPR)
    8161            5 :                       std::swap (rhs1, rhs2);
    8162              :                   }
    8163              :                 else
    8164              :                   {
    8165            0 :                     g = gimple_build_cond (NE_EXPR, rhs1,
    8166            0 :                                            build_zero_cst (TREE_TYPE (rhs1)),
    8167              :                                            NULL_TREE, NULL_TREE);
    8168            0 :                     rhs1 = gimple_assign_rhs2 (stmt);
    8169            0 :                     rhs2 = gimple_assign_rhs3 (stmt);
    8170              :                   }
    8171           17 :                 gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8172           17 :                 gimple_set_location (g, loc);
    8173           17 :                 edge e1 = split_block (gsi_bb (gsi), g);
    8174           17 :                 edge e2 = split_block (e1->dest, (gimple *) NULL);
    8175           17 :                 edge e3 = make_edge (e1->src, e2->dest, EDGE_FALSE_VALUE);
    8176           17 :                 e3->probability = profile_probability::even ();
    8177           17 :                 e1->flags = EDGE_TRUE_VALUE;
    8178           17 :                 e1->probability = e3->probability.invert ();
    8179           17 :                 if (dom_info_available_p (CDI_DOMINATORS))
    8180            9 :                   set_immediate_dominator (CDI_DOMINATORS, e2->dest, e1->src);
    8181           17 :                 if (rhs_code == ABS_EXPR || rhs_code == ABSU_EXPR)
    8182              :                   {
    8183            8 :                     gsi = gsi_after_labels (e1->dest);
    8184            8 :                     gassign *a
    8185            8 :                       = gimple_build_assign (make_ssa_name (TREE_TYPE (rhs1)),
    8186              :                                              NEGATE_EXPR, rhs1);
    8187            8 :                     gsi_insert_before (&gsi, a, GSI_SAME_STMT);
    8188            8 :                     gimple_set_location (a, loc);
    8189            8 :                     rhs2 = gimple_assign_lhs (a);
    8190            8 :                     std::swap (rhs1, rhs2);
    8191              :                   }
    8192           17 :                 gsi = gsi_for_stmt (stmt);
    8193           17 :                 gsi_remove (&gsi, true);
    8194           17 :                 gphi *phi = create_phi_node (lhs, e2->dest);
    8195           17 :                 add_phi_arg (phi, rhs1, e2, UNKNOWN_LOCATION);
    8196           17 :                 add_phi_arg (phi, rhs2, e3, UNKNOWN_LOCATION);
    8197           17 :                 break;
    8198              :               }
    8199        15587 :           else if (gimple_call_internal_p (stmt, IFN_CLMUL_WIDEN))
    8200              :             {
    8201              :               /* For now, lower this to two IFN_CLMUL and three
    8202              :                  IFN_BITREVERSE calls.  Could be implemented in
    8203              :                  lower_clmul too, just needs special care on padding
    8204              :                  bits and split the shifting into up to two disjunct
    8205              :                  results, or treat result as 2*prec array and adjust
    8206              :                  afterwards.  */
    8207           10 :               first_large_huge = 0;
    8208           10 :               location_t loc = gimple_location (stmt);
    8209           10 :               tree arg0 = gimple_call_arg (stmt, 0);
    8210           10 :               tree arg1 = gimple_call_arg (stmt, 1);
    8211           10 :               tree type = TREE_TYPE (arg0);
    8212           10 :               gsi = gsi_for_stmt (stmt);
    8213           10 :               gimple *g = gimple_build_call_internal (IFN_CLMUL, 2,
    8214              :                                                       arg0, arg1);
    8215           10 :               tree real = make_ssa_name (type);
    8216           10 :               gimple_call_set_lhs (g, real);
    8217           10 :               gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8218           10 :               gimple_set_location (g, loc);
    8219           10 :               g = gimple_build_call_internal (IFN_BITREVERSE, 1, arg0);
    8220           10 :               tree rarg0 = make_ssa_name (type);
    8221           10 :               gimple_call_set_lhs (g, rarg0);
    8222           10 :               gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8223           10 :               gimple_set_location (g, loc);
    8224           10 :               g = gimple_build_call_internal (IFN_BITREVERSE, 1, arg1);
    8225           10 :               tree rarg1 = make_ssa_name (type);
    8226           10 :               gimple_call_set_lhs (g, rarg1);
    8227           10 :               gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8228           10 :               gimple_set_location (g, loc);
    8229           10 :               g = gimple_build_call_internal (IFN_CLMUL, 2, rarg0, rarg1);
    8230           10 :               tree rimag = make_ssa_name (type);
    8231           10 :               gimple_call_set_lhs (g, rimag);
    8232           10 :               gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8233           10 :               gimple_set_location (g, loc);
    8234           10 :               g = gimple_build_call_internal (IFN_BITREVERSE, 1, rimag);
    8235           10 :               tree imag = make_ssa_name (type);
    8236           10 :               gimple_call_set_lhs (g, imag);
    8237           10 :               gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8238           10 :               gimple_set_location (g, loc);
    8239           10 :               g = gimple_build_assign (make_ssa_name (type), RSHIFT_EXPR, imag,
    8240              :                                        build_one_cst (unsigned_type_node));
    8241           10 :               gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8242           10 :               gimple_set_location (g, loc);
    8243           10 :               g = gimple_build_assign (gimple_call_lhs (stmt), COMPLEX_EXPR,
    8244              :                                        real, gimple_assign_lhs (g));
    8245           10 :               gimple_set_location (g, loc);
    8246           10 :               gsi_replace (&gsi, g, true);
    8247              :             }
    8248        15577 :           else if (gimple_call_internal_p (stmt, IFN_BITCOMPRESS)
    8249        15577 :                    || gimple_call_internal_p (stmt, IFN_BITEXPAND))
    8250              :             {
    8251           26 :               first_large_huge = 0;
    8252           26 :               if (gimple_call_internal_p (stmt, IFN_BITEXPAND))
    8253           14 :                 need_vops_update = true;
    8254           26 :               lower_bitcompress_bitexpand (stmt);
    8255              :             }
    8256        15551 :           else if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s)
    8257           76 :                    && is_gimple_call (stmt)
    8258        15571 :                    && gimple_call_internal_p (stmt))
    8259           20 :             switch (gimple_call_internal_fn (stmt))
    8260              :               {
    8261           12 :               case IFN_UBSAN_CHECK_ADD:
    8262           12 :               case IFN_UBSAN_CHECK_SUB:
    8263           12 :                 if (!bitint_big_endian)
    8264              :                   break;
    8265              :                 /* FALLTHRU */
    8266              :               case IFN_UBSAN_CHECK_MUL:
    8267              :               case IFN_BSWAP:
    8268              :               case IFN_BITREVERSE:
    8269              :               case IFN_CLMUL:
    8270           22 :                 for (unsigned i = 0; i < gimple_call_num_args (stmt); ++i)
    8271              :                   {
    8272           14 :                     location_t loc = gimple_location (stmt);
    8273           14 :                     gsi = gsi_for_stmt (stmt);
    8274              :                     /* Similar case to multiplication/division with (ab)
    8275              :                        above for internal functions which set muldiv_p.  */
    8276           14 :                     tree arg = gimple_call_arg (stmt, i);
    8277           14 :                     if (TREE_CODE (arg) == SSA_NAME
    8278           14 :                         && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (arg))
    8279              :                       {
    8280            8 :                         first_large_huge = 0;
    8281            8 :                         tree t = make_ssa_name (TREE_TYPE (arg));
    8282            8 :                         g = gimple_build_assign (t, SSA_NAME, arg);
    8283            8 :                         gsi_insert_before (&gsi, g, GSI_SAME_STMT);
    8284            8 :                         gimple_set_location (g, loc);
    8285            8 :                         gimple_call_set_arg (stmt, i, t);
    8286            8 :                         if (i == 0
    8287            8 :                             && gimple_call_num_args (stmt) >= 2
    8288           14 :                             && gimple_call_arg (stmt, 1) == arg)
    8289            0 :                           gimple_call_set_arg (stmt, 1, t);
    8290            8 :                         update_stmt (stmt);
    8291              :                       }
    8292              :                   }
    8293              :                 break;
    8294              :               default:
    8295              :                 break;
    8296              :               }
    8297        39955 :           else if (gphi *phi = dyn_cast <gphi *> (stmt))
    8298              :             {
    8299              :               /* Remove PHIs with no uses, coalescing apparently
    8300              :                  relies on this.  */
    8301         1011 :               if (has_zero_uses (s))
    8302              :                 {
    8303            8 :                   remove_gimple_phi_args (phi);
    8304            8 :                   gsi = gsi_for_stmt (stmt);
    8305            8 :                   remove_phi_node (&gsi, true);
    8306              :                 }
    8307              :             }
    8308              :         }
    8309              :       /* We need to also rewrite stores of large/huge _BitInt INTEGER_CSTs
    8310              :          into memory.  Such functions could have no large/huge SSA_NAMEs.  */
    8311        84530 :       else if (SSA_NAME_IS_VIRTUAL_OPERAND (s))
    8312              :         {
    8313        54079 :           auto *g = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (s));
    8314        17507 :           if (g && gimple_store_p (g))
    8315              :             {
    8316        17507 :               tree t = gimple_assign_rhs1 (g);
    8317        19943 :               if (BITINT_TYPE_P (TREE_TYPE (t))
    8318        17507 :                   && (bitint_precision_kind (TREE_TYPE (t))
    8319              :                       >= bitint_prec_large))
    8320        12003 :                 has_large_huge = true;
    8321              :             }
    8322              :         }
    8323              :       /* Similarly, e.g. with -frounding-math casts from _BitInt INTEGER_CSTs
    8324              :          to floating point types need to be rewritten.  */
    8325        30451 :       else if (SCALAR_FLOAT_TYPE_P (type))
    8326              :         {
    8327       128345 :           auto *g = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (s));
    8328          769 :           if (g && gimple_assign_rhs_code (g) == FLOAT_EXPR)
    8329              :             {
    8330          187 :               tree t = gimple_assign_rhs1 (g);
    8331          187 :               if (TREE_CODE (t) == INTEGER_CST
    8332            1 :                   && BITINT_TYPE_P (TREE_TYPE (t))
    8333          188 :                   && (bitint_precision_kind (TREE_TYPE (t))
    8334              :                       >= bitint_prec_large))
    8335            1 :                 has_large_huge = true;
    8336              :             }
    8337              :         }
    8338              :     }
    8339         7779 :   if (need_vops_update)
    8340           14 :     update_ssa (TODO_update_ssa_only_virtuals);
    8341              : 
    8342         7779 :   auto maybe_optimize_ssa_name
    8343        99983 :     = [&has_large_huge, &has_large_huge_parm_result, &large_huge,
    8344              :        &loop_init_done] (tree s, bool force = false)
    8345              :     {
    8346        99983 :       tree type = TREE_TYPE (s);
    8347        99983 :       if (TREE_CODE (type) == COMPLEX_TYPE)
    8348         4136 :         type = TREE_TYPE (type);
    8349        60363 :       if (BITINT_TYPE_P (type)
    8350       100008 :           && bitint_precision_kind (type) >= bitint_prec_large)
    8351              :         {
    8352        38938 :           use_operand_p use_p;
    8353        38938 :           gimple *use_stmt;
    8354        38938 :           has_large_huge = true;
    8355        38938 :           if (force)
    8356            3 :             goto force_name;
    8357        38935 :           if (optimize
    8358        58430 :               && optimizable_arith_overflow (SSA_NAME_DEF_STMT (s)))
    8359         6944 :             return false;
    8360              :           /* Ignore large/huge _BitInt SSA_NAMEs which have single use in
    8361              :              the same bb and could be handled in the same loop with the
    8362              :              immediate use.  */
    8363        37271 :           if (optimize
    8364        17831 :               && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s)
    8365        17764 :               && single_imm_use (s, &use_p, &use_stmt)
    8366        53764 :               && gimple_bb (SSA_NAME_DEF_STMT (s)) == gimple_bb (use_stmt))
    8367              :             {
    8368        11759 :               if (mergeable_op (SSA_NAME_DEF_STMT (s)))
    8369              :                 {
    8370         2552 :                   if (mergeable_op (use_stmt))
    8371              :                     return false;
    8372          335 :                   tree_code cmp_code = comparison_op (use_stmt, NULL, NULL);
    8373          335 :                   if (cmp_code == EQ_EXPR || cmp_code == NE_EXPR)
    8374              :                     return false;
    8375          308 :                   if (gimple_assign_cast_p (use_stmt))
    8376              :                     {
    8377          133 :                       tree lhs = gimple_assign_lhs (use_stmt);
    8378          266 :                       if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    8379              :                           /* Don't merge with VIEW_CONVERT_EXPRs to
    8380              :                              huge INTEGER_TYPEs used sometimes in memcpy
    8381              :                              expansion.  */
    8382          254 :                           && (TREE_CODE (TREE_TYPE (lhs)) != INTEGER_TYPE
    8383            6 :                               || (TYPE_PRECISION (TREE_TYPE (lhs))
    8384           12 :                                   <= MAX_FIXED_MODE_SIZE)))
    8385              :                         {
    8386          150 :                           if (BITINT_TYPE_P (TREE_TYPE (lhs))
    8387          121 :                               && (bitint_precision_kind (TREE_TYPE (lhs))
    8388              :                                   >= bitint_prec_large))
    8389           91 :                             return false;
    8390              :                           return true;
    8391              :                         }
    8392              :                     }
    8393          175 :                   else if (gimple_store_p (use_stmt)
    8394            0 :                            && is_gimple_assign (use_stmt)
    8395            0 :                            && !gimple_has_volatile_ops (use_stmt)
    8396          175 :                            && !stmt_ends_bb_p (use_stmt))
    8397              :                     return false;
    8398              :                 }
    8399         9394 :               if (gimple_assign_cast_p (SSA_NAME_DEF_STMT (s)))
    8400              :                 {
    8401          887 :                   tree rhs1 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s));
    8402          887 :                   if (TREE_CODE (rhs1) == VIEW_CONVERT_EXPR)
    8403              :                     {
    8404           20 :                       rhs1 = TREE_OPERAND (rhs1, 0);
    8405           20 :                       if (!INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    8406           16 :                           && !POINTER_TYPE_P (TREE_TYPE (rhs1))
    8407           16 :                           && gimple_store_p (use_stmt))
    8408              :                         return false;
    8409              :                     }
    8410         1759 :                   if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
    8411          789 :                       && ((is_gimple_assign (use_stmt)
    8412          742 :                            && (gimple_assign_rhs_code (use_stmt)
    8413              :                                != COMPLEX_EXPR))
    8414           47 :                           || gimple_code (use_stmt) == GIMPLE_COND)
    8415          779 :                       && (!gimple_store_p (use_stmt)
    8416          135 :                           || (is_gimple_assign (use_stmt)
    8417          135 :                               && !gimple_has_volatile_ops (use_stmt)
    8418          135 :                               && !stmt_ends_bb_p (use_stmt)))
    8419         1659 :                       && (TREE_CODE (rhs1) != SSA_NAME
    8420          779 :                           || !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (rhs1)))
    8421              :                     {
    8422          779 :                       if (gassign *use_stmt_a = dyn_cast<gassign *> (use_stmt))
    8423          742 :                         switch (gimple_assign_rhs_code (use_stmt))
    8424              :                           {
    8425           54 :                           case TRUNC_DIV_EXPR:
    8426           54 :                           case EXACT_DIV_EXPR:
    8427           54 :                           case TRUNC_MOD_EXPR:
    8428           54 :                           case FLOAT_EXPR:
    8429              :                             /* For division, modulo and casts to floating
    8430              :                                point, avoid representing unsigned operands
    8431              :                                using negative prec if they were sign-extended
    8432              :                                from narrower precision.  */
    8433           54 :                             if (TYPE_UNSIGNED (TREE_TYPE (s))
    8434           28 :                                 && !TYPE_UNSIGNED (TREE_TYPE (rhs1))
    8435           63 :                                 && (TYPE_PRECISION (TREE_TYPE (s))
    8436            9 :                                     > TYPE_PRECISION (TREE_TYPE (rhs1))))
    8437            8 :                               goto force_name;
    8438              :                             /* FALLTHRU */
    8439          115 :                           case MULT_EXPR:
    8440          130 :                             if (!BITINT_TYPE_P (TREE_TYPE (rhs1))
    8441          115 :                                 || (bitint_precision_kind (TREE_TYPE (rhs1))
    8442              :                                     < bitint_prec_large))
    8443              :                               return true;
    8444              :                             /* Uses which use handle_operand_addr can't
    8445              :                                deal with nested casts.  */
    8446           65 :                             if (TREE_CODE (rhs1) == SSA_NAME
    8447           65 :                                 && gimple_assign_cast_p
    8448           65 :                                      (SSA_NAME_DEF_STMT (rhs1))
    8449           43 :                                 && has_single_use (rhs1)
    8450          108 :                                 && (gimple_bb (SSA_NAME_DEF_STMT (rhs1))
    8451           43 :                                     == gimple_bb (SSA_NAME_DEF_STMT (s))))
    8452           43 :                               goto force_name;
    8453              :                             break;
    8454            0 :                           case VIEW_CONVERT_EXPR:
    8455            0 :                             {
    8456            0 :                               tree lhs = gimple_assign_lhs (use_stmt_a);
    8457              :                               /* Don't merge with VIEW_CONVERT_EXPRs to
    8458              :                                  non-integral types.  */
    8459            0 :                               if (!INTEGRAL_TYPE_P (TREE_TYPE (lhs)))
    8460            0 :                                 goto force_name;
    8461              :                               /* Don't merge with VIEW_CONVERT_EXPRs to
    8462              :                                  huge INTEGER_TYPEs used sometimes in memcpy
    8463              :                                  expansion.  */
    8464            0 :                               if (TREE_CODE (TREE_TYPE (lhs)) == INTEGER_TYPE
    8465            0 :                                   && (TYPE_PRECISION (TREE_TYPE (lhs))
    8466            0 :                                       > MAX_FIXED_MODE_SIZE))
    8467            0 :                                 goto force_name;
    8468              :                             }
    8469              :                             break;
    8470              :                           default:
    8471              :                             break;
    8472              :                         }
    8473          868 :                       if (!BITINT_TYPE_P (TREE_TYPE (rhs1))
    8474          679 :                           || (bitint_precision_kind (TREE_TYPE (rhs1))
    8475              :                               < bitint_prec_large))
    8476              :                         return true;
    8477          425 :                       if ((TYPE_PRECISION (TREE_TYPE (rhs1))
    8478          425 :                            >= TYPE_PRECISION (TREE_TYPE (s)))
    8479          425 :                           && mergeable_op (use_stmt))
    8480              :                         return false;
    8481              :                       /* Prevent merging a widening non-mergeable cast
    8482              :                          on result of some narrower mergeable op
    8483              :                          together with later mergeable operations.  E.g.
    8484              :                          result of _BitInt(223) addition shouldn't be
    8485              :                          sign-extended to _BitInt(513) and have another
    8486              :                          _BitInt(513) added to it, as handle_plus_minus
    8487              :                          with its PHI node handling inside of handle_cast
    8488              :                          will not work correctly.  An exception is if
    8489              :                          use_stmt is a store, this is handled directly
    8490              :                          in lower_mergeable_stmt.  */
    8491          363 :                       if (TREE_CODE (rhs1) != SSA_NAME
    8492          363 :                           || !has_single_use (rhs1)
    8493          277 :                           || (gimple_bb (SSA_NAME_DEF_STMT (rhs1))
    8494          277 :                               != gimple_bb (SSA_NAME_DEF_STMT (s)))
    8495          582 :                           || !mergeable_op (SSA_NAME_DEF_STMT (rhs1)))
    8496              :                         return true;
    8497           87 :                       if (gimple_store_p (use_stmt))
    8498              :                         return false;
    8499            7 :                       if ((TYPE_PRECISION (TREE_TYPE (rhs1))
    8500            7 :                            < TYPE_PRECISION (TREE_TYPE (s)))
    8501            9 :                           && gimple_assign_cast_p (SSA_NAME_DEF_STMT (rhs1)))
    8502              :                         {
    8503              :                           /* Another exception is if the widening cast is
    8504              :                              from mergeable same precision cast from something
    8505              :                              not mergeable.  */
    8506            0 :                           tree rhs2
    8507            0 :                             = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (rhs1));
    8508            0 :                           if (BITINT_TYPE_P (TREE_TYPE (rhs2))
    8509            0 :                               && (TYPE_PRECISION (TREE_TYPE (rhs1))
    8510            0 :                                   == TYPE_PRECISION (TREE_TYPE (rhs2))))
    8511              :                             {
    8512            0 :                               if (TREE_CODE (rhs2) != SSA_NAME
    8513            0 :                                   || !has_single_use (rhs2)
    8514            0 :                                   || (gimple_bb (SSA_NAME_DEF_STMT (rhs2))
    8515            0 :                                       != gimple_bb (SSA_NAME_DEF_STMT (s)))
    8516            0 :                                   || !mergeable_op (SSA_NAME_DEF_STMT (rhs2)))
    8517              :                                 return false;
    8518              :                             }
    8519              :                         }
    8520              :                     }
    8521              :                 }
    8522         8615 :               if (is_gimple_assign (SSA_NAME_DEF_STMT (s)))
    8523         5642 :                 switch (gimple_assign_rhs_code (SSA_NAME_DEF_STMT (s)))
    8524              :                   {
    8525         1815 :                   case REALPART_EXPR:
    8526         1815 :                   case IMAGPART_EXPR:
    8527         1815 :                     {
    8528         1815 :                       gimple *ds = SSA_NAME_DEF_STMT (s);
    8529         1815 :                       tree rhs1 = gimple_assign_rhs1 (ds);
    8530         1815 :                       rhs1 = TREE_OPERAND (rhs1, 0);
    8531         1815 :                       if (TREE_CODE (rhs1) == SSA_NAME)
    8532              :                         {
    8533         1815 :                           gimple *g = SSA_NAME_DEF_STMT (rhs1);
    8534         1815 :                           if (optimizable_arith_overflow (g))
    8535              :                             {
    8536         1650 :                               if (gimple_assign_rhs_code (ds) == IMAGPART_EXPR)
    8537              :                                 return false;
    8538           10 :                               if (gimple_store_p (use_stmt))
    8539              :                                 {
    8540              :                                   /* Punt if the cast use of IMAGPART_EXPR stmt
    8541              :                                      appears before the store use_stmt, because
    8542              :                                      optimizable arith overflow can't be
    8543              :                                      lowered at the store location in that case.
    8544              :                                      See PR121828.  */
    8545           10 :                                   gimple_stmt_iterator gsi
    8546           10 :                                     = gsi_for_stmt (use_stmt);
    8547           10 :                                   unsigned int cnt = 0;
    8548           12 :                                   do
    8549              :                                     {
    8550           12 :                                       gsi_prev_nondebug (&gsi);
    8551           12 :                                       if (gsi_end_p (gsi))
    8552              :                                         break;
    8553           12 :                                       gimple *g2 = gsi_stmt (gsi);
    8554           12 :                                       if (g2 == ds)
    8555              :                                         break;
    8556            3 :                                       if (++cnt == 64)
    8557              :                                         break;
    8558            3 :                                       if (!gimple_assign_cast_p (g2))
    8559            2 :                                         continue;
    8560            1 :                                       tree rhs2 = gimple_assign_rhs1 (g2);
    8561            1 :                                       if (TREE_CODE (rhs2) != SSA_NAME)
    8562            0 :                                         continue;
    8563            1 :                                       auto *g3 = dyn_cast<gassign *>
    8564            1 :                                         (SSA_NAME_DEF_STMT (rhs2));
    8565            1 :                                       if (!g3)
    8566            0 :                                         continue;
    8567            2 :                                       if (gimple_assign_rhs_code (g3)
    8568              :                                           != IMAGPART_EXPR)
    8569            0 :                                         continue;
    8570            1 :                                       rhs2 = gimple_assign_rhs1 (g3);
    8571            1 :                                       rhs2 = TREE_OPERAND (rhs2, 0);
    8572            1 :                                       if (rhs2 != rhs1)
    8573            0 :                                         continue;
    8574              :                                       cnt = 64;
    8575              :                                       break;
    8576              :                                     }
    8577              :                                   while (1);
    8578           10 :                                   if (cnt == 64)
    8579              :                                     break;
    8580              :                                 }
    8581              :                             }
    8582              :                         }
    8583              :                     }
    8584              :                     /* FALLTHRU */
    8585         1021 :                   case LSHIFT_EXPR:
    8586         1021 :                   case RSHIFT_EXPR:
    8587         1021 :                   case MULT_EXPR:
    8588         1021 :                   case TRUNC_DIV_EXPR:
    8589         1021 :                   case EXACT_DIV_EXPR:
    8590         1021 :                   case TRUNC_MOD_EXPR:
    8591         1021 :                   case FIX_TRUNC_EXPR:
    8592         1021 :                     if (gimple_store_p (use_stmt)
    8593          469 :                         && is_gimple_assign (use_stmt)
    8594          469 :                         && !gimple_has_volatile_ops (use_stmt)
    8595         1489 :                         && !stmt_ends_bb_p (use_stmt))
    8596              :                       {
    8597          468 :                         tree lhs = gimple_assign_lhs (use_stmt);
    8598              :                         /* As multiply/division passes address of the lhs
    8599              :                            to library function and that assumes it can extend
    8600              :                            it to whole number of limbs, avoid merging those
    8601              :                            with bit-field stores.  Don't allow it for
    8602              :                            shifts etc. either, so that the bit-field store
    8603              :                            handling doesn't have to be done everywhere.  */
    8604          468 :                         if (TREE_CODE (lhs) == COMPONENT_REF
    8605          468 :                             && DECL_BIT_FIELD_TYPE (TREE_OPERAND (lhs, 1)))
    8606              :                           break;
    8607              :                         return false;
    8608              :                       }
    8609              :                     break;
    8610              :                   default:
    8611              :                     break;
    8612              :                   }
    8613         2973 :               else if (is_gimple_call (SSA_NAME_DEF_STMT (s))
    8614         2973 :                        && gimple_call_internal_p (SSA_NAME_DEF_STMT (s)))
    8615           75 :                 switch (gimple_call_internal_fn (SSA_NAME_DEF_STMT (s)))
    8616              :                   {
    8617           73 :                   case IFN_BSWAP:
    8618           73 :                   case IFN_BITREVERSE:
    8619           73 :                   case IFN_CLMUL:
    8620           73 :                     if (gimple_store_p (use_stmt)
    8621           23 :                         && is_gimple_assign (use_stmt)
    8622           23 :                         && !gimple_has_volatile_ops (use_stmt)
    8623           96 :                         && !stmt_ends_bb_p (use_stmt))
    8624              :                       {
    8625           23 :                         tree lhs = gimple_assign_lhs (use_stmt);
    8626           23 :                         if (TREE_CODE (lhs) == COMPONENT_REF
    8627           23 :                             && DECL_BIT_FIELD_TYPE (TREE_OPERAND (lhs, 1)))
    8628              :                           break;
    8629              :                         return false;
    8630              :                       }
    8631              :                     break;
    8632              :                   default:
    8633              :                     break;
    8634              :                   }
    8635              :             }
    8636              : 
    8637              :           /* Also ignore uninitialized uses.  */
    8638        31999 :           if (SSA_NAME_IS_DEFAULT_DEF (s)
    8639        31999 :               && (!SSA_NAME_VAR (s) || VAR_P (SSA_NAME_VAR (s))))
    8640              :             return false;
    8641              : 
    8642        31994 :         force_name:
    8643        31994 :           if (!large_huge.m_names)
    8644         6068 :             large_huge.m_names = BITMAP_ALLOC (NULL);
    8645        31994 :           bitmap_set_bit (large_huge.m_names, SSA_NAME_VERSION (s));
    8646        31994 :           if (has_single_use (s))
    8647              :             {
    8648              :               tree s2 = s, s3 = s;
    8649              :               /* The coalescing hook special cases SSA_NAME copies.
    8650              :                  Make sure not to mark in m_single_use_names single
    8651              :                  use SSA_NAMEs copied from non-single use SSA_NAMEs.  */
    8652        27610 :               while (gimple_assign_copy_p (SSA_NAME_DEF_STMT (s2)))
    8653              :                 {
    8654         1061 :                   s2 = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (s2));
    8655         1061 :                   if (TREE_CODE (s2) != SSA_NAME)
    8656              :                     break;
    8657          108 :                   if (!has_single_use (s2))
    8658              :                     {
    8659              :                       s2 = NULL_TREE;
    8660              :                       break;
    8661              :                     }
    8662              :                   s3 = s2;
    8663              :                 }
    8664        27568 :               if (s2)
    8665              :                 {
    8666              :                   /* Only set m_single_use_names for SSA_NAMEs where
    8667              :                      the definition and use are within the same loop,
    8668              :                      otherwise if the use could be executed more times
    8669              :                      than the def stmt, we can't emit clobbers.
    8670              :                      Or if irreducible loops are involved, only handle
    8671              :                      same bb definitions.  */
    8672        27502 :                   gimple *def = SSA_NAME_DEF_STMT (s3), *use;
    8673        27502 :                   use_operand_p use_p;
    8674        27502 :                   single_imm_use (s, &use_p, &use);
    8675        27502 :                   basic_block def_bb, use_bb;
    8676        27502 :                   if (SSA_NAME_IS_DEFAULT_DEF (s3))
    8677              :                     def_bb = NULL;
    8678              :                   else
    8679        22113 :                     def_bb = gimple_bb (def);
    8680        27502 :                   use_bb = gimple_bb (use);
    8681        27502 :                   if (def_bb != use_bb)
    8682              :                     {
    8683         7450 :                       if (!loop_init_done)
    8684              :                         {
    8685         4363 :                           unsigned flags
    8686              :                             = (AVOID_CFG_MODIFICATIONS
    8687              :                                | LOOPS_HAVE_MARKED_IRREDUCIBLE_REGIONS);
    8688         4363 :                           loop_optimizer_init (flags);
    8689         4363 :                           loop_init_done = true;
    8690              :                         }
    8691         7450 :                       if ((use_bb->flags & BB_IRREDUCIBLE_LOOP) == 0)
    8692              :                         {
    8693         7402 :                           class loop *def_loop
    8694         7402 :                             = def_bb ? def_bb->loop_father
    8695         7402 :                                      : get_loop (cfun, 0);
    8696         7402 :                           class loop *use_loop = use_bb->loop_father;
    8697         7402 :                           if (def_loop == use_loop)
    8698        27502 :                             def_bb = use_bb;
    8699              :                         }
    8700              :                     }
    8701        27502 :                   if (def_bb == use_bb)
    8702              :                     {
    8703        27211 :                       if (!large_huge.m_single_use_names)
    8704         5893 :                         large_huge.m_single_use_names = BITMAP_ALLOC (NULL);
    8705        27211 :                       bitmap_set_bit (large_huge.m_single_use_names,
    8706        27211 :                                       SSA_NAME_VERSION (s));
    8707              :                     }
    8708              :                 }
    8709              :             }
    8710        31994 :           if (SSA_NAME_VAR (s)
    8711         8774 :               && ((TREE_CODE (SSA_NAME_VAR (s)) == PARM_DECL
    8712         5851 :                    && SSA_NAME_IS_DEFAULT_DEF (s))
    8713         3027 :                   || TREE_CODE (SSA_NAME_VAR (s)) == RESULT_DECL))
    8714         5747 :             has_large_huge_parm_result = true;
    8715        31994 :           if (optimize
    8716        12554 :               && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s)
    8717        12487 :               && gimple_assign_load_p (SSA_NAME_DEF_STMT (s))
    8718         6156 :               && !gimple_has_volatile_ops (SSA_NAME_DEF_STMT (s))
    8719        35015 :               && !stmt_ends_bb_p (SSA_NAME_DEF_STMT (s)))
    8720              :             {
    8721         3021 :               use_operand_p use_p;
    8722         3021 :               imm_use_iterator iter;
    8723         3021 :               bool optimizable_load = true;
    8724         6120 :               FOR_EACH_IMM_USE_FAST (use_p, iter, s)
    8725              :                 {
    8726         3200 :                   gimple *use_stmt = USE_STMT (use_p);
    8727         3200 :                   if (is_gimple_debug (use_stmt))
    8728            0 :                     continue;
    8729         3200 :                   if (is_gimple_call (use_stmt)
    8730         3200 :                       && gimple_call_internal_p (use_stmt))
    8731           66 :                     switch (gimple_call_internal_fn (use_stmt))
    8732              :                       {
    8733           10 :                       case IFN_CLZ:
    8734           10 :                       case IFN_CTZ:
    8735           10 :                       case IFN_CLRSB:
    8736           10 :                       case IFN_FFS:
    8737           10 :                       case IFN_PARITY:
    8738           10 :                       case IFN_POPCOUNT:
    8739           10 :                       case IFN_BSWAP:
    8740           10 :                       case IFN_BITREVERSE:
    8741           10 :                       case IFN_CLMUL:
    8742           10 :                         continue;
    8743              :                       default:
    8744              :                         break;
    8745              :                       }
    8746         3190 :                   if (gimple_code (use_stmt) == GIMPLE_PHI
    8747              :                       || is_gimple_call (use_stmt)
    8748              :                       || gimple_code (use_stmt) == GIMPLE_ASM
    8749              :                       || (is_gimple_assign (use_stmt)
    8750         1940 :                           && (gimple_assign_rhs_code (use_stmt)
    8751              :                               == COMPLEX_EXPR)))
    8752              :                     {
    8753              :                       optimizable_load = false;
    8754              :                       break;
    8755              :                     }
    8756         3021 :                 }
    8757              : 
    8758         3021 :               ssa_op_iter oi;
    8759         4085 :               FOR_EACH_SSA_USE_OPERAND (use_p, SSA_NAME_DEF_STMT (s),
    8760              :                                         oi, SSA_OP_USE)
    8761              :                 {
    8762         1064 :                   tree s2 = USE_FROM_PTR (use_p);
    8763         1064 :                   if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (s2))
    8764              :                     {
    8765              :                       optimizable_load = false;
    8766              :                       break;
    8767              :                     }
    8768              :                 }
    8769              : 
    8770         3021 :               if (optimizable_load && !stmt_ends_bb_p (SSA_NAME_DEF_STMT (s)))
    8771              :                 {
    8772         2920 :                   if (!large_huge.m_loads)
    8773          333 :                     large_huge.m_loads = BITMAP_ALLOC (NULL);
    8774         2920 :                   bitmap_set_bit (large_huge.m_loads, SSA_NAME_VERSION (s));
    8775              :                 }
    8776              :             }
    8777              :         }
    8778              :       /* We need to also rewrite stores of large/huge _BitInt INTEGER_CSTs
    8779              :          into memory.  Such functions could have no large/huge SSA_NAMEs.  */
    8780        61045 :       else if (SSA_NAME_IS_VIRTUAL_OPERAND (s))
    8781              :         {
    8782        43134 :           gassign *g = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (s));
    8783        14766 :           if (g && gimple_store_p (g))
    8784              :             {
    8785        14766 :               tree t = gimple_assign_rhs1 (g);
    8786        16826 :               if (BITINT_TYPE_P (TREE_TYPE (t))
    8787        14766 :                   && bitint_precision_kind (TREE_TYPE (t)) >= bitint_prec_large)
    8788        11892 :                 has_large_huge = true;
    8789              :             }
    8790              :         }
    8791              :       return false;
    8792         7779 :     };
    8793         7779 :   auto_vec<tree, 16> ssa_names_to_reconsider;
    8794       111798 :   for (i = first_large_huge; i < num_ssa_names; ++i)
    8795              :     {
    8796       104019 :       tree s = ssa_name (i);
    8797       104019 :       if (s == NULL)
    8798         4039 :         continue;
    8799              :       /* Try to prevent cases where single use of s in the same bb is
    8800              :          something unimplementable by m_upwards_2limb (so something not
    8801              :          handleable by lower_mergeable_stmt or lower_addsub_overflow or
    8802              :          lower_bit_query) but is supposed to be merged with something which
    8803              :          relies on m_upwards_2limb (handle_plus_minus, handle_lshift).  */
    8804        99980 :       if (maybe_optimize_ssa_name (s)
    8805        99980 :           && requires_upwards_2limb (large_huge, SSA_NAME_DEF_STMT (s)))
    8806            3 :         ssa_names_to_reconsider.safe_push (s);
    8807              :     }
    8808        23340 :   for (tree s : ssa_names_to_reconsider)
    8809            3 :     if (requires_upwards_2limb (large_huge, SSA_NAME_DEF_STMT (s)))
    8810            3 :       maybe_optimize_ssa_name (s, true);
    8811              : 
    8812         7779 :   if (large_huge.m_names || has_large_huge)
    8813              :     {
    8814         6278 :       ret = TODO_update_ssa_only_virtuals | TODO_cleanup_cfg;
    8815         6278 :       calculate_dominance_info (CDI_DOMINATORS);
    8816         6278 :       if (optimize)
    8817         3455 :         enable_ranger (cfun);
    8818         6278 :       if (large_huge.m_loads)
    8819              :         {
    8820          333 :           basic_block entry = ENTRY_BLOCK_PTR_FOR_FN (cfun);
    8821          333 :           entry->aux = NULL;
    8822          666 :           bitint_dom_walker (large_huge.m_names,
    8823          333 :                              large_huge.m_loads).walk (entry);
    8824          333 :           bitmap_and_compl_into (large_huge.m_names, large_huge.m_loads);
    8825          333 :           clear_aux_for_blocks ();
    8826          333 :           BITMAP_FREE (large_huge.m_loads);
    8827              :         }
    8828         6278 :       large_huge.m_limb_type = build_nonstandard_integer_type (limb_prec, 1);
    8829         6278 :       large_huge.m_limb_size
    8830         6278 :         = tree_to_uhwi (TYPE_SIZE_UNIT (large_huge.m_limb_type));
    8831              :     }
    8832         7779 :   if (large_huge.m_names)
    8833              :     {
    8834         6068 :       large_huge.m_map
    8835        12136 :         = init_var_map (num_ssa_names, NULL, large_huge.m_names);
    8836         6068 :       coalesce_ssa_name (large_huge.m_map);
    8837         6068 :       partition_view_normal (large_huge.m_map);
    8838         6068 :       if (dump_file && (dump_flags & TDF_DETAILS))
    8839              :         {
    8840            0 :           fprintf (dump_file, "After Coalescing:\n");
    8841            0 :           dump_var_map (dump_file, large_huge.m_map);
    8842              :         }
    8843         6068 :       large_huge.m_vars
    8844         6068 :         = XCNEWVEC (tree, num_var_partitions (large_huge.m_map));
    8845         6068 :       bitmap_iterator bi;
    8846         6068 :       if (has_large_huge_parm_result)
    8847        21390 :         EXECUTE_IF_SET_IN_BITMAP (large_huge.m_names, 0, i, bi)
    8848              :           {
    8849        16945 :             tree s = ssa_name (i);
    8850        16945 :             if (SSA_NAME_VAR (s)
    8851         7188 :                 && ((TREE_CODE (SSA_NAME_VAR (s)) == PARM_DECL
    8852         5851 :                      && SSA_NAME_IS_DEFAULT_DEF (s))
    8853         1441 :                     || TREE_CODE (SSA_NAME_VAR (s)) == RESULT_DECL))
    8854              :               {
    8855         5747 :                 int p = var_to_partition (large_huge.m_map, s);
    8856         5747 :                 if (large_huge.m_vars[p] == NULL_TREE)
    8857              :                   {
    8858         5747 :                     large_huge.m_vars[p] = SSA_NAME_VAR (s);
    8859         5747 :                     mark_addressable (SSA_NAME_VAR (s));
    8860              :                   }
    8861              :               }
    8862              :           }
    8863         6068 :       tree atype = NULL_TREE;
    8864         6068 :       if (dump_file && (dump_flags & TDF_DETAILS))
    8865            0 :         fprintf (dump_file, "Mapping SSA_NAMEs to decls:\n");
    8866        35676 :       EXECUTE_IF_SET_IN_BITMAP (large_huge.m_names, 0, i, bi)
    8867              :         {
    8868        29608 :           tree s = ssa_name (i);
    8869        29608 :           int p = var_to_partition (large_huge.m_map, s);
    8870        29608 :           if (large_huge.m_vars[p] == NULL_TREE)
    8871              :             {
    8872        19901 :               if (atype == NULL_TREE
    8873        34705 :                   || !tree_int_cst_equal (TYPE_SIZE (atype),
    8874        14804 :                                           TYPE_SIZE (TREE_TYPE (s))))
    8875              :                 {
    8876         8123 :                   unsigned HOST_WIDE_INT nelts
    8877         8123 :                     = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (s))) / limb_prec;
    8878         8123 :                   atype = build_array_type_nelts (large_huge.m_limb_type,
    8879         8123 :                                                   nelts);
    8880              :                 }
    8881        19901 :               large_huge.m_vars[p] = create_tmp_var (atype, "bitint");
    8882        19901 :               mark_addressable (large_huge.m_vars[p]);
    8883              :             }
    8884        29608 :           if (dump_file && (dump_flags & TDF_DETAILS))
    8885              :             {
    8886            0 :               print_generic_expr (dump_file, s, TDF_SLIM);
    8887            0 :               fprintf (dump_file, " -> ");
    8888            0 :               print_generic_expr (dump_file, large_huge.m_vars[p], TDF_SLIM);
    8889            0 :               fprintf (dump_file, "\n");
    8890              :             }
    8891              :         }
    8892              :     }
    8893              : 
    8894        49664 :   FOR_EACH_BB_REVERSE_FN (bb, cfun)
    8895              :     {
    8896        41885 :       gimple_stmt_iterator prev;
    8897       210688 :       for (gimple_stmt_iterator gsi = gsi_last_bb (bb); !gsi_end_p (gsi);
    8898       126918 :            gsi = prev)
    8899              :         {
    8900       126918 :           prev = gsi;
    8901       126918 :           gsi_prev (&prev);
    8902       126918 :           ssa_op_iter iter;
    8903       126918 :           gimple *stmt = gsi_stmt (gsi);
    8904       126918 :           if (is_gimple_debug (stmt))
    8905        81941 :             continue;
    8906       121119 :           bitint_prec_kind kind = bitint_prec_small;
    8907       121119 :           tree t;
    8908       364599 :           FOR_EACH_SSA_TREE_OPERAND (t, stmt, iter, SSA_OP_ALL_OPERANDS)
    8909       243480 :             if (BITINT_TYPE_P (TREE_TYPE (t)))
    8910              :               {
    8911        83762 :                 bitint_prec_kind this_kind
    8912        83762 :                   = bitint_precision_kind (TREE_TYPE (t));
    8913        83762 :                 kind = MAX (kind, this_kind);
    8914              :               }
    8915       159718 :             else if (TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE
    8916       159718 :                      && BITINT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
    8917              :               {
    8918        15462 :                 bitint_prec_kind this_kind
    8919        15462 :                   = bitint_precision_kind (TREE_TYPE (TREE_TYPE (t)));
    8920       243790 :                 kind = MAX (kind, this_kind);
    8921              :               }
    8922       121119 :           gassign *assign = dyn_cast<gassign *> (stmt);
    8923        64771 :           if (assign && gimple_store_p (assign))
    8924              :             {
    8925        17551 :               t = gimple_assign_rhs1 (assign);
    8926        17551 :               if (BITINT_TYPE_P (TREE_TYPE (t)))
    8927              :                 {
    8928        15089 :                   bitint_prec_kind this_kind
    8929        15089 :                     = bitint_precision_kind (TREE_TYPE (t));
    8930        15089 :                   kind = MAX (kind, this_kind);
    8931              :                 }
    8932              :             }
    8933       185890 :           if (assign && gimple_assign_rhs_code (assign) == FLOAT_EXPR)
    8934              :             {
    8935          189 :               t = gimple_assign_rhs1 (assign);
    8936          218 :               if (BITINT_TYPE_P (TREE_TYPE (t))
    8937          191 :                   && TREE_CODE (t) == INTEGER_CST)
    8938              :                 {
    8939            1 :                   bitint_prec_kind this_kind
    8940            1 :                     = bitint_precision_kind (TREE_TYPE (t));
    8941            1 :                   kind = MAX (kind, this_kind);
    8942              :                 }
    8943              :             }
    8944       121119 :           if (is_gimple_call (stmt))
    8945              :             {
    8946        27202 :               t = gimple_call_lhs (stmt);
    8947        27202 :               if (t && TREE_CODE (TREE_TYPE (t)) == COMPLEX_TYPE)
    8948              :                 {
    8949         5335 :                   bitint_prec_kind this_kind = arith_overflow_arg_kind (stmt);
    8950         5335 :                   kind = MAX (kind, this_kind);
    8951         5335 :                   if (BITINT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
    8952              :                     {
    8953         5210 :                       this_kind
    8954         5210 :                         = bitint_precision_kind (TREE_TYPE (TREE_TYPE (t)));
    8955         5210 :                       kind = MAX (kind, this_kind);
    8956              :                     }
    8957              :                 }
    8958              :             }
    8959       120797 :           if (kind == bitint_prec_small)
    8960        48910 :             continue;
    8961        72209 :           switch (gimple_code (stmt))
    8962              :             {
    8963        11672 :             case GIMPLE_CALL:
    8964              :               /* For now.  We'll need to handle some internal functions and
    8965              :                  perhaps some builtins.  */
    8966        11672 :               if (kind == bitint_prec_middle)
    8967         2298 :                 continue;
    8968              :               break;
    8969            4 :             case GIMPLE_ASM:
    8970            4 :               if (kind == bitint_prec_middle)
    8971            1 :                 continue;
    8972              :               break;
    8973         1130 :             case GIMPLE_RETURN:
    8974         1130 :               continue;
    8975        50277 :             case GIMPLE_ASSIGN:
    8976        50277 :               if (gimple_clobber_p (stmt))
    8977         3521 :                 continue;
    8978        46756 :               if (kind >= bitint_prec_large)
    8979              :                 break;
    8980         8870 :               if (gimple_assign_single_p (stmt))
    8981              :                 /* No need to lower copies, loads or stores.  */
    8982         5828 :                 continue;
    8983         3042 :               if (gimple_assign_cast_p (stmt))
    8984              :                 {
    8985         2449 :                   tree lhs = gimple_assign_lhs (stmt);
    8986         2449 :                   tree rhs = gimple_assign_rhs1 (stmt);
    8987         4898 :                   if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))
    8988         2449 :                       && INTEGRAL_TYPE_P (TREE_TYPE (rhs))
    8989         4892 :                       && (TYPE_PRECISION (TREE_TYPE (lhs))
    8990         2443 :                           == TYPE_PRECISION (TREE_TYPE (rhs))))
    8991              :                     /* No need to lower casts to same precision.  */
    8992           35 :                     continue;
    8993              :                 }
    8994              :               break;
    8995              :             default:
    8996              :               break;
    8997         1130 :             }
    8998              : 
    8999        12133 :           if (kind == bitint_prec_middle)
    9000              :             {
    9001         5151 :               tree type = NULL_TREE;
    9002              :               /* Middle _BitInt(N) is rewritten to casts to INTEGER_TYPEs
    9003              :                  with the same precision and back.  */
    9004         5151 :               unsigned int nops = gimple_num_ops (stmt);
    9005        17279 :               for (unsigned int i = is_gimple_assign (stmt) ? 1 : 0;
    9006        17279 :                    i < nops; ++i)
    9007        12128 :                 if (tree op = gimple_op (stmt, i))
    9008              :                   {
    9009         7866 :                     tree nop = maybe_cast_middle_bitint (&gsi, op, type);
    9010         7866 :                     if (nop != op)
    9011         6891 :                       gimple_set_op (stmt, i, nop);
    9012          975 :                     else if (COMPARISON_CLASS_P (op))
    9013              :                       {
    9014            0 :                         TREE_OPERAND (op, 0)
    9015            0 :                           = maybe_cast_middle_bitint (&gsi,
    9016            0 :                                                       TREE_OPERAND (op, 0),
    9017              :                                                       type);
    9018            0 :                         TREE_OPERAND (op, 1)
    9019            0 :                           = maybe_cast_middle_bitint (&gsi,
    9020            0 :                                                       TREE_OPERAND (op, 1),
    9021              :                                                       type);
    9022              :                       }
    9023          975 :                     else if (TREE_CODE (op) == CASE_LABEL_EXPR)
    9024              :                       {
    9025          100 :                         CASE_LOW (op)
    9026          100 :                           = maybe_cast_middle_bitint (&gsi, CASE_LOW (op),
    9027              :                                                       type);
    9028          200 :                         CASE_HIGH (op)
    9029          200 :                           = maybe_cast_middle_bitint (&gsi, CASE_HIGH (op),
    9030              :                                                       type);
    9031              :                       }
    9032              :                   }
    9033         5151 :               if (tree lhs = gimple_get_lhs (stmt))
    9034         4593 :                 if (BITINT_TYPE_P (TREE_TYPE (lhs))
    9035         3007 :                     && (bitint_precision_kind (TREE_TYPE (lhs))
    9036              :                         == bitint_prec_middle))
    9037              :                   {
    9038         1409 :                     int prec = TYPE_PRECISION (TREE_TYPE (lhs));
    9039         1409 :                     int uns = TYPE_UNSIGNED (TREE_TYPE (lhs));
    9040         1409 :                     type = build_nonstandard_integer_type (prec, uns);
    9041         1409 :                     tree lhs2 = make_ssa_name (type);
    9042         1409 :                     gimple_set_lhs (stmt, lhs2);
    9043         1409 :                     gimple *g = gimple_build_assign (lhs, NOP_EXPR, lhs2);
    9044         1409 :                     if (stmt_ends_bb_p (stmt))
    9045              :                       {
    9046            4 :                         edge e = find_fallthru_edge (gsi_bb (gsi)->succs);
    9047            4 :                         gsi_insert_on_edge (e, g);
    9048            4 :                         edge_insertions = true;
    9049              :                       }
    9050              :                     else
    9051         1405 :                       gsi_insert_after (&gsi, g, GSI_SAME_STMT);
    9052              :                   }
    9053         5151 :               update_stmt (stmt);
    9054         5151 :               continue;
    9055         5151 :             }
    9056              : 
    9057        54245 :           if (tree lhs = gimple_get_lhs (stmt))
    9058        47129 :             if (TREE_CODE (lhs) == SSA_NAME)
    9059              :               {
    9060        37807 :                 tree type = TREE_TYPE (lhs);
    9061        37807 :                 if (TREE_CODE (type) == COMPLEX_TYPE)
    9062         4241 :                   type = TREE_TYPE (type);
    9063         5508 :                 if (BITINT_TYPE_P (type)
    9064        32311 :                     && bitint_precision_kind (type) >= bitint_prec_large
    9065        69915 :                     && (large_huge.m_names == NULL
    9066        31903 :                         || !bitmap_bit_p (large_huge.m_names,
    9067        31903 :                                           SSA_NAME_VERSION (lhs))))
    9068         9268 :                   continue;
    9069              :               }
    9070              : 
    9071        44977 :           large_huge.lower_stmt (stmt);
    9072              :         }
    9073              : 
    9074              :       /* The PHIs of BB read their arguments from an incoming edge in
    9075              :          parallel.  For each edge, queue the copies in the order of the
    9076              :          PHIs and then the constant stores.  If a copy reads a partition
    9077              :          that an earlier copy on the edge writes, save the partition to a
    9078              :          temporary before all the copies and let the copy read that.  */
    9079        41885 :       tree atype = NULL_TREE;
    9080        83770 :       auto_bitmap written;
    9081        83770 :       hash_map<int_hash<int, -1, -2>, tree> saved;
    9082       139181 :       for (unsigned i = 0; i < EDGE_COUNT (bb->preds); ++i)
    9083              :         {
    9084        55411 :           gimple_seq saves = NULL, copies = NULL, consts = NULL;
    9085        55411 :           gimple_seq clobbers = NULL;
    9086        55411 :           bitmap_clear (written);
    9087        55411 :           saved.empty ();
    9088        79355 :           for (gphi_iterator gsi = gsi_start_phis (bb); !gsi_end_p (gsi);
    9089        23944 :                gsi_next (&gsi))
    9090              :             {
    9091        23944 :               gphi *phi = gsi.phi ();
    9092        23944 :               tree lhs = gimple_phi_result (phi);
    9093        45636 :               if (!BITINT_TYPE_P (TREE_TYPE (lhs))
    9094        23944 :                   || (bitint_precision_kind (TREE_TYPE (lhs))
    9095              :                       < bitint_prec_large))
    9096        21797 :                 continue;
    9097         2147 :               int p1 = var_to_partition (large_huge.m_map, lhs);
    9098         2147 :               gcc_assert (large_huge.m_vars[p1] != NULL_TREE);
    9099         2147 :               tree v1 = large_huge.m_vars[p1];
    9100         2147 :               tree arg = gimple_phi_arg_def (phi, i);
    9101         2147 :               gimple *g;
    9102         2147 :               switch (TREE_CODE (arg))
    9103              :                 {
    9104          632 :                 case INTEGER_CST:
    9105          632 :                   if (integer_zerop (arg) && VAR_P (v1))
    9106              :                     {
    9107          295 :                       tree zero = build_zero_cst (TREE_TYPE (v1));
    9108          295 :                       g = gimple_build_assign (v1, zero);
    9109          295 :                       gimple_seq_add_stmt (&consts, g);
    9110         1376 :                       break;
    9111              :                     }
    9112          337 :                   int ext;
    9113          337 :                   unsigned int min_prec, prec, rem;
    9114          337 :                   tree c;
    9115          337 :                   prec = TYPE_PRECISION (TREE_TYPE (arg));
    9116          337 :                   rem = prec % (2 * limb_prec);
    9117          337 :                   min_prec = bitint_min_cst_precision (arg, ext);
    9118          337 :                   if (min_prec > prec - rem - 2 * limb_prec
    9119           72 :                       && min_prec > (unsigned) limb_prec)
    9120              :                     /* Constant which has enough significant bits that it
    9121              :                        isn't worth trying to save .rodata space by extending
    9122              :                        from smaller number.  */
    9123              :                     min_prec = prec;
    9124              :                   else
    9125              :                     {
    9126          313 :                       min_prec = CEIL (min_prec, limb_prec) * limb_prec;
    9127          313 :                       if (min_prec > (unsigned) limb_prec
    9128            3 :                           && abi_limb_prec > limb_prec)
    9129              :                         {
    9130              :                           /* For targets with ABI limb precision higher than
    9131              :                              limb precision round to ABI limb precision,
    9132              :                              otherwise c can contain padding bits.  */
    9133            0 :                           min_prec
    9134            0 :                             = CEIL (min_prec, abi_limb_prec) * abi_limb_prec;
    9135            0 :                           if (min_prec > prec - rem - 2 * limb_prec)
    9136           24 :                             min_prec = prec;
    9137              :                         }
    9138              :                     }
    9139          337 :                   if (min_prec == 0)
    9140              :                     c = NULL_TREE;
    9141          310 :                   else if (min_prec == prec)
    9142           24 :                     c = tree_output_constant_def (arg);
    9143          286 :                   else if (min_prec == (unsigned) limb_prec)
    9144          283 :                     c = fold_convert (large_huge.m_limb_type, arg);
    9145              :                   else
    9146              :                     {
    9147            3 :                       tree ctype = build_bitint_type (min_prec, 1);
    9148            3 :                       c = tree_output_constant_def (fold_convert (ctype, arg));
    9149              :                     }
    9150          310 :                   if (c)
    9151              :                     {
    9152          310 :                       if (VAR_P (v1) && min_prec == prec)
    9153              :                         {
    9154           15 :                           tree v2 = build1 (VIEW_CONVERT_EXPR,
    9155           15 :                                             TREE_TYPE (v1), c);
    9156           15 :                           g = gimple_build_assign (v1, v2);
    9157           15 :                           gimple_seq_add_stmt (&consts, g);
    9158           15 :                           break;
    9159              :                         }
    9160          295 :                       if (TREE_CODE (TREE_TYPE (c)) == INTEGER_TYPE)
    9161              :                         {
    9162          283 :                           if (bitint_big_endian)
    9163              :                             {
    9164            0 :                               tree ptype = build_pointer_type (TREE_TYPE (v1));
    9165            0 :                               tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (v1));
    9166            0 :                               tree sz2 = TYPE_SIZE_UNIT (TREE_TYPE (c));
    9167            0 :                               tree off = build_int_cst (ptype,
    9168            0 :                                                         tree_to_uhwi (sz1)
    9169            0 :                                                         - tree_to_uhwi (sz2));
    9170            0 :                               tree vd = build2 (MEM_REF, TREE_TYPE (c),
    9171              :                                                 build_fold_addr_expr (v1),
    9172              :                                                 off);
    9173            0 :                               g = gimple_build_assign (vd, c);
    9174              :                             }
    9175              :                           else
    9176          283 :                             g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR,
    9177          283 :                                                              TREE_TYPE (c),
    9178              :                                                              v1), c);
    9179              :                         }
    9180              :                       else
    9181              :                         {
    9182           12 :                           unsigned HOST_WIDE_INT nelts
    9183           12 :                             = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (c)))
    9184           12 :                               / limb_prec;
    9185           12 :                           tree vtype
    9186           24 :                             = build_array_type_nelts (large_huge.m_limb_type,
    9187           12 :                                                       nelts);
    9188           12 :                           tree vd;
    9189           12 :                           if (bitint_big_endian)
    9190              :                             {
    9191            0 :                               tree ptype = build_pointer_type (TREE_TYPE (v1));
    9192            0 :                               tree sz1 = TYPE_SIZE_UNIT (TREE_TYPE (v1));
    9193            0 :                               tree sz2 = TYPE_SIZE_UNIT (vtype);
    9194            0 :                               tree off = build_int_cst (ptype,
    9195            0 :                                                         tree_to_uhwi (sz1)
    9196            0 :                                                         - tree_to_uhwi (sz2));
    9197            0 :                               vd = build2 (MEM_REF, vtype,
    9198              :                                            build_fold_addr_expr (v1), off);
    9199              :                             }
    9200              :                           else
    9201           12 :                             vd = build1 (VIEW_CONVERT_EXPR, vtype, v1);
    9202           12 :                           g = gimple_build_assign (vd,
    9203              :                                                    build1 (VIEW_CONVERT_EXPR,
    9204              :                                                            vtype, c));
    9205              :                         }
    9206          295 :                       gimple_seq_add_stmt (&consts, g);
    9207          295 :                       if (min_prec == prec)
    9208              :                         break;
    9209              :                     }
    9210          313 :                   if (ext == 0)
    9211              :                     {
    9212          292 :                       unsigned HOST_WIDE_INT nelts
    9213          292 :                         = (tree_to_uhwi (TYPE_SIZE (TREE_TYPE (v1)))
    9214          292 :                            - min_prec) / limb_prec;
    9215          292 :                       tree vtype
    9216          584 :                         = build_array_type_nelts (large_huge.m_limb_type,
    9217          292 :                                                   nelts);
    9218          292 :                       tree ptype = build_pointer_type (TREE_TYPE (v1));
    9219          292 :                       tree off;
    9220          292 :                       if (c && !bitint_big_endian)
    9221          282 :                         off = fold_convert (ptype,
    9222              :                                             TYPE_SIZE_UNIT (TREE_TYPE (c)));
    9223              :                       else
    9224           10 :                         off = build_zero_cst (ptype);
    9225          292 :                       tree vd = build2 (MEM_REF, vtype,
    9226              :                                         build_fold_addr_expr (v1), off);
    9227          292 :                       g = gimple_build_assign (vd, build_zero_cst (vtype));
    9228              :                     }
    9229              :                   else
    9230              :                     {
    9231           21 :                       tree vd = v1;
    9232           21 :                       if (c && !bitint_big_endian)
    9233              :                         {
    9234            4 :                           tree ptype = build_pointer_type (TREE_TYPE (v1));
    9235            4 :                           tree off
    9236            4 :                             = fold_convert (ptype,
    9237              :                                             TYPE_SIZE_UNIT (TREE_TYPE (c)));
    9238            4 :                           vd = build2 (MEM_REF, large_huge.m_limb_type,
    9239              :                                        build_fold_addr_expr (v1), off);
    9240              :                         }
    9241           21 :                       vd = build_fold_addr_expr (vd);
    9242           21 :                       unsigned HOST_WIDE_INT nbytes
    9243           21 :                         = tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (v1)));
    9244           21 :                       if (c)
    9245            4 :                         nbytes
    9246            4 :                           -= tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (c)));
    9247           21 :                       tree fn = builtin_decl_implicit (BUILT_IN_MEMSET);
    9248           21 :                       g = gimple_build_call (fn, 3, vd,
    9249              :                                              integer_minus_one_node,
    9250              :                                              build_int_cst (sizetype,
    9251           21 :                                                             nbytes));
    9252              :                     }
    9253          313 :                   gimple_seq_add_stmt (&consts, g);
    9254          313 :                   break;
    9255            0 :                 default:
    9256            0 :                   gcc_unreachable ();
    9257         1515 :                 case SSA_NAME:
    9258         1515 :                   if (gimple_code (SSA_NAME_DEF_STMT (arg)) == GIMPLE_NOP)
    9259              :                     {
    9260          269 :                       if (large_huge.m_names == NULL
    9261          538 :                           || !bitmap_bit_p (large_huge.m_names,
    9262          269 :                                             SSA_NAME_VERSION (arg)))
    9263         1066 :                         continue;
    9264              :                     }
    9265         1515 :                   int p2 = var_to_partition (large_huge.m_map, arg);
    9266         1515 :                   if (p1 == p2)
    9267         1066 :                     continue;
    9268          449 :                   gcc_assert (large_huge.m_vars[p2] != NULL_TREE);
    9269          449 :                   tree v2 = large_huge.m_vars[p2];
    9270          449 :                   if (atype == NULL_TREE
    9271          646 :                       || !tree_int_cst_equal (TYPE_SIZE (atype),
    9272          197 :                                               TYPE_SIZE (TREE_TYPE (lhs))))
    9273              :                     {
    9274          252 :                       unsigned HOST_WIDE_INT nelts
    9275          252 :                         = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (lhs)))
    9276          252 :                           / limb_prec;
    9277          252 :                       atype = build_array_type_nelts (large_huge.m_limb_type,
    9278          252 :                                                       nelts);
    9279              :                     }
    9280          449 :                   if (bitmap_bit_p (written, p2))
    9281              :                     {
    9282          121 :                       bool existed;
    9283          121 :                       tree &tmp = saved.get_or_insert (p2, &existed);
    9284          121 :                       if (!existed)
    9285              :                         {
    9286          106 :                           tmp = create_tmp_var (atype);
    9287          106 :                           if (TREE_TYPE (v2) != atype)
    9288           36 :                             v2 = build1 (VIEW_CONVERT_EXPR, atype, v2);
    9289          106 :                           g = gimple_build_assign (tmp, v2);
    9290          106 :                           gimple_seq_add_stmt (&saves, g);
    9291          106 :                           tree clobber = build_clobber (atype,
    9292              :                                                         CLOBBER_STORAGE_END);
    9293          106 :                           g = gimple_build_assign (tmp, clobber);
    9294          106 :                           gimple_seq_add_stmt (&clobbers, g);
    9295              :                         }
    9296          121 :                       v2 = tmp;
    9297              :                     }
    9298          449 :                   if (VAR_P (v1) && VAR_P (v2))
    9299          250 :                     g = gimple_build_assign (v1, v2);
    9300          199 :                   else if (VAR_P (v1))
    9301          117 :                     g = gimple_build_assign (v1, build1 (VIEW_CONVERT_EXPR,
    9302          117 :                                                          TREE_TYPE (v1), v2));
    9303           82 :                   else if (VAR_P (v2))
    9304           36 :                     g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR,
    9305           36 :                                                      TREE_TYPE (v2), v1), v2);
    9306              :                   else
    9307           46 :                     g = gimple_build_assign (build1 (VIEW_CONVERT_EXPR,
    9308              :                                                      atype, v1),
    9309              :                                              build1 (VIEW_CONVERT_EXPR,
    9310              :                                                      atype, v2));
    9311          449 :                   gimple_seq_add_stmt (&copies, g);
    9312              :                   /* The live PHI results of BB conflict with each other, so
    9313              :                      no two copies on the edge write the same partition.  */
    9314          449 :                   bool fresh = bitmap_set_bit (written, p1);
    9315          449 :                   gcc_checking_assert (fresh);
    9316              :                   break;
    9317              :                 }
    9318              :             }
    9319        55411 :           gimple_seq_add_seq (&saves, copies);
    9320        55411 :           gimple_seq_add_seq (&saves, consts);
    9321        55411 :           gimple_seq_add_seq (&saves, clobbers);
    9322        55411 :           if (saves)
    9323              :             {
    9324          622 :               gsi_insert_seq_on_edge (EDGE_PRED (bb, i), saves);
    9325          622 :               edge_insertions = true;
    9326              :             }
    9327              :         }
    9328              :     }
    9329              : 
    9330         7779 :   if (large_huge.m_names || has_large_huge)
    9331              :     {
    9332         6278 :       gimple *nop = NULL;
    9333       417453 :       for (i = 0; i < num_ssa_names; ++i)
    9334              :         {
    9335       411175 :           tree s = ssa_name (i);
    9336       411175 :           if (s == NULL_TREE)
    9337        16531 :             continue;
    9338       394644 :           tree type = TREE_TYPE (s);
    9339       394644 :           if (TREE_CODE (type) == COMPLEX_TYPE)
    9340        18674 :             type = TREE_TYPE (type);
    9341       351858 :           if (BITINT_TYPE_P (type)
    9342       394672 :               && bitint_precision_kind (type) >= bitint_prec_large)
    9343              :             {
    9344        43633 :               if (large_huge.m_preserved
    9345        48138 :                   && bitmap_bit_p (large_huge.m_preserved,
    9346         6854 :                                    SSA_NAME_VERSION (s)))
    9347         2349 :                 continue;
    9348        38935 :               gimple *g = SSA_NAME_DEF_STMT (s);
    9349        38935 :               if (gimple_code (g) == GIMPLE_NOP)
    9350              :                 {
    9351        10500 :                   if (SSA_NAME_VAR (s))
    9352         5816 :                     set_ssa_default_def (cfun, SSA_NAME_VAR (s), NULL_TREE);
    9353        10500 :                   release_ssa_name (s);
    9354        10500 :                   continue;
    9355              :                 }
    9356        28435 :               if (gimple_bb (g) == NULL)
    9357              :                 {
    9358            0 :                   release_ssa_name (s);
    9359            0 :                   continue;
    9360              :                 }
    9361        28435 :               if (gimple_code (g) != GIMPLE_ASM)
    9362              :                 {
    9363        28434 :                   gimple_stmt_iterator gsi = gsi_for_stmt (g);
    9364        28434 :                   bool save_vta = flag_var_tracking_assignments;
    9365        28434 :                   flag_var_tracking_assignments = false;
    9366        28434 :                   gsi_remove (&gsi, true);
    9367        28434 :                   flag_var_tracking_assignments = save_vta;
    9368              :                 }
    9369        28435 :               if (nop == NULL)
    9370         5192 :                 nop = gimple_build_nop ();
    9371        28435 :               SSA_NAME_DEF_STMT (s) = nop;
    9372        28435 :               release_ssa_name (s);
    9373              :             }
    9374              :         }
    9375         6278 :       if (optimize)
    9376         3455 :         disable_ranger (cfun);
    9377              :     }
    9378              : 
    9379         7779 :   if (edge_insertions)
    9380          260 :     gsi_commit_edge_inserts ();
    9381              : 
    9382              :   /* Fix up arguments of ECF_RETURNS_TWICE calls.  Those were temporarily
    9383              :      inserted before the call, but that is invalid IL, so move them to the
    9384              :      right place and add corresponding PHIs.  */
    9385         7779 :   if (!large_huge.m_returns_twice_calls.is_empty ())
    9386              :     {
    9387            9 :       auto_vec<gimple *, 16> arg_stmts;
    9388           29 :       while (!large_huge.m_returns_twice_calls.is_empty ())
    9389              :         {
    9390           11 :           gimple *stmt = large_huge.m_returns_twice_calls.pop ();
    9391           11 :           gimple_stmt_iterator gsi = gsi_after_labels (gimple_bb (stmt));
    9392           36 :           while (gsi_stmt (gsi) != stmt)
    9393              :             {
    9394           25 :               if (is_gimple_debug (gsi_stmt (gsi)))
    9395            2 :                 gsi_next (&gsi);
    9396              :               else
    9397              :                 {
    9398           23 :                   arg_stmts.safe_push (gsi_stmt (gsi));
    9399           23 :                   gsi_remove (&gsi, false);
    9400              :                 }
    9401              :             }
    9402           11 :           gimple *g;
    9403           11 :           basic_block bb = NULL;
    9404           11 :           edge e = NULL, ead = NULL;
    9405           34 :           FOR_EACH_VEC_ELT (arg_stmts, i, g)
    9406              :             {
    9407           23 :               gsi_safe_insert_before (&gsi, g);
    9408           23 :               if (i == 0)
    9409              :                 {
    9410           11 :                   bb = gimple_bb (stmt);
    9411           11 :                   gcc_checking_assert (EDGE_COUNT (bb->preds) == 2);
    9412           11 :                   e = EDGE_PRED (bb, 0);
    9413           11 :                   ead = EDGE_PRED (bb, 1);
    9414           11 :                   if ((ead->flags & EDGE_ABNORMAL) == 0)
    9415            0 :                     std::swap (e, ead);
    9416           11 :                   gcc_checking_assert ((e->flags & EDGE_ABNORMAL) == 0
    9417              :                                        && (ead->flags & EDGE_ABNORMAL));
    9418              :                 }
    9419           23 :               tree lhs = gimple_assign_lhs (g);
    9420           23 :               tree arg = lhs;
    9421           23 :               gphi *phi = create_phi_node (copy_ssa_name (arg), bb);
    9422           23 :               add_phi_arg (phi, arg, e, UNKNOWN_LOCATION);
    9423           23 :               tree var = create_tmp_reg (TREE_TYPE (arg));
    9424           23 :               suppress_warning (var, OPT_Wuninitialized);
    9425           23 :               arg = get_or_create_ssa_default_def (cfun, var);
    9426           23 :               SSA_NAME_OCCURS_IN_ABNORMAL_PHI (arg) = 1;
    9427           23 :               add_phi_arg (phi, arg, ead, UNKNOWN_LOCATION);
    9428           23 :               arg = gimple_phi_result (phi);
    9429           23 :               SSA_NAME_OCCURS_IN_ABNORMAL_PHI (arg) = 1;
    9430           23 :               imm_use_iterator iter;
    9431           23 :               gimple *use_stmt;
    9432           69 :               FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
    9433              :                 {
    9434           46 :                   if (use_stmt == phi)
    9435           23 :                     continue;
    9436           23 :                   gcc_checking_assert (use_stmt == stmt);
    9437           23 :                   use_operand_p use_p;
    9438           46 :                   FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
    9439           23 :                     SET_USE (use_p, arg);
    9440           23 :                 }
    9441              :             }
    9442           11 :           update_stmt (stmt);
    9443           11 :           arg_stmts.truncate (0);
    9444              :         }
    9445            9 :     }
    9446              : 
    9447         7779 :   if (loop_init_done)
    9448         4363 :     loop_optimizer_finalize ();
    9449              : 
    9450         7779 :   return ret;
    9451         7779 : }
    9452              : 
    9453              : namespace {
    9454              : 
    9455              : const pass_data pass_data_lower_bitint =
    9456              : {
    9457              :   GIMPLE_PASS, /* type */
    9458              :   "bitintlower", /* name */
    9459              :   OPTGROUP_NONE, /* optinfo_flags */
    9460              :   TV_NONE, /* tv_id */
    9461              :   PROP_ssa, /* properties_required */
    9462              :   PROP_gimple_lbitint, /* properties_provided */
    9463              :   0, /* properties_destroyed */
    9464              :   0, /* todo_flags_start */
    9465              :   0, /* todo_flags_finish */
    9466              : };
    9467              : 
    9468              : class pass_lower_bitint : public gimple_opt_pass
    9469              : {
    9470              : public:
    9471       605970 :   pass_lower_bitint (gcc::context *ctxt)
    9472      1211940 :     : gimple_opt_pass (pass_data_lower_bitint, ctxt)
    9473              :   {}
    9474              : 
    9475              :   /* opt_pass methods: */
    9476       302985 :   opt_pass * clone () final override { return new pass_lower_bitint (m_ctxt); }
    9477      1070725 :   unsigned int execute (function *) final override
    9478              :   {
    9479      1070725 :     return gimple_lower_bitint ();
    9480              :   }
    9481              : 
    9482              : }; // class pass_lower_bitint
    9483              : 
    9484              : } // anon namespace
    9485              : 
    9486              : gimple_opt_pass *
    9487       302985 : make_pass_lower_bitint (gcc::context *ctxt)
    9488              : {
    9489       302985 :   return new pass_lower_bitint (ctxt);
    9490              : }
    9491              : 
    9492              : 
    9493              : namespace {
    9494              : 
    9495              : const pass_data pass_data_lower_bitint_O0 =
    9496              : {
    9497              :   GIMPLE_PASS, /* type */
    9498              :   "bitintlower0", /* name */
    9499              :   OPTGROUP_NONE, /* optinfo_flags */
    9500              :   TV_NONE, /* tv_id */
    9501              :   PROP_cfg, /* properties_required */
    9502              :   PROP_gimple_lbitint, /* properties_provided */
    9503              :   0, /* properties_destroyed */
    9504              :   0, /* todo_flags_start */
    9505              :   0, /* todo_flags_finish */
    9506              : };
    9507              : 
    9508              : class pass_lower_bitint_O0 : public gimple_opt_pass
    9509              : {
    9510              : public:
    9511       302985 :   pass_lower_bitint_O0 (gcc::context *ctxt)
    9512       605970 :     : gimple_opt_pass (pass_data_lower_bitint_O0, ctxt)
    9513              :   {}
    9514              : 
    9515              :   /* opt_pass methods: */
    9516      1531899 :   bool gate (function *fun) final override
    9517              :     {
    9518              :       /* With errors, normal optimization passes are not run.  If we don't
    9519              :          lower bitint operations at all, rtl expansion will abort.  */
    9520      1531899 :       return !(fun->curr_properties & PROP_gimple_lbitint);
    9521              :     }
    9522              : 
    9523       461345 :   unsigned int execute (function *) final override
    9524              :   {
    9525       461345 :     return gimple_lower_bitint ();
    9526              :   }
    9527              : 
    9528              : }; // class pass_lower_bitint_O0
    9529              : 
    9530              : } // anon namespace
    9531              : 
    9532              : gimple_opt_pass *
    9533       302985 : make_pass_lower_bitint_O0 (gcc::context *ctxt)
    9534              : {
    9535       302985 :   return new pass_lower_bitint_O0 (ctxt);
    9536              : }
        

Generated by: LCOV version 2.6-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.