]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
predict: Fix return value in unlikely_executed_stmt_p for __builtin_unreachable/__bui...
authorAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Wed, 17 Dec 2025 00:04:18 +0000 (16:04 -0800)
committerAndrew Pinski <andrew.pinski@oss.qualcomm.com>
Thu, 18 Dec 2025 02:51:18 +0000 (18:51 -0800)
Looks like Honza messed up the return value for __builtin_unreachable/__builtin_trap
in unlikely_executed_stmt_p (with r16-2639-g1d3e713dda99e2). These are inserted
by the user or optimizers but they are always unlikely. So fix the return value
to be true for these.

A minor update to gcc.target/i386/pr121572-1a.c is needed as the never executed
predicate causes the trap instruction (ud2) to be in a new partition which interfers
with the dg-final check-body check. Also the code generation goes back to what it
was in GCC 15 also.

Bootstrapped and tested on x86_64-linux-gnu.

gcc/ChangeLog:

* predict.cc (unlikely_executed_stmt_p): Fix up return for
__builtin_unreachable/__builtin_trap.

gcc/testsuite/ChangeLog:

* gcc.target/i386/pr121572-1a.c: Turn off -freorder-blocks-and-partition
as it interferes with the check-body.

Signed-off-by: Andrew Pinski <andrew.pinski@oss.qualcomm.com>
gcc/predict.cc
gcc/testsuite/gcc.target/i386/pr121572-1a.c

index d937cc699b0754fc6edf47d0ec3c719bf62945c8..704a4b574f97fbd774617f8fa9745cd8e0eafe2b 100644 (file)
@@ -839,7 +839,7 @@ unlikely_executed_stmt_p (gimple *stmt)
   if (gimple_call_builtin_p (stmt, BUILT_IN_UNREACHABLE)
       || gimple_call_builtin_p (stmt, BUILT_IN_UNREACHABLE_TRAP)
       || gimple_call_builtin_p (stmt, BUILT_IN_TRAP))
-    return false;
+    return true;
 
   /* Checks below do not need to be fully reliable.  Cold attribute may be
      misplaced by user and in the presence of comdat we may result in call to
index 270d8ff5cb6da7503343f469ab351240c06c1802..c96c3f046a59998b0cac42ee7290e1d25b00465b 100644 (file)
@@ -19,7 +19,7 @@ extern __thread int tv_cache __attribute__ ((visibility ("hidden")));
 extern void use_cache (int);
 extern int val (int v);
 
-__attribute__ ((optimize (2)))
+__attribute__ ((optimize (2,"-fno-reorder-blocks-and-partition")))
 void
 bug (void)
 {