From: Andrew Pinski Date: Wed, 17 Dec 2025 00:04:18 +0000 (-0800) Subject: predict: Fix return value in unlikely_executed_stmt_p for __builtin_unreachable/__bui... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b2b5ccb0a2450a812526bdde72545f9c85fce473;p=thirdparty%2Fgcc.git predict: Fix return value in unlikely_executed_stmt_p for __builtin_unreachable/__builtin_trap 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 --- diff --git a/gcc/predict.cc b/gcc/predict.cc index d937cc699b0..704a4b574f9 100644 --- a/gcc/predict.cc +++ b/gcc/predict.cc @@ -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 diff --git a/gcc/testsuite/gcc.target/i386/pr121572-1a.c b/gcc/testsuite/gcc.target/i386/pr121572-1a.c index 270d8ff5cb6..c96c3f046a5 100644 --- a/gcc/testsuite/gcc.target/i386/pr121572-1a.c +++ b/gcc/testsuite/gcc.target/i386/pr121572-1a.c @@ -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) {