{"id":2223416,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2223416/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/ad9geEOhFRyA9Fwq@tucnak/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/projects/17/?format=json","name":"GNU Compiler Collection","link_name":"gcc","list_id":"gcc-patches.gcc.gnu.org","list_email":"gcc-patches@gcc.gnu.org","web_url":null,"scm_url":null,"webscm_url":null},"msgid":"<ad9geEOhFRyA9Fwq@tucnak>","date":"2026-04-15T09:55:04","name":"bitintlower: Padding bit fixes, part 1 [PR123635]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"c24fe2116b2a553c9ad2f96893ce0bca6487dc65","submitter":{"id":671,"url":"http://patchwork.ozlabs.org/api/1.1/people/671/?format=json","name":"Jakub Jelinek","email":"jakub@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/ad9geEOhFRyA9Fwq@tucnak/mbox/","series":[{"id":499953,"url":"http://patchwork.ozlabs.org/api/1.1/series/499953/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=499953","date":"2026-04-15T09:55:04","name":"bitintlower: Padding bit fixes, part 1 [PR123635]","version":1,"mbox":"http://patchwork.ozlabs.org/series/499953/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2223416/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2223416/checks/","tags":{},"headers":{"Return-Path":"<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>","X-Original-To":["incoming@patchwork.ozlabs.org","gcc-patches@gcc.gnu.org"],"Delivered-To":["patchwork-incoming@legolas.ozlabs.org","gcc-patches@gcc.gnu.org"],"Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=Faz7sEjU;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)","sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=Faz7sEjU","sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com","sourceware.org; spf=pass smtp.mailfrom=redhat.com","server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.129.124"],"Received":["from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fwc3d2VDjz1yHM\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 19:55:52 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id CD28F4BA2E07\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 15 Apr 2026 09:55:49 +0000 (GMT)","from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 562D84BA5436\n for <gcc-patches@gcc.gnu.org>; Wed, 15 Apr 2026 09:55:15 +0000 (GMT)","from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-503-aLbG01g3P0GyGkpAlsbwzA-1; Wed,\n 15 Apr 2026 05:55:10 -0400","from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 7752D1800366; Wed, 15 Apr 2026 09:55:09 +0000 (UTC)","from tucnak.zalov.cz (unknown [10.44.33.129])\n by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id A5077180057E; Wed, 15 Apr 2026 09:55:08 +0000 (UTC)","from tucnak.zalov.cz (localhost [127.0.0.1])\n by tucnak.zalov.cz (8.18.1/8.18.1) with ESMTPS id 63F9t5FO1905078\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);\n Wed, 15 Apr 2026 11:55:05 +0200","(from jakub@localhost)\n by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 63F9t4St1905077;\n Wed, 15 Apr 2026 11:55:04 +0200"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org CD28F4BA2E07","OpenDKIM Filter v2.11.0 sourceware.org 562D84BA5436"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 562D84BA5436","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 562D84BA5436","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776246915; cv=none;\n b=gFEBEupQpym6yfuDfTGUa9+7jtBGNBEshFeIxnEOrKmd1K29Mk/l8NrNyxvHJXFyqBTIT9pCW6Trd4y8KHMxG7BHtj9BblONzAw4P6bFz7rBe3uplEPnmt822y+q85gtYsYuCNjzFGkXzt8LTPqeiwvfqDrPxMPyTcCZHxipUhw=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776246915; c=relaxed/simple;\n bh=GCve/j4C8xhoazpV8e9Nf50+zBQ9GUOX/r7TR/ocoVM=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=xKqWBSOGPLSTGLncMgo/D7jcNTmJJVhthne9ViUUtXx3lagH9YSuMCybSlz9M7nlqHosg3k23Kmr1NueFlR2RL8u7A/LIfAR51gRPpiaWHwniymDXIB2oBTjbkBaex8hmvPFRs8+JYV1owoPDzjRnuntCklUwDw9oBecBx/2YSk=","ARC-Authentication-Results":"i=1; server2.sourceware.org","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776246914;\n h=from:from:reply-to:reply-to:subject:subject:date:date:\n message-id:message-id:to:to:cc:cc:mime-version:mime-version:\n content-type:content-type; bh=wrx9wymUD4C0sWaD4azpbL6Y2NgkLJK8wxurmOnE6ZU=;\n b=Faz7sEjUEf4ty/p7Aj/iU4hKdkiMV9G68RNrf5oX8guwHkDe9yFd34i3Cz9U0mx5EoFIjN\n VoXARfMvh/N46FW/XebNS3DfvFqcO6YvH4oUNh5YZpbw3ttPFaQ1Rb2rjIaE8grGY5K3GV\n UFsAKRvH3pfn7sJgVz8RG4AeA9plrcA=","X-MC-Unique":"aLbG01g3P0GyGkpAlsbwzA-1","X-Mimecast-MFC-AGG-ID":"aLbG01g3P0GyGkpAlsbwzA_1776246909","Date":"Wed, 15 Apr 2026 11:55:04 +0200","From":"Jakub Jelinek <jakub@redhat.com>","To":"Richard Biener <rguenther@suse.de>","Cc":"gcc-patches@gcc.gnu.org,\n Andre Simoes Dias Vieira <Andre.SimoesDiasVieira@arm.com>,\n Palmer Dabbelt <palmer@dabbelt.com>, Robin Dapp <rdapp.gcc@gmail.com>","Subject":"[PATCH] bitintlower: Padding bit fixes, part 1 [PR123635]","Message-ID":"<ad9geEOhFRyA9Fwq@tucnak>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.93","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"7wGgDmbuwf1QICcPalNTvz3jPnygQScGR57wX4uJTdY_1776246909","X-Mimecast-Originator":"redhat.com","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","X-BeenThere":"gcc-patches@gcc.gnu.org","X-Mailman-Version":"2.1.30","Precedence":"list","List-Id":"Gcc-patches mailing list <gcc-patches.gcc.gnu.org>","List-Unsubscribe":"<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>","List-Archive":"<https://gcc.gnu.org/pipermail/gcc-patches/>","List-Post":"<mailto:gcc-patches@gcc.gnu.org>","List-Help":"<mailto:gcc-patches-request@gcc.gnu.org?subject=help>","List-Subscribe":"<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>","Reply-To":"Jakub Jelinek <jakub@redhat.com>","Errors-To":"gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"},"content":"Hi!\n\nx86_64/ia32/aarch64 say padding bits of _BitInt values have unspecified\nvalues, and until GCC 16 those were the only supported _BitInt targets.\nIn GCC 16, we've added _BitInt support for some further arches,\nloongarch, riscv, s390x and arm and all of them chose to specify the\npadding bits (require zero or sign extension depending on whether the\ntype is signed or unsigned).\ns390x is big-endian, on the other side has abi_limb_mode the same as\nlimb_mode, so the extension is always just within the same limb.\nloongarch chose to require weird extension, only within the same limb\nbut not abi limb, so the current extensions are also mostly ok.\nriscv and arm both use abi_limb_mode larger than limb_)mode and require\nextension, which means that say for _BitInt(513) one needs to sign extend\nnot just within the limb corresponding to bit 512 (32-bit on arm, 64-bit\non loongarch), but within the whole abi limb (64-bit on arm, 128-bit on\nloongarch), which means when working with the usual limbs we need to\nextend another whole 32-bit or 64-bit limb above the one we'd normally\nextend.\n\nThe following patch tweaks the bitint_info, so that it differentiates\nbetween the different extension possibilities (x86_64/ia32/aarch64 0,\nloongarch 1, arm/riscv 2, s390x doesn't really matter if 1 or 2, but\nchose to document 2 and in gimple-lower-bitint.cc treat it as 1).\nAnd then for a subset of lowerings handle it even for the\nbitint_extended == 2 cases.\nIn particular, this patch handles the mergeable stmts (like +/- and many\nothers which walk from least significant limb to most significant limb\nand can handle 2 limbs in a loop), including the separate_ext extension\n(where a mergeable operation is then extended to much wider _BitInt,\nhandled by handling normally the mergeable operation, remembering if\nwe should zero or sign extend (and whether to 0 or -1) and then in a\nseparate loop or straight line code store the 0s or -1s), division/modulo\n(these are done by forcing larger prec on the output, modulo result\nshould never be larger than the first operand and same sign, division\nof negative minimum by -1 is UB and otherwise also should be never larger\nthan first operand), signed multiplication (again, done by extending\nprec because signed multiplication overflow is UB), unsigned multiplication\n(this one can't be handled that way because unsigned mult overflow wraps,\nso we need to pass exact lhs prec, so the code stores zero limb when\nneeded), and conversions from floating point (binary or decimal) to _BitInt\n(signed or unsigned), those again are supposed to store minimum or maximum\nvalue on overflow and so lhs prec needs to be maintained, so the code\nfor unsigned result clears one limb when needed or for signed result\nright shifts the second most significant limb by limb prec - 1 and stores\nthat into most significant limb.\n\nBootstrapped/regtested on x86_64-linux, i686-linux, aarch64-linux and\ns390x-linux, ok for trunk if somebody tests this on arm-linux-gnueabi or\nriscv*-linux?\n\nNote, <<, >>, add/sub overflow and mul overflow at least aren't done in\nthis patch, to be resolved incrementally.\n\n2026-04-15  Jakub Jelinek  <jakub@redhat.com>\n\n\tPR middle-end/123635\n\t* target.h (struct bitint_info): Change extend type from bool\n\tto unsigned char and document it.\n\t* gimple-lower-bitint.cc (bitint_extended): Change type from bool\n\tto unsigned char.\n\t(bitint_precision_kind): Change bitint_extended to 1 from 2 if\n\tlimb_mode is the same as abi_limb_mode.\n\t(bitint_large_huge::limb_access_type): For bitint_extended == 2\n\tallow access to the most significant limb solely with padding\n\tbits if present.\n\t(bitint_large_huge::lower_mergeable_stmt): Handle bitint_extended == 2\n\textension if needed.\n\t(bitint_large_huge::lower_muldiv_stmt): Likewise.\n\t(bitint_large_huge::lower_float_conv_stmt): Likewise.\n\t* config/aarch64/aarch64.cc (aarch64_bitint_type_info): Set\n\tinfo->extended to 0 rather than false.\n\t* config/arm/arm.cc (arm_bitint_type_info): Set\n\tinfo->extended to 2 rather than true.\n\t* config/i386/i386.cc (ix86_bitint_type_info): Set\n\tinfo->extended to 0 rather than false.\n\t* config/loongarch/loongarch.cc (loongarch_bitint_type_info): Set\n\tinfo->extended to 1 rather than true.\n\t* config/riscv/riscv.cc (riscv_bitint_type_info): Set\n\tinfo->extended to 2 rather than true.\n\t* config/s390/s390.cc (s390_bitint_type_info): Likewise.\n\n\t* gcc.dg/bitintext.h: Handle __riscv__ like __arm__.\n\t* gcc.dg/torture/bitint-86.c: New test.\n\t* gcc.dg/torture/bitint-87.c: New test.\n\n\n\tJakub","diff":"--- gcc/target.h.jj\t2026-03-27 10:17:14.548323983 +0100\n+++ gcc/target.h\t2026-04-14 12:46:32.676679315 +0200\n@@ -72,9 +72,13 @@ union cumulative_args_t { void *p; };\n    as series of abi_limb_mode CEIL (N, GET_MODE_PRECISION (abi_limb_mode))\n    limbs, ordered from least significant to most significant if !big_endian,\n    otherwise from most significant to least significant.  If extended is\n-   false, the bits above or equal to N are undefined when stored in a register\n-   or memory, otherwise they are zero or sign extended depending on if\n-   it is unsigned _BitInt(N) or _BitInt(N) / signed _BitInt(N).\n+   0, the bits above or equal to N are undefined when stored in a register\n+   or memory, if extended is 2, they are zero or sign extended depending on if\n+   it is unsigned _BitInt(N) or _BitInt(N) / signed _BitInt(N), if extended is\n+   1, then bits above or equal to N and below\n+   M = CEIL (N, GET_MODE_PRECISION (limb_mode)) * GET_MODE_PRECISION (limb_mode)\n+   are zero or sign extended as specified above and bits above or equal to M\n+   are undefined.\n    limb_mode is either the same as abi_limb_mode, or some narrower mode\n    in which _BitInt lowering should actually perform operations in and\n    what libgcc _BitInt helpers should use.\n@@ -87,7 +91,7 @@ union cumulative_args_t { void *p; };\n struct bitint_info {\n   machine_mode abi_limb_mode, limb_mode;\n   bool big_endian;\n-  bool extended;\n+  unsigned char extended;\n };\n \n /* Types of memory operation understood by the \"by_pieces\" infrastructure.\n--- gcc/gimple-lower-bitint.cc.jj\t2026-04-14 09:27:02.221287531 +0200\n+++ gcc/gimple-lower-bitint.cc\t2026-04-14 18:45:43.191371265 +0200\n@@ -77,7 +77,8 @@ enum bitint_prec_kind {\n \n static int small_max_prec, mid_min_prec, large_min_prec, huge_min_prec;\n static int limb_prec, abi_limb_prec;\n-static bool bitint_big_endian, bitint_extended;\n+static bool bitint_big_endian;\n+static int bitint_extended;\n \n /* Categorize _BitInt(PREC) as small, middle, large or huge.  */\n \n@@ -104,6 +105,8 @@ bitint_precision_kind (int prec)\n     }\n   bitint_big_endian = info.big_endian;\n   bitint_extended = info.extended;\n+  if (info.limb_mode == info.abi_limb_mode && bitint_extended == 2)\n+    bitint_extended = 1;\n   if (!large_min_prec\n       && GET_MODE_PRECISION (limb_mode) <= MAX_FIXED_MODE_SIZE)\n     large_min_prec = MAX_FIXED_MODE_SIZE + 1;\n@@ -599,7 +602,11 @@ bitint_large_huge::limb_access_type (tre\n     return m_limb_type;\n   unsigned HOST_WIDE_INT i = tree_to_uhwi (idx);\n   unsigned int prec = TYPE_PRECISION (type);\n-  gcc_assert (i * limb_prec < prec);\n+  gcc_assert (i * limb_prec < prec\n+\t      || (bitint_extended == 2\n+\t\t  && abi_limb_prec > limb_prec\n+\t\t  && i * limb_prec\n+\t\t     < CEIL (prec, abi_limb_prec) * abi_limb_prec));\n   if (bitint_big_endian\n       ? (i != 0 || (prec % limb_prec) == 0)\n       : (i + 1) * limb_prec <= prec)\n@@ -2870,6 +2877,16 @@ bitint_large_huge::lower_mergeable_stmt\n     = (prec != (unsigned) TYPE_PRECISION (type)\n        && (CEIL ((unsigned) TYPE_PRECISION (type), limb_prec)\n \t   > CEIL (prec, limb_prec)));\n+  if (bitint_extended == 2\n+      && !eq_p\n+      && abi_limb_prec > limb_prec\n+      && ((CEIL ((unsigned) TYPE_PRECISION (type), abi_limb_prec)\n+\t   * abi_limb_prec / limb_prec) > CEIL (prec, limb_prec)))\n+    {\n+      if (prec == (unsigned) TYPE_PRECISION (type))\n+\tsext = !TYPE_UNSIGNED (type);\n+      separate_ext = true;\n+    }\n   unsigned dst_idx_off = 0;\n   if (separate_ext && bitint_big_endian)\n     dst_idx_off = (CEIL ((unsigned) TYPE_PRECISION (type), limb_prec)\n@@ -3107,6 +3124,11 @@ bitint_large_huge::lower_mergeable_stmt\n       kind = bitint_precision_kind (type);\n       unsigned start = CEIL (prec, limb_prec);\n       prec = TYPE_PRECISION (type);\n+      if (bitint_extended == 2 && abi_limb_prec > limb_prec)\n+\t{\n+\t  prec = CEIL (prec, abi_limb_prec) * abi_limb_prec;\n+\t  kind = bitint_precision_kind (prec);\n+\t}\n       unsigned total = CEIL (prec, limb_prec);\n       idx = idx_first = idx_next = NULL_TREE;\n       if (prec <= (start + 2 + (bo_shift != 0)) * limb_prec)\n@@ -3964,6 +3986,7 @@ bitint_large_huge::lower_muldiv_stmt (tr\n   gcc_assert (TREE_CODE (type) == BITINT_TYPE\n \t      && bitint_precision_kind (type) >= bitint_prec_large);\n   int prec = TYPE_PRECISION (type), prec1, prec2;\n+  bool zero_ms_limb = false;\n   rhs1 = handle_operand_addr (rhs1, stmt, NULL, &prec1);\n   rhs2 = handle_operand_addr (rhs2, stmt, NULL, &prec2);\n   if (obj == NULL_TREE)\n@@ -3979,6 +4002,18 @@ bitint_large_huge::lower_muldiv_stmt (tr\n       lhs = force_gimple_operand_gsi (&m_gsi, lhs, true,\n \t\t\t\t      NULL_TREE, true, GSI_SAME_STMT);\n     }\n+  if (bitint_extended == 2\n+      && abi_limb_prec > limb_prec\n+      && (CEIL (prec, abi_limb_prec) * abi_limb_prec\n+\t  > CEIL (prec, limb_prec) * limb_prec))\n+    {\n+      /* unsigned multiplication needs to wrap around, so we can't\n+\t increase prec.  */\n+      if (rhs_code == MULT_EXPR && TYPE_UNSIGNED (type))\n+\tzero_ms_limb = true;\n+      else\n+\tprec = CEIL (prec, abi_limb_prec) * abi_limb_prec;\n+    }\n   tree sitype = lang_hooks.types.type_for_mode (SImode, 0);\n   gimple *g;\n   switch (rhs_code)\n@@ -4032,6 +4067,13 @@ bitint_large_huge::lower_muldiv_stmt (tr\n \t  add_eh_edge (e2->src, e1);\n \t}\n     }\n+  if (zero_ms_limb)\n+    {\n+      unsigned int i = CEIL (prec, abi_limb_prec) * abi_limb_prec / limb_prec;\n+      g = gimple_build_assign (limb_access (type, obj, size_int (i - 1), true),\n+\t\t\t       build_zero_cst (m_limb_type));\n+      insert_before (g);\n+    }\n }\n \n /* Lower large/huge _BitInt conversion to/from floating point.  */\n@@ -4046,8 +4088,15 @@ bitint_large_huge::lower_float_conv_stmt\n   gimple *g;\n   if (rhs_code == FIX_TRUNC_EXPR)\n     {\n-      int prec = TYPE_PRECISION (TREE_TYPE (lhs));\n-      if (!TYPE_UNSIGNED (TREE_TYPE (lhs)))\n+      tree type = TREE_TYPE (lhs);\n+      int prec = TYPE_PRECISION (type);\n+      bool extend_ms_limb = false;\n+      if (bitint_extended == 2\n+\t  && abi_limb_prec > limb_prec\n+\t  && (CEIL (prec, abi_limb_prec) * abi_limb_prec\n+\t      > CEIL (prec, limb_prec) * limb_prec))\n+\textend_ms_limb = true;\n+      if (!TYPE_UNSIGNED (type))\n \tprec = -prec;\n       if (obj == NULL_TREE)\n \t{\n@@ -4081,6 +4130,32 @@ bitint_large_huge::lower_float_conv_stmt\n \t\t\t\t      lhs, build_int_cst (sitype, prec),\n \t\t\t\t      rhs1);\n       insert_before (g);\n+      if (extend_ms_limb)\n+\t{\n+\t  unsigned int i\n+\t    = (CEIL (prec < 0 ? -prec : prec, abi_limb_prec)\n+\t       * abi_limb_prec / limb_prec);\n+\t  tree val;\n+\t  if (prec < 0)\n+\t    {\n+\t      g = gimple_build_assign (make_ssa_name (m_limb_type),\n+\t\t\t\t       limb_access (type, obj,\n+\t\t\t\t\t\t    size_int (i - 2),\n+\t\t\t\t\t\t    true));\n+\t      insert_before (g);\n+\t      g = gimple_build_assign (make_ssa_name (m_limb_type),\n+\t\t\t\t       RSHIFT_EXPR, gimple_assign_lhs (g),\n+\t\t\t\t       build_int_cst (unsigned_type_node,\n+\t\t\t\t\t\t      limb_prec - 1));\n+\t      insert_before (g);\n+\t      val = gimple_assign_lhs (g);\n+\t    }\n+\t  else\n+\t    val = build_zero_cst (m_limb_type);\n+\t  g = gimple_build_assign (limb_access (type, obj, size_int (i - 1),\n+\t\t\t\t\t\ttrue), val);\n+\t  insert_before (g);\n+\t}\n     }\n   else\n     {\n--- gcc/config/aarch64/aarch64.cc.jj\t2026-04-10 08:45:20.699812103 +0200\n+++ gcc/config/aarch64/aarch64.cc\t2026-04-14 13:05:23.358474454 +0200\n@@ -30497,7 +30497,7 @@ aarch64_bitint_type_info (int n, struct\n   else\n     info->abi_limb_mode = info->limb_mode;\n   info->big_endian = TARGET_BIG_END;\n-  info->extended = false;\n+  info->extended = 0;\n   return true;\n }\n \n--- gcc/config/arm/arm.cc.jj\t2026-03-30 11:56:53.023841345 +0200\n+++ gcc/config/arm/arm.cc\t2026-04-14 13:05:31.620334159 +0200\n@@ -35933,7 +35933,7 @@ arm_bitint_type_info (int n, struct biti\n   else\n     info->abi_limb_mode = info->limb_mode;\n   info->big_endian = TARGET_BIG_END;\n-  info->extended = true;\n+  info->extended = 2;\n   return true;\n }\n \n--- gcc/config/i386/i386.cc.jj\t2026-04-14 08:39:48.626636548 +0200\n+++ gcc/config/i386/i386.cc\t2026-04-14 13:05:37.917227233 +0200\n@@ -27719,7 +27719,7 @@ ix86_bitint_type_info (int n, struct bit\n     info->limb_mode = DImode;\n   info->abi_limb_mode = info->limb_mode;\n   info->big_endian = false;\n-  info->extended = false;\n+  info->extended = 0;\n   return true;\n }\n \n--- gcc/config/loongarch/loongarch.cc.jj\t2026-04-02 14:18:31.926538351 +0200\n+++ gcc/config/loongarch/loongarch.cc\t2026-04-14 13:05:41.762161943 +0200\n@@ -11391,7 +11391,7 @@ loongarch_bitint_type_info (int n, struc\n     info->abi_limb_mode = TImode;\n \n   info->big_endian = false;\n-  info->extended = true;\n+  info->extended = 1;\n   return true;\n }\n \n--- gcc/config/riscv/riscv.cc.jj\t2026-04-10 08:45:20.701812067 +0200\n+++ gcc/config/riscv/riscv.cc\t2026-04-14 13:05:46.023089589 +0200\n@@ -14926,7 +14926,7 @@ riscv_bitint_type_info (int n, struct bi\n     info->abi_limb_mode = DImode;\n \n   info->big_endian = TARGET_BIG_ENDIAN;\n-  info->extended = true;\n+  info->extended = 2;\n   return true;\n }\n \n--- gcc/config/s390/s390.cc.jj\t2026-04-01 19:09:38.325343788 +0200\n+++ gcc/config/s390/s390.cc\t2026-04-14 13:05:49.527030090 +0200\n@@ -18851,7 +18851,7 @@ s390_bitint_type_info (int n, struct bit\n     info->limb_mode = DImode;\n   info->abi_limb_mode = info->limb_mode;\n   info->big_endian = true;\n-  info->extended = true;\n+  info->extended = 2;\n   return true;\n }\n \n--- gcc/testsuite/gcc.dg/bitintext.h.jj\t2026-03-27 10:17:16.871286076 +0100\n+++ gcc/testsuite/gcc.dg/bitintext.h\t2026-04-14 12:26:15.243964985 +0200\n@@ -16,7 +16,7 @@ do_copy (void *p, const void *q, __SIZE_\n #define CEIL(x,y) (((x) + (y) - 1) / (y))\n \n /* Promote a _BitInt type to include its padding bits.  */\n-#if defined (__s390x__) || defined(__arm__)\n+#if defined (__s390x__) || defined(__arm__) || defined(__riscv__)\n #define PROMOTED_SIZE(x) sizeof (x)\n #elif defined(__loongarch__)\n #define PROMOTED_SIZE(x) (sizeof (x) > 8 ? CEIL (S (x), 64) * 8 : sizeof (x))\n@@ -24,7 +24,8 @@ do_copy (void *p, const void *q, __SIZE_\n \n /* Macro to test whether (on targets where psABI requires it) _BitInt\n    with padding bits have those filled with sign or zero extension.  */\n-#if defined(__s390x__) || defined(__arm__) || defined(__loongarch__)\n+#if defined(__s390x__) || defined(__arm__) || defined(__loongarch__) \\\n+    || defined(__riscv__)\n #define BEXTC1(x, uns) \\\n   do {\t\t\t\t\t\t\t  \\\n     uns _BitInt(PROMOTED_SIZE (x) * __CHAR_BIT__) __x;\t  \\\n--- gcc/testsuite/gcc.dg/torture/bitint-86.c.jj\t2026-04-14 13:52:03.448042878 +0200\n+++ gcc/testsuite/gcc.dg/torture/bitint-86.c\t2026-04-14 15:49:40.833426638 +0200\n@@ -0,0 +1,96 @@\n+/* PR middle-end/123635 */\n+/* { dg-do run { target bitint } } */\n+/* { dg-require-effective-target sync_char_short } */\n+/* { dg-options \"-std=c23 -pedantic-errors\" } */\n+/* { dg-skip-if \"\" { ! run_expensive_tests }  { \"*\" } { \"-O0\" \"-O2\" } } */\n+/* { dg-skip-if \"\" { ! run_expensive_tests } { \"-flto\" } { \"\" } } */\n+\n+#if __BITINT_MAXWIDTH__ >= 1025\n+_BitInt(513) a, b, c, d;\n+unsigned _BitInt(513) e, f, g, h;\n+_BitInt(1025) i, j, k, l;\n+unsigned _BitInt(1025) m, n, o, p;\n+#endif\n+\n+#include \"../bitintext.h\"\n+\n+#if __BITINT_MAXWIDTH__ >= 1025\n+[[gnu::noipa]] void\n+f1 (_BitInt(513) q, _BitInt(513) r, _BitInt(513) s,\n+    unsigned _BitInt(513) t, unsigned _BitInt(513) u, unsigned _BitInt(513) v)\n+{\n+  a = q + r;\n+  BEXTC (a);\n+  b = r + s;\n+  BEXTC (b);\n+  c = q - r;\n+  BEXTC (c);\n+  d = q - s;\n+  BEXTC (d);\n+  e = t + u;\n+  BEXTC (e);\n+  f = u + v;\n+  BEXTC (f);\n+  g = t - u;\n+  BEXTC (g);\n+  h = t - v;\n+  BEXTC (h);\n+}\n+\n+[[gnu::noipa]] void\n+f2 (_BitInt(513) q, _BitInt(513) r, _BitInt(513) s,\n+    unsigned _BitInt(513) t, unsigned _BitInt(513) u, unsigned _BitInt(513) v)\n+{\n+  i = q + r;\n+  BEXTC (i);\n+  j = r + s;\n+  BEXTC (j);\n+  k = q - r;\n+  BEXTC (k);\n+  l = q - s;\n+  BEXTC (l);\n+  m = t + u;\n+  BEXTC (m);\n+  n = u + v;\n+  BEXTC (n);\n+  o = t - u;\n+  BEXTC (o);\n+  p = t - v;\n+  BEXTC (p);\n+}\n+#endif\n+\n+int\n+main ()\n+{\n+#if __BITINT_MAXWIDTH__ >= 1025\n+  __builtin_memset (&a, 0x55, sizeof (a));\n+  __builtin_memset (&b, 0xaa, sizeof (b));\n+  __builtin_memset (&c, 0x55, sizeof (c));\n+  __builtin_memset (&d, 0xaa, sizeof (d));\n+  __builtin_memset (&e, 0x55, sizeof (e));\n+  __builtin_memset (&f, 0xaa, sizeof (f));\n+  __builtin_memset (&g, 0x55, sizeof (g));\n+  __builtin_memset (&h, 0xaa, sizeof (h));\n+  f1 (-2639616085193412675089727272130019765984398127278861998378045997173219392866835944828454559654047247059773556852593471531433454810831298259785611283536204wb,\n+      -7234121192495298112713936268702056205915537824658323839255206188456944966709752205781440683757949161649123152428620619997014209098183677328840647884700332wb,\n+      8654283549227219676537451326576929768614001427323560383705131223498505581982738964879437520020436012891649083646965651378407397436785749860023553778646861wb,\n+      15046745594550617619205422464231805109110883864578289024439083517871820578179553927615539526791313634437787081814763432804808038115388367331529035246240655uwb,\n+      20633637828717837096174917874088391607464281656818868213468970773994599068609617673436080725569780340050358299419252926775025136778754971701553110169281151uwb,\n+      513612209045189503622076474995216606086383139671427104179978688982034117764664711277072795083902951564358998498109412142322138933760173628255697435284781uwb);\n+  __builtin_memset (&i, 0x55, sizeof (i));\n+  __builtin_memset (&j, 0xaa, sizeof (j));\n+  __builtin_memset (&k, 0x55, sizeof (k));\n+  __builtin_memset (&l, 0xaa, sizeof (l));\n+  __builtin_memset (&m, 0x55, sizeof (m));\n+  __builtin_memset (&n, 0xaa, sizeof (n));\n+  __builtin_memset (&o, 0x55, sizeof (o));\n+  __builtin_memset (&p, 0xaa, sizeof (p));\n+  f2 (-2639616085193412675089727272130019765984398127278861998378045997173219392866835944828454559654047247059773556852593471531433454810831298259785611283536204wb,\n+      -7234121192495298112713936268702056205915537824658323839255206188456944966709752205781440683757949161649123152428620619997014209098183677328840647884700332wb,\n+      8654283549227219676537451326576929768614001427323560383705131223498505581982738964879437520020436012891649083646965651378407397436785749860023553778646861wb,\n+      15046745594550617619205422464231805109110883864578289024439083517871820578179553927615539526791313634437787081814763432804808038115388367331529035246240655uwb,\n+      20633637828717837096174917874088391607464281656818868213468970773994599068609617673436080725569780340050358299419252926775025136778754971701553110169281151uwb,\n+      513612209045189503622076474995216606086383139671427104179978688982034117764664711277072795083902951564358998498109412142322138933760173628255697435284781uwb);\n+#endif\n+}\n--- gcc/testsuite/gcc.dg/torture/bitint-87.c.jj\t2026-04-14 15:48:02.591099982 +0200\n+++ gcc/testsuite/gcc.dg/torture/bitint-87.c\t2026-04-14 15:56:45.479193714 +0200\n@@ -0,0 +1,85 @@\n+/* PR middle-end/123635 */\n+/* { dg-do run { target bitint } } */\n+/* { dg-require-effective-target sync_char_short } */\n+/* { dg-options \"-std=c23 -pedantic-errors\" } */\n+/* { dg-skip-if \"\" { ! run_expensive_tests }  { \"*\" } { \"-O0\" \"-O2\" } } */\n+/* { dg-skip-if \"\" { ! run_expensive_tests } { \"-flto\" } { \"\" } } */\n+\n+#if __BITINT_MAXWIDTH__ >= 513\n+_BitInt(513) a, b, c, d;\n+unsigned _BitInt(513) e, f, g, h;\n+_BitInt(513) i, j, k;\n+unsigned _BitInt(513) l, m, n;\n+#endif\n+\n+#include \"../bitintext.h\"\n+\n+#if __BITINT_MAXWIDTH__ >= 513\n+[[gnu::noipa]] void\n+f1 (_BitInt(513) q, _BitInt(513) r, _BitInt(513) s,\n+    unsigned _BitInt(513) t, unsigned _BitInt(513) u, unsigned _BitInt(513) v)\n+{\n+  a = q * r;\n+  BEXTC (a);\n+  b = r * s;\n+  BEXTC (b);\n+  c = q / r;\n+  BEXTC (c);\n+  d = q / s;\n+  BEXTC (d);\n+  e = t * u;\n+  BEXTC (e);\n+  f = u * v;\n+  BEXTC (f);\n+  g = t / u;\n+  BEXTC (g);\n+  h = t / v;\n+  BEXTC (h);\n+}\n+\n+[[gnu::noipa]] void\n+f2 (float q, double r, long double s, float t, double u, long double v)\n+{\n+  i = q;\n+  BEXTC (i);\n+  j = r;\n+  BEXTC (j);\n+  k = s;\n+  BEXTC (k);\n+  l = t;\n+  BEXTC (l);\n+  m = u;\n+  BEXTC (m);\n+  n = v;\n+  BEXTC (n);\n+}\n+#endif\n+\n+int\n+main ()\n+{\n+#if __BITINT_MAXWIDTH__ >= 513\n+  __builtin_memset (&a, 0x55, sizeof (a));\n+  __builtin_memset (&b, 0xaa, sizeof (b));\n+  __builtin_memset (&c, 0x55, sizeof (c));\n+  __builtin_memset (&d, 0xaa, sizeof (d));\n+  __builtin_memset (&e, 0x55, sizeof (e));\n+  __builtin_memset (&f, 0xaa, sizeof (f));\n+  __builtin_memset (&g, 0x55, sizeof (g));\n+  __builtin_memset (&h, 0xaa, sizeof (h));\n+  f1 (-53323980256963787505256507743137477556434962931963225515943461794698643113423wb,\n+      -10076482373458251489901780456236592759327822657780415144730546867053397315531wb,\n+      9430367348600775477158545473775377451258484445522540280907903691748059121081wb,\n+      15046745594550617619205422464231805109110883864578289024439083517871820578179553927615539526791313634437787081814763432804808038115388367331529035246240655uwb,\n+      20633637828717837096174917874088391607464281656818868213468970773994599068609617673436080725569780340050358299419252926775025136778754971701553110169281uwb,\n+      5136122090451895036220764749952166060863831396714271041799786889820341177646647112770727950839029515643589984981094121423221389337601736282556974uwb);\n+  __builtin_memset (&i, 0x55, sizeof (i));\n+  __builtin_memset (&j, 0xaa, sizeof (j));\n+  __builtin_memset (&k, 0x55, sizeof (k));\n+  __builtin_memset (&l, 0xaa, sizeof (l));\n+  __builtin_memset (&m, 0x55, sizeof (m));\n+  __builtin_memset (&n, 0xaa, sizeof (n));\n+  f2 (12345678.5f, -234567891234567.125, 123465987893275.53244532L,\n+      12345678.5f, 234567891234567.125, 123465987893275.53244532L);\n+#endif\n+}\n","prefixes":[]}