]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: Replace INTEGER_CST + expand_normal with tree_to_uwhi. [PR126363] master trunk
authorKael Andrew Alonzo Franco <kaelfandrew@gmail.com>
Fri, 24 Jul 2026 12:42:44 +0000 (08:42 -0400)
committerKael Andrew Alonzo Franco <kaelfandrew@gmail.com>
Fri, 24 Jul 2026 12:42:44 +0000 (08:42 -0400)
Replace INTEGER_CST + expand_normal with tree_fits_uwhi_p + tree_to_uwhi
since it is less expensive and is more readable.

Bootstrapped and regtested on x86_64-pc-linux-gnu.

PR middle-end/126363

gcc/ChangeLog:

* builtins.cc (fold_builtin_atomic_always_lock_free): Replace
INTEGER_CST + expand_normal with tree_to_uwhi.

Signed-off-by: Kael Andrew Franco <kaelfandrew@gmail.com>
gcc/builtins.cc

index 52dd51bad5574686f901a1edadba4f64e7fe94a9..b0083186462faae137ce38e3b45e7446f0848165 100644 (file)
@@ -7260,23 +7260,23 @@ expand_builtin_atomic_test_and_set (tree exp, rtx target)
 static tree
 fold_builtin_atomic_always_lock_free (tree arg0, tree arg1)
 {
-  int size;
+  HOST_WIDE_INT size;
   machine_mode mode;
   unsigned int mode_align, type_align;
 
-  if (TREE_CODE (arg0) != INTEGER_CST)
+  if (!tree_fits_shwi_p (arg0))
     return NULL_TREE;
 
   /* We need a corresponding integer mode for the access to be lock-free.  */
-  size = INTVAL (expand_normal (arg0)) * BITS_PER_UNIT;
+  size = tree_to_shwi (arg0) * BITS_PER_UNIT;
   if (!int_mode_for_size (size, 0).exists (&mode))
     return boolean_false_node;
 
   mode_align = GET_MODE_ALIGNMENT (mode);
 
-  if (TREE_CODE (arg1) == INTEGER_CST)
+  if (tree_fits_uhwi_p (arg1))
     {
-      unsigned HOST_WIDE_INT val = UINTVAL (expand_normal (arg1));
+      unsigned HOST_WIDE_INT val = tree_to_uhwi (arg1);
 
       /* Either this argument is null, or it's a fake pointer encoding
          the alignment of the object.  */