]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
expand: Reduce unneeded _BitInt extensions
authorYang Yujie <yangyujie@loongson.cn>
Tue, 5 Aug 2025 10:53:27 +0000 (12:53 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 5 Aug 2025 10:57:27 +0000 (12:57 +0200)
For targets that set the "extended" flag in TARGET_C_BITINT_TYPE_INFO,
we assume small _BitInts to be internally extended after arithmetic
operations. In this case, an extra extension during RTL expansion
can be avoided.

* expr.cc (expand_expr_real_1): Do not call
reduce_to_bit_field_precision if the target assumes the _BitInt
results to be already extended.
(EXTEND_BITINT): Same.
* expr.h (bitint_extended): Declare the cache variable.
* function.cc (prepare_function_start): Initialize it.

gcc/expr.cc
gcc/expr.h
gcc/function.cc

index 3f2b121ee038faa527e39f128f5a30a0ff380c5d..3d2b253515854abe30f58fc199726489870d21df 100644 (file)
@@ -76,6 +76,10 @@ along with GCC; see the file COPYING3.  If not see
    the same indirect address eventually.  */
 int cse_not_expected;
 
+/* Cache of the "extended" flag in the target's _BitInt description
+   for use during expand.  */
+int bitint_extended = -1;
+
 static bool block_move_libcall_safe_for_call_parm (void);
 static bool emit_block_move_via_pattern (rtx, rtx, rtx, unsigned, unsigned,
                                         HOST_WIDE_INT, unsigned HOST_WIDE_INT,
@@ -11280,6 +11284,7 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
      when reading from SSA_NAMEs of vars.  */
 #define EXTEND_BITINT(expr) \
   ((TREE_CODE (type) == BITINT_TYPE                                    \
+    && !bitint_extended                                                        \
     && reduce_bit_field                                                        \
     && mode != BLKmode                                                 \
     && modifier != EXPAND_MEMORY                                       \
@@ -11291,6 +11296,13 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
   type = TREE_TYPE (exp);
   mode = TYPE_MODE (type);
   unsignedp = TYPE_UNSIGNED (type);
+  if (TREE_CODE (type) == BITINT_TYPE && bitint_extended == -1)
+    {
+      struct bitint_info info;
+      bool ok = targetm.c.bitint_type_info (TYPE_PRECISION (type), &info);
+      gcc_assert (ok);
+      bitint_extended = info.extended;
+    }
 
   treeop0 = treeop1 = treeop2 = NULL_TREE;
   if (!VL_EXP_CLASS_P (exp))
index 53ab625787ec9b0f949ee6971a7d611813a55b74..060151df0109c2d2b13e60478f698ad2770fee54 100644 (file)
@@ -388,4 +388,8 @@ extern void expand_crc_table_based (rtx, rtx, rtx, rtx, machine_mode);
 extern void expand_reversed_crc_table_based (rtx, rtx, rtx, rtx, machine_mode,
                                             void (*) (rtx *));
 
+/* Cache of the "extended" flag in the target's _BitInt description
+   for use during expand.  */
+extern int bitint_extended;
+
 #endif /* GCC_EXPR_H */
index 2b77bbd8bb320f60a58c27c48b1c4b52a62cbcaa..5a054a945c2a48b6ff888beac8336cf04558c412 100644 (file)
@@ -4965,6 +4965,10 @@ prepare_function_start (void)
 
   /* Indicate we have no need of a frame pointer yet.  */
   frame_pointer_needed = 0;
+
+  /* Reset the cache of the "extended" flag in the target's
+     _BitInt info struct.  */
+  bitint_extended = -1;
 }
 
 void