https://gcc.gnu.org/g:b2b5ccb0a2450a812526bdde72545f9c85fce473

commit r16-6232-gb2b5ccb0a2450a812526bdde72545f9c85fce473
Author: Andrew Pinski <[email protected]>
Date:   Tue Dec 16 16:04:18 2025 -0800

    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 <[email protected]>

Diff:
---
 gcc/predict.cc                              | 2 +-
 gcc/testsuite/gcc.target/i386/pr121572-1a.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/gcc/predict.cc b/gcc/predict.cc
index d937cc699b07..704a4b574f97 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 270d8ff5cb6d..c96c3f046a59 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)
 {

Reply via email to