]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ipa: Remove LTO requirement for builtin callback carriers.
authorJosef Melcr <josef.melcr@suse.com>
Thu, 20 Nov 2025 22:57:57 +0000 (23:57 +0100)
committerJosef Melcr <josef.melcr@suse.com>
Fri, 21 Nov 2025 08:17:26 +0000 (09:17 +0100)
Due to the if statement in ipa_compute_jump_functions_for_bb, callback
edges were never constructed for builtin functions unless LTO was
enabled.  This patch corrects this behavior, allowing GCC to optimize
callbacks more broadly.  It also extends our testing capabilities.

gcc/ChangeLog:

* attr-callback.cc (callback_edge_callee_has_attr): New
function.
* attr-callback.h (callback_edge_callee_has_attr): New function
decl.
* ipa-prop.cc (ipa_compute_jump_functions_for_bb): Don't skip
callback carriers when calculating jump functions.

libgomp/ChangeLog:

* testsuite/libgomp.c/ipcp-cb-spec1.c: Remove LTO requirement.
* testsuite/libgomp.c/ipcp-cb-spec2.c: Likewise.
* testsuite/libgomp.c/ipcp-cb1.c: Likewise.

Signed-off-by: Josef Melcr <josef.melcr@suse.com>
gcc/attr-callback.cc
gcc/attr-callback.h
gcc/ipa-prop.cc
libgomp/testsuite/libgomp.c/ipcp-cb-spec1.c
libgomp/testsuite/libgomp.c/ipcp-cb-spec2.c
libgomp/testsuite/libgomp.c/ipcp-cb1.c

index 04b5ad0ef119abf7485ea9b44620ba4d29e604d8..f116f0472f32eacb0f043f747d36b54e860cfc74 100644 (file)
@@ -83,6 +83,15 @@ callback_special_case_attr (tree decl)
   gcc_unreachable ();
 }
 
+/* Returns TRUE if the callee of E has a callback attribute.  */
+bool
+callback_edge_callee_has_attr (cgraph_edge *e)
+{
+  return lookup_attribute (CALLBACK_ATTR_IDENT,
+                          DECL_ATTRIBUTES (e->callee->decl))
+        || callback_is_special_cased (e->callee->decl, e->call_stmt);
+}
+
 /* Given an instance of callback attribute, return the 0-based
    index of the called function in question.  */
 int
index b0b08438afbe43f8d60fa7292b2238e83aad498f..39a4fe8ac94effbd5f1f30f15440d552fc11b1aa 100644 (file)
@@ -43,6 +43,9 @@ bool callback_is_special_cased (tree decl, gcall *stmt);
 /* Returns an attribute for a special cased function.  */
 tree callback_special_case_attr (tree decl);
 
+/* Returns TRUE if the callee of E has a callback attribute.  */
+bool callback_edge_callee_has_attr (cgraph_edge *e);
+
 /* Given an instance of callback attribute, return the 0-based
    index of the called function in question.  */
 int callback_get_fn_index (tree cb_attr);
index 1e4b6d4548d97bf8b1f3971a06fb5121cc81e6e7..2debbe10de38509dc508913f748766cfad69344f 100644 (file)
@@ -2698,7 +2698,8 @@ ipa_compute_jump_functions_for_bb (struct ipa_func_body_info *fbi, basic_block b
          /* We do not need to bother analyzing calls to unknown functions
             unless they may become known during lto/whopr.  */
          if (!callee->definition && !flag_lto
-             && !gimple_call_fnspec (cs->call_stmt).known_p ())
+             && !gimple_call_fnspec (cs->call_stmt).known_p ()
+             && !callback_edge_callee_has_attr (cs))
            continue;
        }
       ipa_compute_jump_functions_for_edge (fbi, cs);
index a85e62300f98d9916d146c8c02a164093fb5af24..ff82f4c2f29d9507613326c30e79b6780c14769f 100644 (file)
@@ -1,9 +1,8 @@
 /* Test that GOMP_task is special cased when cpyfn is NULL.  */
 
 /* { dg-do run } */
-/* { dg-options "-O3 -fopenmp -flto -std=gnu99 -fdump-ipa-cp-details" } */
+/* { dg-options "-O3 -fopenmp -std=gnu99 -fdump-ipa-cp-details" } */
 /* { dg-require-effective-target fopenmp } */
-/* { dg-require-effective-target lto } */
 
 void test(int c) {
   for (int i = 0; i < c; i++)
@@ -16,4 +15,4 @@ int main() {
   return 0;
 }
 
-/* { dg-final { scan-wpa-ipa-dump "Creating a specialized node of main._omp_fn" "cp" } } */
+/* { dg-final { scan-ipa-dump "Creating a specialized node of main._omp_fn" "cp" } } */
index 01d7425c99f9d84afb6203aff3c8fff92b1a1204..30894d7d748bcd54ff9136850ab7aa079c6100eb 100644 (file)
@@ -2,9 +2,8 @@
    NULL.  */
 
 /* { dg-do run } */
-/* { dg-options "-O3 -fopenmp -flto -std=gnu99 -fdump-ipa-cp-details" } */
+/* { dg-options "-O3 -fopenmp -std=gnu99 -fdump-ipa-cp-details" } */
 /* { dg-require-effective-target fopenmp } */
-/* { dg-require-effective-target lto } */
 
 void test(int *a) {
   for (int i = 0; i < 100; i++) {
index 3418b5dedab2d68e1b412cb6725dc57875a670b1..e390f04d8cf3f072bccb1f960a72967901453026 100644 (file)
@@ -2,9 +2,8 @@
    This tests the underlying callback attribute and its related edges.  */
 
 /* { dg-do run } */
-/* { dg-options "-O3 -fopenmp -flto -std=gnu99 -fdump-ipa-cp-details" } */
+/* { dg-options "-O3 -fopenmp -std=gnu99 -fdump-ipa-cp-details" } */
 /* { dg-require-effective-target fopenmp } */
-/* { dg-require-effective-target lto } */
 
 int a[100];
 void test(int c) {
@@ -21,5 +20,5 @@ int main() {
   return a[5] - 5;
 }
 
-/* { dg-final { scan-wpa-ipa-dump "Creating a specialized node of test._omp_fn" "cp" } } */
-/* { dg-final { scan-wpa-ipa-dump "Aggregate replacements: 0\\\[0]=100\\(by_ref\\)" "cp" } } */
+/* { dg-final { scan-ipa-dump "Creating a specialized node of test._omp_fn" "cp" } } */
+/* { dg-final { scan-ipa-dump "Aggregate replacements: 0\\\[0]=100\\(by_ref\\)" "cp" } } */