[gcc r17-67] bitintlower: Padding bit fixes, part 5 [PR123635]

Jakub Jelinek jakub@gcc.gnu.org
Fri Apr 24 12:37:13 GMT 2026


https://gcc.gnu.org/g:dcaa624319dc58ed8b1f51f6e0718cba94d7a3b9

commit r17-67-gdcaa624319dc58ed8b1f51f6e0718cba94d7a3b9
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Apr 24 14:36:29 2026 +0200

    bitintlower: Padding bit fixes, part 5 [PR123635]
    
    The following patch is hopefully the last missing part of the _BitInt
    bitint_extended padding bit fixes, this time for
    __builtin_{add,sub,mul}_overflow.  For __builtin_{add,sub}_overflow,
    the extension in the padding bits of a partial limb (if any) is already
    done in some cases during the handling of the limbs (and the last
    hunk in gimple-lower-bitint.cc just adds it to one spot where it was
    missing).  The extension in the padding bits of a full limb of padding
    bits (if any) and for __builtin_mul_overflow partial limb too is done
    in finish_arith_overflow.  If both var and obj are NULL, it is
    __builtin_*_overflow_p or __builtin_*_overflow that ignores the result
    of the operation and only cares about whether it overflowed or not; in
    that case there is nothing to extend.
    
    2026-04-24  Jakub Jelinek  <jakub@redhat.com>
    
            PR middle-end/123635
            PR tree-optimization/124988
            * gimple-lower-bitint.cc (bitint_large_huge::finish_arith_overflow):
            Handle bitint_extend.
            (bitint_large_huge::lower_addsub_overflow): Fix up comment spelling.
            For bitint_extended extend the partial limb if any.
    
            * gcc.dg/torture/bitint-91.c: New test.
            * gcc.dg/torture/bitint-92.c: New test.
            * gcc.dg/torture/bitint-93.c: New test.
            * gcc.dg/torture/bitint-94.c: New test.
            * gcc.dg/torture/bitint-95.c: New test.
    
    Reviewed-by: Richard Biener <rguenth@suse.de>

Diff:
---
 gcc/gimple-lower-bitint.cc               |  67 ++++++++++++++-
 gcc/testsuite/gcc.dg/torture/bitint-91.c | 140 +++++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/torture/bitint-92.c | 140 +++++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/torture/bitint-93.c | 140 +++++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/torture/bitint-94.c | 140 +++++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/torture/bitint-95.c |  22 +++++
 6 files changed, 648 insertions(+), 1 deletion(-)

diff --git a/gcc/gimple-lower-bitint.cc b/gcc/gimple-lower-bitint.cc
index fc8e1c256094..9c4600121d0a 100644
--- a/gcc/gimple-lower-bitint.cc
+++ b/gcc/gimple-lower-bitint.cc
@@ -4478,6 +4478,65 @@ bitint_large_huge::finish_arith_overflow (tree var, tree obj, tree type,
     {
       unsigned HOST_WIDE_INT obj_nelts = 0;
       tree atype = NULL_TREE;
+      if (bitint_extended && (var || obj))
+	{
+	  unsigned prec = TYPE_PRECISION (type);
+	  unsigned prec_limbs = CEIL (prec, limb_prec);
+	  bool ext_ms_limb
+	    = (bitint_extended == bitint_ext_full
+	       && abi_limb_prec > limb_prec
+	       && (CEIL (prec, abi_limb_prec) * abi_limb_prec
+		   > CEIL (prec, limb_prec) * limb_prec));
+	  /* For .{ADD,SUB}_OVERFLOW the partial limb if any is
+	     already extended in lower_addsub_overflow.  */
+	  if ((code == MULT_EXPR && (prec % limb_prec) != 0)
+	      || (ext_ms_limb && !TYPE_UNSIGNED (type)))
+	    {
+	      tree plm1idx = size_int (bitint_big_endian ? 0 : prec_limbs - 1);
+	      tree plm1type = limb_access_type (type, plm1idx);
+	      tree l = limb_access (type, var ? var : obj, plm1idx, true);
+	      tree rhs = make_ssa_name (TREE_TYPE (l));
+	      g = gimple_build_assign (rhs, l);
+	      insert_before (g);
+	      if (code == MULT_EXPR && (prec % limb_prec) != 0)
+		{
+		  if (!useless_type_conversion_p (plm1type, TREE_TYPE (rhs)))
+		    rhs = add_cast (plm1type, rhs);
+		  if (!useless_type_conversion_p (TREE_TYPE (l),
+						  TREE_TYPE (rhs)))
+		    rhs = add_cast (TREE_TYPE (l), rhs);
+		  l = limb_access (type, var ? var : obj, plm1idx, true);
+		  g = gimple_build_assign (l, rhs);
+		  insert_before (g);
+		}
+	      if (ext_ms_limb && !TYPE_UNSIGNED (type))
+		{
+		  rhs = add_cast (signed_type_for (m_limb_type), rhs);
+		  tree lpm1 = build_int_cst (unsigned_type_node,
+					     limb_prec - 1);
+		  tree v = make_ssa_name (TREE_TYPE (rhs));
+		  g = gimple_build_assign (v, RSHIFT_EXPR, rhs, lpm1);
+		  insert_before (g);
+		  unsigned int i
+		    = CEIL (prec, abi_limb_prec) * abi_limb_prec / limb_prec;
+		  v = add_cast (m_limb_type, v);
+		  g = gimple_build_assign (limb_access (type, var ? var : obj,
+							size_int (i - 1),
+							true), v);
+		  insert_before (g);
+		  ext_ms_limb = false;
+		}
+	    }
+	  if (ext_ms_limb)
+	    {
+	      unsigned int i
+		= CEIL (prec, abi_limb_prec) * abi_limb_prec / limb_prec;
+	      g = gimple_build_assign (limb_access (type, var ? var : obj,
+						    size_int (i - 1), true),
+				       build_zero_cst (m_limb_type));
+	      insert_before (g);
+	    }
+	}
       if (obj)
 	{
 	  obj_nelts = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (obj))) / limb_prec;
@@ -4673,7 +4732,7 @@ bitint_large_huge::lower_addsub_overflow (tree obj, gimple *stmt)
   int prec0 = range_to_prec (arg0, stmt);
   int prec1 = range_to_prec (arg1, stmt);
   /* If PREC0 >= 0 && PREC1 >= 0 and CODE is not MINUS_EXPR, PREC2 is
-     the be minimum unsigned precision of any possible operation's
+     the minimum unsigned precision of any possible operation's
      result, otherwise it is minimum signed precision.
      Some examples:
      If PREC0 or PREC1 is 8, it means that argument is [0, 0xff],
@@ -5149,6 +5208,12 @@ bitint_large_huge::lower_addsub_overflow (tree obj, gimple *stmt)
 		    }
 		}
 	      tree l = limb_access (type, var ? var : obj, idxl, true);
+	      if (bitint_extended && tree_fits_uhwi_p (idxl))
+		{
+		  tree atype = limb_access_type (type, idxl);
+		  if (!useless_type_conversion_p (atype, TREE_TYPE (rhs)))
+		    rhs = add_cast (atype, rhs);
+		}
 	      if (!useless_type_conversion_p (TREE_TYPE (l), TREE_TYPE (rhs)))
 		rhs = add_cast (TREE_TYPE (l), rhs);
 	      g = gimple_build_assign (l, rhs);
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-91.c b/gcc/testsuite/gcc.dg/torture/bitint-91.c
new file mode 100644
index 000000000000..ed6d864559c8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-91.c
@@ -0,0 +1,140 @@
+/* PR middle-end/123635 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+#if __BITINT_MAXWIDTH__ >= 513
+_BitInt(513) a, b, c, d;
+unsigned _BitInt(513) e, f, g, h;
+#endif
+
+#include "../bitintext.h"
+
+#if __BITINT_MAXWIDTH__ >= 513
+[[gnu::noipa]] bool
+f1 (_BitInt(513) q, _BitInt(513) r, _BitInt(513) s, _BitInt(513) t,
+    _BitInt(513) u, _BitInt(513) v, _BitInt(513) w, _BitInt(513) x)
+{
+  bool res = false;
+  res |= __builtin_add_overflow (q, r, &a);
+  BEXTC (a);
+  res |= __builtin_add_overflow (s, t, &b);
+  BEXTC (b);
+  res |= __builtin_sub_overflow (u, v, &c);
+  BEXTC (c);
+  res |= __builtin_sub_overflow (w, x, &d);
+  BEXTC (d);
+  return res;
+}
+
+[[gnu::noipa]] bool
+f2 (unsigned _BitInt(513) q, unsigned _BitInt(513) r, unsigned _BitInt(513) s,
+    unsigned _BitInt(513) t, unsigned _BitInt(513) u, unsigned _BitInt(513) v,
+    unsigned _BitInt(513) w, unsigned _BitInt(513) x)
+{
+  bool res = false;
+  res |= __builtin_add_overflow (q, r, &e);
+  BEXTC (e);
+  res |= __builtin_add_overflow (s, t, &f);
+  BEXTC (f);
+  res |= __builtin_sub_overflow (u, v, &g);
+  BEXTC (g);
+  res |= __builtin_sub_overflow (w, x, &h);
+  BEXTC (h);
+  return res;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 1025
+[[gnu::noipa]] bool
+f3 (_BitInt(1025) q, _BitInt(1025) r, _BitInt(1025) s, _BitInt(1025) t,
+    _BitInt(1025) u, _BitInt(1025) v, _BitInt(1025) w, _BitInt(1025) x)
+{
+  bool res = false;
+  res |= __builtin_add_overflow (q, r, &a);
+  BEXTC (a);
+  res |= __builtin_add_overflow (s, t, &b);
+  BEXTC (b);
+  res |= __builtin_sub_overflow (u, v, &c);
+  BEXTC (c);
+  res |= __builtin_sub_overflow (w, x, &d);
+  BEXTC (d);
+  return res;
+}
+
+[[gnu::noipa]] bool
+f4 (unsigned _BitInt(1025) q, unsigned _BitInt(1025) r,
+    unsigned _BitInt(1025) s, unsigned _BitInt(1025) t,
+    unsigned _BitInt(1025) u, unsigned _BitInt(1025) v,
+    unsigned _BitInt(1025) w, unsigned _BitInt(1025) x)
+{
+  bool res = false;
+  res |= __builtin_add_overflow (q, r, &e);
+  BEXTC (e);
+  res |= __builtin_add_overflow (s, t, &f);
+  BEXTC (f);
+  res |= __builtin_sub_overflow (u, v, &g);
+  BEXTC (g);
+  res |= __builtin_sub_overflow (w, x, &h);
+  BEXTC (h);
+  return res;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 513
+  __builtin_memset (&a, 0x55, sizeof (a));
+  __builtin_memset (&b, 0xaa, sizeof (b));
+  __builtin_memset (&c, 0x55, sizeof (c));
+  __builtin_memset (&d, 0xaa, sizeof (d));
+  f1 (9655959669318785079954371230049554909200604556467603939808122955133717885340333846085453917625768204337699198414625928325836300792547598919086330010444969wb,
+      7603664655075175676551887792243938044412742856114886907427675169347553852589402599411290168288930382377283108890322269708884902998253293780483440129483327wb,
+      -10324098565034498465875215630604107238940128063553910460445433007166121079968132667074154355395844552937058899426253790777657675901838010055644316728526393wb,
+      -12236477238783553839340584917720106564483878483173525158555406923388638347150144919001024905877475401353674848301774791298367823029012449896858367218938488wb,
+      9966990594172406012310078765295767555782555285684385899869231608869471023379202086947215337899533069949801311225161562404400717858011700306179102121342515wb,
+      -12983782114594329520373595420695508584715919272703648469298375086460508080215963268729027546042229893937296428010493668720716318664505339275354851120734372wb,
+      -9655954001341551443087909192198932353132996418457245295521644079521230896558300756133292365213357603788911695147437530569709679437147630523365259553067954wb,
+      7072009366582949478473862650011262253783850301083169883440824883235985480601391689101153902500460700035282434290760483209786664550714449512762684388339187wb);
+  __builtin_memset (&e, 0x55, sizeof (e));
+  __builtin_memset (&f, 0xaa, sizeof (f));
+  __builtin_memset (&g, 0x55, sizeof (g));
+  __builtin_memset (&h, 0xaa, sizeof (h));
+  f2 (2964639554149490973596341394839758078409778829067653681666106821776834568408151111543733982288078570825867875863050348925537769671189456471968723686512034uwb,
+      5957364445683686818410817200949409124779631391545643887373796564697563753416937684648786338497928327653380765964317808469492623477785654419190708204181795uwb,
+      19191677104746999910669997770314557441327241058126327798712726258248174396859949489325836442238807787970653545840621658707862487865809500322706194229135252uwb,
+      24586718166970605619478065808613217078037607297232337682881885486187967367467012073369595089067814569116855119567799143349802467998026209123576080005659752uwb,
+      10462823982820178661190434713437061473290880952772417752401116804833406586088773886481041433195457558834409214235712063242433511929332344716172942804205442uwb,
+      16419753656873030796354060609416030388733546880849213639440646945524833982946459564500329809304700518677496254061943255280441489964246119308925190525772266uwb,
+      10405391186665161836576844847101505242465502880093273915903880455941412499859291312405803977208427105275040816651924471784587928355909534429001102837285163uwb,
+      17157919740278597151158601296325640095140225651359053582867340974133209625747219873488488134575281986967033985073454136035802749428039704256375550535464357uwb);
+#endif
+#if __BITINT_MAXWIDTH__ >= 1025
+  __builtin_memset (&a, 0x55, sizeof (a));
+  __builtin_memset (&b, 0xaa, sizeof (b));
+  __builtin_memset (&c, 0x55, sizeof (c));
+  __builtin_memset (&d, 0xaa, sizeof (d));
+  f3 (9655959669318785079954371230049554909200604556467603939808122955133717885340333846085453917625768204337699198414625928325836300792547598919086330010444969wb,
+      7603664655075175676551887792243938044412742856114886907427675169347553852589402599411290168288930382377283108890322269708884902998253293780483440129483327wb,
+      -10324098565034498465875215630604107238940128063553910460445433007166121079968132667074154355395844552937058899426253790777657675901838010055644316728526393wb,
+      -12236477238783553839340584917720106564483878483173525158555406923388638347150144919001024905877475401353674848301774791298367823029012449896858367218938488wb,
+      9966990594172406012310078765295767555782555285684385899869231608869471023379202086947215337899533069949801311225161562404400717858011700306179102121342515wb,
+      -12983782114594329520373595420695508584715919272703648469298375086460508080215963268729027546042229893937296428010493668720716318664505339275354851120734372wb,
+      -9655954001341551443087909192198932353132996418457245295521644079521230896558300756133292365213357603788911695147437530569709679437147630523365259553067954wb,
+      7072009366582949478473862650011262253783850301083169883440824883235985480601391689101153902500460700035282434290760483209786664550714449512762684388339187wb);
+  __builtin_memset (&e, 0x55, sizeof (e));
+  __builtin_memset (&f, 0xaa, sizeof (f));
+  __builtin_memset (&g, 0x55, sizeof (g));
+  __builtin_memset (&h, 0xaa, sizeof (h));
+  f4 (2964639554149490973596341394839758078409778829067653681666106821776834568408151111543733982288078570825867875863050348925537769671189456471968723686512034uwb,
+      5957364445683686818410817200949409124779631391545643887373796564697563753416937684648786338497928327653380765964317808469492623477785654419190708204181795uwb,
+      19191677104746999910669997770314557441327241058126327798712726258248174396859949489325836442238807787970653545840621658707862487865809500322706194229135252uwb,
+      24586718166970605619478065808613217078037607297232337682881885486187967367467012073369595089067814569116855119567799143349802467998026209123576080005659752uwb,
+      10462823982820178661190434713437061473290880952772417752401116804833406586088773886481041433195457558834409214235712063242433511929332344716172942804205442uwb,
+      16419753656873030796354060609416030388733546880849213639440646945524833982946459564500329809304700518677496254061943255280441489964246119308925190525772266uwb,
+      10405391186665161836576844847101505242465502880093273915903880455941412499859291312405803977208427105275040816651924471784587928355909534429001102837285163uwb,
+      17157919740278597151158601296325640095140225651359053582867340974133209625747219873488488134575281986967033985073454136035802749428039704256375550535464357uwb);
+#endif
+}
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-92.c b/gcc/testsuite/gcc.dg/torture/bitint-92.c
new file mode 100644
index 000000000000..f35ed79a7bb2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-92.c
@@ -0,0 +1,140 @@
+/* PR middle-end/123635 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+#if __BITINT_MAXWIDTH__ >= 511
+_BitInt(511) a, b, c, d;
+unsigned _BitInt(511) e, f, g, h;
+#endif
+
+#include "../bitintext.h"
+
+#if __BITINT_MAXWIDTH__ >= 511
+[[gnu::noipa]] bool
+f1 (_BitInt(511) q, _BitInt(511) r, _BitInt(511) s, _BitInt(511) t,
+    _BitInt(511) u, _BitInt(511) v, _BitInt(511) w, _BitInt(511) x)
+{
+  bool res = false;
+  res |= __builtin_add_overflow (q, r, &a);
+  BEXTC (a);
+  res |= __builtin_add_overflow (s, t, &b);
+  BEXTC (b);
+  res |= __builtin_sub_overflow (u, v, &c);
+  BEXTC (c);
+  res |= __builtin_sub_overflow (w, x, &d);
+  BEXTC (d);
+  return res;
+}
+
+[[gnu::noipa]] bool
+f2 (unsigned _BitInt(511) q, unsigned _BitInt(511) r, unsigned _BitInt(511) s,
+    unsigned _BitInt(511) t, unsigned _BitInt(511) u, unsigned _BitInt(511) v,
+    unsigned _BitInt(511) w, unsigned _BitInt(511) x)
+{
+  bool res = false;
+  res |= __builtin_add_overflow (q, r, &e);
+  BEXTC (e);
+  res |= __builtin_add_overflow (s, t, &f);
+  BEXTC (f);
+  res |= __builtin_sub_overflow (u, v, &g);
+  BEXTC (g);
+  res |= __builtin_sub_overflow (w, x, &h);
+  BEXTC (h);
+  return res;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 1023
+[[gnu::noipa]] bool
+f3 (_BitInt(1023) q, _BitInt(1023) r, _BitInt(1023) s, _BitInt(1023) t,
+    _BitInt(1023) u, _BitInt(1023) v, _BitInt(1023) w, _BitInt(1023) x)
+{
+  bool res = false;
+  res |= __builtin_add_overflow (q, r, &a);
+  BEXTC (a);
+  res |= __builtin_add_overflow (s, t, &b);
+  BEXTC (b);
+  res |= __builtin_sub_overflow (u, v, &c);
+  BEXTC (c);
+  res |= __builtin_sub_overflow (w, x, &d);
+  BEXTC (d);
+  return res;
+}
+
+[[gnu::noipa]] bool
+f4 (unsigned _BitInt(1023) q, unsigned _BitInt(1023) r,
+    unsigned _BitInt(1023) s, unsigned _BitInt(1023) t,
+    unsigned _BitInt(1023) u, unsigned _BitInt(1023) v,
+    unsigned _BitInt(1023) w, unsigned _BitInt(1023) x)
+{
+  bool res = false;
+  res |= __builtin_add_overflow (q, r, &e);
+  BEXTC (e);
+  res |= __builtin_add_overflow (s, t, &f);
+  BEXTC (f);
+  res |= __builtin_sub_overflow (u, v, &g);
+  BEXTC (g);
+  res |= __builtin_sub_overflow (w, x, &h);
+  BEXTC (h);
+  return res;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 511
+  __builtin_memset (&a, 0x55, sizeof (a));
+  __builtin_memset (&b, 0xaa, sizeof (b));
+  __builtin_memset (&c, 0x55, sizeof (c));
+  __builtin_memset (&d, 0xaa, sizeof (d));
+  f1 (1390399912725058458200009048198820064492005235154664882378103191585647121798330571086629470693362953212791514491575158989602893218788902339652768462242628wb,
+      249177562235295607181226393168319684003354962277368763264203376508018272147140149371861361061154101827443514415658157865648522550758405852726010180808769wb,
+      -1780354034824880726793039893594299865138723691931754426795433194731471391545042339625233657837435887106690554340836104535849707683265009199435873463559020wb,
+      -740336545197937933670467416719493466419101689845476460441897613938923219348614699785899092241758652210632646359181180435230820349533052964898247331288194wb,
+      1264371856933908934004928210670432922219833109703326669407665736158573607996286450258750907679580905729735376144263375732104941574779989141805339934906103wb,
+      -1800762928143884868360591340947709805381121865559594609800602059770468706915015121333590484473244364203044167384984634798933392092472849088487188206919199wb,
+      -1874437506355165235214302048933351258782970556591446143241539194417790344619692436179305620246514867157285378788470027340983415072326706619779323878095044wb,
+      465089731165341206127432983731596524669687828142734277104372042775063012806153170457800193495447488542433104457447397078966750100194606523184187779891236wb);
+  __builtin_memset (&e, 0x55, sizeof (e));
+  __builtin_memset (&f, 0xaa, sizeof (f));
+  __builtin_memset (&g, 0x55, sizeof (g));
+  __builtin_memset (&h, 0xaa, sizeof (h));
+  f2 (1769288740652242299842741192560763693851113543365386227639113810655132281658311706354953254148690319453722073610881280531971362644037227748091681178317919uwb,
+      6609813168053391222543030306163941663953801084514170716266507032727748531561564744911045686719066313628734721154746698442483812155667254002473644708866548uwb,
+      2165581935187317546841478283262759103626305739168208417811840048675479552879740382682893926794456473657370285890451624909369445002539226077543796184885282uwb,
+      5583940649350967625413437252987234424283831963591403609577766560068787593281191860443568915932187805635333850527113490331304189378639908270408210201131036uwb,
+      4709767295913180049914868365292708657912010821088789452741841268048043047122882916441448275499420638756517585965684291097104349699944179639251796038947955uwb,
+      6280470013560252695084315130173483896550287179700449102345092527255864285425735025909066687910837200841028187788564127729392389462477148514426504126205653uwb,
+      5729764965697040092309843504303102973344572729567710548288594203184644343090550648393517676044608898029180050379384056057530481830153485215690201926045860uwb,
+      2025545578012992696919009225822788038691815646525577733706021933464568718262575612415581176797970841793616511309641023298056786955966008679910134224064441uwb);
+#endif
+#if __BITINT_MAXWIDTH__ >= 1023
+  __builtin_memset (&a, 0x55, sizeof (a));
+  __builtin_memset (&b, 0xaa, sizeof (b));
+  __builtin_memset (&c, 0x55, sizeof (c));
+  __builtin_memset (&d, 0xaa, sizeof (d));
+  f3 (1390399912725058458200009048198820064492005235154664882378103191585647121798330571086629470693362953212791514491575158989602893218788902339652768462242628wb,
+      249177562235295607181226393168319684003354962277368763264203376508018272147140149371861361061154101827443514415658157865648522550758405852726010180808769wb,
+      -1780354034824880726793039893594299865138723691931754426795433194731471391545042339625233657837435887106690554340836104535849707683265009199435873463559020wb,
+      -740336545197937933670467416719493466419101689845476460441897613938923219348614699785899092241758652210632646359181180435230820349533052964898247331288194wb,
+      1264371856933908934004928210670432922219833109703326669407665736158573607996286450258750907679580905729735376144263375732104941574779989141805339934906103wb,
+      -1800762928143884868360591340947709805381121865559594609800602059770468706915015121333590484473244364203044167384984634798933392092472849088487188206919199wb,
+      -1874437506355165235214302048933351258782970556591446143241539194417790344619692436179305620246514867157285378788470027340983415072326706619779323878095044wb,
+      465089731165341206127432983731596524669687828142734277104372042775063012806153170457800193495447488542433104457447397078966750100194606523184187779891236wb);
+  __builtin_memset (&e, 0x55, sizeof (e));
+  __builtin_memset (&f, 0xaa, sizeof (f));
+  __builtin_memset (&g, 0x55, sizeof (g));
+  __builtin_memset (&h, 0xaa, sizeof (h));
+  f4 (1769288740652242299842741192560763693851113543365386227639113810655132281658311706354953254148690319453722073610881280531971362644037227748091681178317919uwb,
+      6609813168053391222543030306163941663953801084514170716266507032727748531561564744911045686719066313628734721154746698442483812155667254002473644708866548uwb,
+      2165581935187317546841478283262759103626305739168208417811840048675479552879740382682893926794456473657370285890451624909369445002539226077543796184885282uwb,
+      5583940649350967625413437252987234424283831963591403609577766560068787593281191860443568915932187805635333850527113490331304189378639908270408210201131036uwb,
+      4709767295913180049914868365292708657912010821088789452741841268048043047122882916441448275499420638756517585965684291097104349699944179639251796038947955uwb,
+      6280470013560252695084315130173483896550287179700449102345092527255864285425735025909066687910837200841028187788564127729392389462477148514426504126205653uwb,
+      5729764965697040092309843504303102973344572729567710548288594203184644343090550648393517676044608898029180050379384056057530481830153485215690201926045860uwb,
+      2025545578012992696919009225822788038691815646525577733706021933464568718262575612415581176797970841793616511309641023298056786955966008679910134224064441uwb);
+#endif
+}
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-93.c b/gcc/testsuite/gcc.dg/torture/bitint-93.c
new file mode 100644
index 000000000000..317a8e17b0c1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-93.c
@@ -0,0 +1,140 @@
+/* PR middle-end/123635 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+#if __BITINT_MAXWIDTH__ >= 513
+_BitInt(513) a, b, c, d;
+unsigned _BitInt(513) e, f, g, h;
+#endif
+
+#include "../bitintext.h"
+
+#if __BITINT_MAXWIDTH__ >= 513
+[[gnu::noipa]] bool
+f1 (_BitInt(513) q, _BitInt(513) r, _BitInt(513) s, _BitInt(513) t,
+    _BitInt(513) u, _BitInt(513) v, _BitInt(513) w, _BitInt(513) x)
+{
+  bool res = false;
+  res |= __builtin_mul_overflow (q, r, &a);
+  BEXTC (a);
+  res |= __builtin_mul_overflow (s, t, &b);
+  BEXTC (b);
+  res |= __builtin_mul_overflow (u, v, &c);
+  BEXTC (c);
+  res |= __builtin_mul_overflow (w, x, &d);
+  BEXTC (d);
+  return res;
+}
+
+[[gnu::noipa]] bool
+f2 (unsigned _BitInt(513) q, unsigned _BitInt(513) r, unsigned _BitInt(513) s,
+    unsigned _BitInt(513) t, unsigned _BitInt(513) u, unsigned _BitInt(513) v,
+    unsigned _BitInt(513) w, unsigned _BitInt(513) x)
+{
+  bool res = false;
+  res |= __builtin_mul_overflow (q, r, &e);
+  BEXTC (e);
+  res |= __builtin_mul_overflow (s, t, &f);
+  BEXTC (f);
+  res |= __builtin_mul_overflow (u, v, &g);
+  BEXTC (g);
+  res |= __builtin_mul_overflow (w, x, &h);
+  BEXTC (h);
+  return res;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 1025
+[[gnu::noipa]] bool
+f3 (_BitInt(1025) q, _BitInt(1025) r, _BitInt(1025) s, _BitInt(1025) t,
+    _BitInt(1025) u, _BitInt(1025) v, _BitInt(1025) w, _BitInt(1025) x)
+{
+  bool res = false;
+  res |= __builtin_mul_overflow (q, r, &a);
+  BEXTC (a);
+  res |= __builtin_mul_overflow (s, t, &b);
+  BEXTC (b);
+  res |= __builtin_mul_overflow (u, v, &c);
+  BEXTC (c);
+  res |= __builtin_mul_overflow (w, x, &d);
+  BEXTC (d);
+  return res;
+}
+
+[[gnu::noipa]] bool
+f4 (unsigned _BitInt(1025) q, unsigned _BitInt(1025) r,
+    unsigned _BitInt(1025) s, unsigned _BitInt(1025) t,
+    unsigned _BitInt(1025) u, unsigned _BitInt(1025) v,
+    unsigned _BitInt(1025) w, unsigned _BitInt(1025) x)
+{
+  bool res = false;
+  res |= __builtin_mul_overflow (q, r, &e);
+  BEXTC (e);
+  res |= __builtin_mul_overflow (s, t, &f);
+  BEXTC (f);
+  res |= __builtin_mul_overflow (u, v, &g);
+  BEXTC (g);
+  res |= __builtin_mul_overflow (w, x, &h);
+  BEXTC (h);
+  return res;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 513
+  __builtin_memset (&a, 0x55, sizeof (a));
+  __builtin_memset (&b, 0xaa, sizeof (b));
+  __builtin_memset (&c, 0x55, sizeof (c));
+  __builtin_memset (&d, 0xaa, sizeof (d));
+  f1 (9655959669318785079954371230049554909200604556467603939808122955133717885340333846085453917625768204337699198414625928325836300792547598919086330010444969wb,
+      7603664655075175676551887792243938044412742856114886907427675169347553852589402599411290168288930382377283108890322269708884902998253293780483440129483327wb,
+      -10324098565034498465875215630604107238940128063553910460445433007166121079968132667074154355395844552937058899426253790777657675901838010055644316728526393wb,
+      -12236477238783553839340584917720106564483878483173525158555406923388638347150144919001024905877475401353674848301774791298367823029012449896858367218938488wb,
+      9966990594172406012310078765295767555782555285684385899869231608869471023379202086947215337899533069949801311225161562404400717858011700306179102121342515wb,
+      -12983782114594329520373595420695508584715919272703648469298375086460508080215963268729027546042229893937296428010493668720716318664505339275354851120734372wb,
+      -9655954001341551443087909192198932353132996418457245295521644079521230896558300756133292365213357603788911695147437530569709679437147630523365259553067954wb,
+      7072009366582949478473862650011262253783850301083169883440824883235985480601391689101153902500460700035282434290760483209786664550714449512762684388339187wb);
+  __builtin_memset (&e, 0x55, sizeof (e));
+  __builtin_memset (&f, 0xaa, sizeof (f));
+  __builtin_memset (&g, 0x55, sizeof (g));
+  __builtin_memset (&h, 0xaa, sizeof (h));
+  f2 (2964639554149490973596341394839758078409778829067653681666106821776834568408151111543733982288078570825867875863050348925537769671189456471968723686512034uwb,
+      5957364445683686818410817200949409124779631391545643887373796564697563753416937684648786338497928327653380765964317808469492623477785654419190708204181795uwb,
+      19191677104746999910669997770314557441327241058126327798712726258248174396859949489325836442238807787970653545840621658707862487865809500322706194229135252uwb,
+      24586718166970605619478065808613217078037607297232337682881885486187967367467012073369595089067814569116855119567799143349802467998026209123576080005659752uwb,
+      10462823982820178661190434713437061473290880952772417752401116804833406586088773886481041433195457558834409214235712063242433511929332344716172942804205442uwb,
+      16419753656873030796354060609416030388733546880849213639440646945524833982946459564500329809304700518677496254061943255280441489964246119308925190525772266uwb,
+      10405391186665161836576844847101505242465502880093273915903880455941412499859291312405803977208427105275040816651924471784587928355909534429001102837285163uwb,
+      17157919740278597151158601296325640095140225651359053582867340974133209625747219873488488134575281986967033985073454136035802749428039704256375550535464357uwb);
+#endif
+#if __BITINT_MAXWIDTH__ >= 1025
+  __builtin_memset (&a, 0x55, sizeof (a));
+  __builtin_memset (&b, 0xaa, sizeof (b));
+  __builtin_memset (&c, 0x55, sizeof (c));
+  __builtin_memset (&d, 0xaa, sizeof (d));
+  f3 (9655959669318785079954371230049554909200604556467603939808122955133717885340333846085453917625768204337699198414625928325836300792547598919086330010444969wb,
+      7603664655075175676551887792243938044412742856114886907427675169347553852589402599411290168288930382377283108890322269708884902998253293780483440129483327wb,
+      -10324098565034498465875215630604107238940128063553910460445433007166121079968132667074154355395844552937058899426253790777657675901838010055644316728526393wb,
+      -12236477238783553839340584917720106564483878483173525158555406923388638347150144919001024905877475401353674848301774791298367823029012449896858367218938488wb,
+      9966990594172406012310078765295767555782555285684385899869231608869471023379202086947215337899533069949801311225161562404400717858011700306179102121342515wb,
+      -12983782114594329520373595420695508584715919272703648469298375086460508080215963268729027546042229893937296428010493668720716318664505339275354851120734372wb,
+      -9655954001341551443087909192198932353132996418457245295521644079521230896558300756133292365213357603788911695147437530569709679437147630523365259553067954wb,
+      7072009366582949478473862650011262253783850301083169883440824883235985480601391689101153902500460700035282434290760483209786664550714449512762684388339187wb);
+  __builtin_memset (&e, 0x55, sizeof (e));
+  __builtin_memset (&f, 0xaa, sizeof (f));
+  __builtin_memset (&g, 0x55, sizeof (g));
+  __builtin_memset (&h, 0xaa, sizeof (h));
+  f4 (2964639554149490973596341394839758078409778829067653681666106821776834568408151111543733982288078570825867875863050348925537769671189456471968723686512034uwb,
+      5957364445683686818410817200949409124779631391545643887373796564697563753416937684648786338497928327653380765964317808469492623477785654419190708204181795uwb,
+      19191677104746999910669997770314557441327241058126327798712726258248174396859949489325836442238807787970653545840621658707862487865809500322706194229135252uwb,
+      24586718166970605619478065808613217078037607297232337682881885486187967367467012073369595089067814569116855119567799143349802467998026209123576080005659752uwb,
+      10462823982820178661190434713437061473290880952772417752401116804833406586088773886481041433195457558834409214235712063242433511929332344716172942804205442uwb,
+      16419753656873030796354060609416030388733546880849213639440646945524833982946459564500329809304700518677496254061943255280441489964246119308925190525772266uwb,
+      10405391186665161836576844847101505242465502880093273915903880455941412499859291312405803977208427105275040816651924471784587928355909534429001102837285163uwb,
+      17157919740278597151158601296325640095140225651359053582867340974133209625747219873488488134575281986967033985073454136035802749428039704256375550535464357uwb);
+#endif
+}
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-94.c b/gcc/testsuite/gcc.dg/torture/bitint-94.c
new file mode 100644
index 000000000000..d7726539bb64
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-94.c
@@ -0,0 +1,140 @@
+/* PR middle-end/123635 */
+/* { dg-do run { target bitint } } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+/* { dg-skip-if "" { ! run_expensive_tests }  { "*" } { "-O0" "-O2" } } */
+/* { dg-skip-if "" { ! run_expensive_tests } { "-flto" } { "" } } */
+
+#if __BITINT_MAXWIDTH__ >= 511
+_BitInt(511) a, b, c, d;
+unsigned _BitInt(511) e, f, g, h;
+#endif
+
+#include "../bitintext.h"
+
+#if __BITINT_MAXWIDTH__ >= 511
+[[gnu::noipa]] bool
+f1 (_BitInt(511) q, _BitInt(511) r, _BitInt(511) s, _BitInt(511) t,
+    _BitInt(511) u, _BitInt(511) v, _BitInt(511) w, _BitInt(511) x)
+{
+  bool res = false;
+  res |= __builtin_mul_overflow (q, r, &a);
+  BEXTC (a);
+  res |= __builtin_mul_overflow (s, t, &b);
+  BEXTC (b);
+  res |= __builtin_mul_overflow (u, v, &c);
+  BEXTC (c);
+  res |= __builtin_mul_overflow (w, x, &d);
+  BEXTC (d);
+  return res;
+}
+
+[[gnu::noipa]] bool
+f2 (unsigned _BitInt(511) q, unsigned _BitInt(511) r, unsigned _BitInt(511) s,
+    unsigned _BitInt(511) t, unsigned _BitInt(511) u, unsigned _BitInt(511) v,
+    unsigned _BitInt(511) w, unsigned _BitInt(511) x)
+{
+  bool res = false;
+  res |= __builtin_mul_overflow (q, r, &e);
+  BEXTC (e);
+  res |= __builtin_mul_overflow (s, t, &f);
+  BEXTC (f);
+  res |= __builtin_mul_overflow (u, v, &g);
+  BEXTC (g);
+  res |= __builtin_mul_overflow (w, x, &h);
+  BEXTC (h);
+  return res;
+}
+#endif
+
+#if __BITINT_MAXWIDTH__ >= 1023
+[[gnu::noipa]] bool
+f3 (_BitInt(1023) q, _BitInt(1023) r, _BitInt(1023) s, _BitInt(1023) t,
+    _BitInt(1023) u, _BitInt(1023) v, _BitInt(1023) w, _BitInt(1023) x)
+{
+  bool res = false;
+  res |= __builtin_mul_overflow (q, r, &a);
+  BEXTC (a);
+  res |= __builtin_mul_overflow (s, t, &b);
+  BEXTC (b);
+  res |= __builtin_mul_overflow (u, v, &c);
+  BEXTC (c);
+  res |= __builtin_mul_overflow (w, x, &d);
+  BEXTC (d);
+  return res;
+}
+
+[[gnu::noipa]] bool
+f4 (unsigned _BitInt(1023) q, unsigned _BitInt(1023) r,
+    unsigned _BitInt(1023) s, unsigned _BitInt(1023) t,
+    unsigned _BitInt(1023) u, unsigned _BitInt(1023) v,
+    unsigned _BitInt(1023) w, unsigned _BitInt(1023) x)
+{
+  bool res = false;
+  res |= __builtin_mul_overflow (q, r, &e);
+  BEXTC (e);
+  res |= __builtin_mul_overflow (s, t, &f);
+  BEXTC (f);
+  res |= __builtin_mul_overflow (u, v, &g);
+  BEXTC (g);
+  res |= __builtin_mul_overflow (w, x, &h);
+  BEXTC (h);
+  return res;
+}
+#endif
+
+int
+main ()
+{
+#if __BITINT_MAXWIDTH__ >= 511
+  __builtin_memset (&a, 0x55, sizeof (a));
+  __builtin_memset (&b, 0xaa, sizeof (b));
+  __builtin_memset (&c, 0x55, sizeof (c));
+  __builtin_memset (&d, 0xaa, sizeof (d));
+  f1 (1390399912725058458200009048198820064492005235154664882378103191585647121798330571086629470693362953212791514491575158989602893218788902339652768462242628wb,
+      249177562235295607181226393168319684003354962277368763264203376508018272147140149371861361061154101827443514415658157865648522550758405852726010180808769wb,
+      -1780354034824880726793039893594299865138723691931754426795433194731471391545042339625233657837435887106690554340836104535849707683265009199435873463559020wb,
+      -740336545197937933670467416719493466419101689845476460441897613938923219348614699785899092241758652210632646359181180435230820349533052964898247331288194wb,
+      1264371856933908934004928210670432922219833109703326669407665736158573607996286450258750907679580905729735376144263375732104941574779989141805339934906103wb,
+      -1800762928143884868360591340947709805381121865559594609800602059770468706915015121333590484473244364203044167384984634798933392092472849088487188206919199wb,
+      -1874437506355165235214302048933351258782970556591446143241539194417790344619692436179305620246514867157285378788470027340983415072326706619779323878095044wb,
+      465089731165341206127432983731596524669687828142734277104372042775063012806153170457800193495447488542433104457447397078966750100194606523184187779891236wb);
+  __builtin_memset (&e, 0x55, sizeof (e));
+  __builtin_memset (&f, 0xaa, sizeof (f));
+  __builtin_memset (&g, 0x55, sizeof (g));
+  __builtin_memset (&h, 0xaa, sizeof (h));
+  f2 (1769288740652242299842741192560763693851113543365386227639113810655132281658311706354953254148690319453722073610881280531971362644037227748091681178317919uwb,
+      6609813168053391222543030306163941663953801084514170716266507032727748531561564744911045686719066313628734721154746698442483812155667254002473644708866548uwb,
+      2165581935187317546841478283262759103626305739168208417811840048675479552879740382682893926794456473657370285890451624909369445002539226077543796184885282uwb,
+      5583940649350967625413437252987234424283831963591403609577766560068787593281191860443568915932187805635333850527113490331304189378639908270408210201131036uwb,
+      4709767295913180049914868365292708657912010821088789452741841268048043047122882916441448275499420638756517585965684291097104349699944179639251796038947955uwb,
+      6280470013560252695084315130173483896550287179700449102345092527255864285425735025909066687910837200841028187788564127729392389462477148514426504126205653uwb,
+      5729764965697040092309843504303102973344572729567710548288594203184644343090550648393517676044608898029180050379384056057530481830153485215690201926045860uwb,
+      2025545578012992696919009225822788038691815646525577733706021933464568718262575612415581176797970841793616511309641023298056786955966008679910134224064441uwb);
+#endif
+#if __BITINT_MAXWIDTH__ >= 1023
+  __builtin_memset (&a, 0x55, sizeof (a));
+  __builtin_memset (&b, 0xaa, sizeof (b));
+  __builtin_memset (&c, 0x55, sizeof (c));
+  __builtin_memset (&d, 0xaa, sizeof (d));
+  f3 (1390399912725058458200009048198820064492005235154664882378103191585647121798330571086629470693362953212791514491575158989602893218788902339652768462242628wb,
+      249177562235295607181226393168319684003354962277368763264203376508018272147140149371861361061154101827443514415658157865648522550758405852726010180808769wb,
+      -1780354034824880726793039893594299865138723691931754426795433194731471391545042339625233657837435887106690554340836104535849707683265009199435873463559020wb,
+      -740336545197937933670467416719493466419101689845476460441897613938923219348614699785899092241758652210632646359181180435230820349533052964898247331288194wb,
+      1264371856933908934004928210670432922219833109703326669407665736158573607996286450258750907679580905729735376144263375732104941574779989141805339934906103wb,
+      -1800762928143884868360591340947709805381121865559594609800602059770468706915015121333590484473244364203044167384984634798933392092472849088487188206919199wb,
+      -1874437506355165235214302048933351258782970556591446143241539194417790344619692436179305620246514867157285378788470027340983415072326706619779323878095044wb,
+      465089731165341206127432983731596524669687828142734277104372042775063012806153170457800193495447488542433104457447397078966750100194606523184187779891236wb);
+  __builtin_memset (&e, 0x55, sizeof (e));
+  __builtin_memset (&f, 0xaa, sizeof (f));
+  __builtin_memset (&g, 0x55, sizeof (g));
+  __builtin_memset (&h, 0xaa, sizeof (h));
+  f4 (1769288740652242299842741192560763693851113543365386227639113810655132281658311706354953254148690319453722073610881280531971362644037227748091681178317919uwb,
+      6609813168053391222543030306163941663953801084514170716266507032727748531561564744911045686719066313628734721154746698442483812155667254002473644708866548uwb,
+      2165581935187317546841478283262759103626305739168208417811840048675479552879740382682893926794456473657370285890451624909369445002539226077543796184885282uwb,
+      5583940649350967625413437252987234424283831963591403609577766560068787593281191860443568915932187805635333850527113490331304189378639908270408210201131036uwb,
+      4709767295913180049914868365292708657912010821088789452741841268048043047122882916441448275499420638756517585965684291097104349699944179639251796038947955uwb,
+      6280470013560252695084315130173483896550287179700449102345092527255864285425735025909066687910837200841028187788564127729392389462477148514426504126205653uwb,
+      5729764965697040092309843504303102973344572729567710548288594203184644343090550648393517676044608898029180050379384056057530481830153485215690201926045860uwb,
+      2025545578012992696919009225822788038691815646525577733706021933464568718262575612415581176797970841793616511309641023298056786955966008679910134224064441uwb);
+#endif
+}
diff --git a/gcc/testsuite/gcc.dg/torture/bitint-95.c b/gcc/testsuite/gcc.dg/torture/bitint-95.c
new file mode 100644
index 000000000000..b322e7c41a9e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/bitint-95.c
@@ -0,0 +1,22 @@
+/* PR tree-optimization/124988 */
+/* { dg-do run } */
+
+int a;
+unsigned _BitInt(132) b;
+
+unsigned _BitInt(128)
+foo (unsigned _BitInt(192) d)
+{
+  bool o = __builtin_mul_overflow (d, 1, &b);
+  if (!o)
+    __atomic_sub_fetch (&a, 1, 0);
+  return b >> 8;
+}
+
+int
+main ()
+{
+  unsigned _BitInt(128) x = foo (0x1100ffeeddccbbaa998877665544332211wb);
+  if (x != 0x100ffeeddccbbaa9988776655443322wb)
+    __builtin_abort ();
+}


More information about the Gcc-cvs mailing list