aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-fold.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/gimple-fold.cc')
-rw-r--r--gcc/gimple-fold.cc82
1 files changed, 78 insertions, 4 deletions
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc
index fd01810..a25b2fd 100644
--- a/gcc/gimple-fold.cc
+++ b/gcc/gimple-fold.cc
@@ -1475,8 +1475,9 @@ gimple_fold_builtin_memset (gimple_stmt_iterator *gsi, tree c, tree len)
if (TREE_CODE (etype) == ARRAY_TYPE)
etype = TREE_TYPE (etype);
- if (!INTEGRAL_TYPE_P (etype)
- && !POINTER_TYPE_P (etype))
+ if ((!INTEGRAL_TYPE_P (etype)
+ && !POINTER_TYPE_P (etype))
+ || TREE_CODE (etype) == BITINT_TYPE)
return NULL_TREE;
if (! var_decl_component_p (var))
@@ -4102,8 +4103,8 @@ gimple_fold_builtin_realloc (gimple_stmt_iterator *gsi)
return false;
}
-/* Number of bytes into which any type but aggregate or vector types
- should fit. */
+/* Number of bytes into which any type but aggregate, vector or
+ _BitInt types should fit. */
static constexpr size_t clear_padding_unit
= MAX_BITSIZE_MODE_ANY_MODE / BITS_PER_UNIT;
/* Buffer size on which __builtin_clear_padding folding code works. */
@@ -4594,6 +4595,26 @@ clear_padding_real_needs_padding_p (tree type)
&& (fmt->signbit_ro == 79 || fmt->signbit_ro == 95));
}
+/* _BitInt has padding bits if it isn't extended in the ABI and has smaller
+ precision than bits in limb or corresponding number of limbs. */
+
+static bool
+clear_padding_bitint_needs_padding_p (tree type)
+{
+ struct bitint_info info;
+ gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info));
+ if (info.extended)
+ return false;
+ scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode);
+ if (TYPE_PRECISION (type) < GET_MODE_PRECISION (limb_mode))
+ return true;
+ else if (TYPE_PRECISION (type) == GET_MODE_PRECISION (limb_mode))
+ return false;
+ else
+ return (((unsigned) TYPE_PRECISION (type))
+ % GET_MODE_PRECISION (limb_mode)) != 0;
+}
+
/* Return true if TYPE might contain any padding bits. */
bool
@@ -4610,6 +4631,8 @@ clear_padding_type_may_have_padding_p (tree type)
return clear_padding_type_may_have_padding_p (TREE_TYPE (type));
case REAL_TYPE:
return clear_padding_real_needs_padding_p (type);
+ case BITINT_TYPE:
+ return clear_padding_bitint_needs_padding_p (type);
default:
return false;
}
@@ -4854,6 +4877,57 @@ clear_padding_type (clear_padding_struct *buf, tree type,
memset (buf->buf + buf->size, ~0, sz);
buf->size += sz;
break;
+ case BITINT_TYPE:
+ {
+ struct bitint_info info;
+ gcc_assert (targetm.c.bitint_type_info (TYPE_PRECISION (type), &info));
+ scalar_int_mode limb_mode = as_a <scalar_int_mode> (info.limb_mode);
+ if (TYPE_PRECISION (type) <= GET_MODE_PRECISION (limb_mode))
+ {
+ gcc_assert ((size_t) sz <= clear_padding_unit);
+ if ((unsigned HOST_WIDE_INT) sz + buf->size
+ > clear_padding_buf_size)
+ clear_padding_flush (buf, false);
+ if (!info.extended
+ && TYPE_PRECISION (type) < GET_MODE_PRECISION (limb_mode))
+ {
+ int tprec = GET_MODE_PRECISION (limb_mode);
+ int prec = TYPE_PRECISION (type);
+ tree t = build_nonstandard_integer_type (tprec, 1);
+ tree cst = wide_int_to_tree (t, wi::mask (prec, true, tprec));
+ int len = native_encode_expr (cst, buf->buf + buf->size, sz);
+ gcc_assert (len > 0 && (size_t) len == (size_t) sz);
+ }
+ else
+ memset (buf->buf + buf->size, 0, sz);
+ buf->size += sz;
+ break;
+ }
+ tree limbtype
+ = build_nonstandard_integer_type (GET_MODE_PRECISION (limb_mode), 1);
+ fldsz = int_size_in_bytes (limbtype);
+ nelts = int_size_in_bytes (type) / fldsz;
+ for (HOST_WIDE_INT i = 0; i < nelts; i++)
+ {
+ if (!info.extended
+ && i == (info.big_endian ? 0 : nelts - 1)
+ && (((unsigned) TYPE_PRECISION (type))
+ % TYPE_PRECISION (limbtype)) != 0)
+ {
+ int tprec = GET_MODE_PRECISION (limb_mode);
+ int prec = (((unsigned) TYPE_PRECISION (type)) % tprec);
+ tree cst = wide_int_to_tree (limbtype,
+ wi::mask (prec, true, tprec));
+ int len = native_encode_expr (cst, buf->buf + buf->size,
+ fldsz);
+ gcc_assert (len > 0 && (size_t) len == (size_t) fldsz);
+ buf->size += fldsz;
+ }
+ else
+ clear_padding_type (buf, limbtype, fldsz, for_auto_init);
+ }
+ break;
+ }
default:
gcc_assert ((size_t) sz <= clear_padding_unit);
if ((unsigned HOST_WIDE_INT) sz + buf->size > clear_padding_buf_size)