Bug 80411 - DCE vs. offloading
Summary: DCE vs. offloading
Status: RESOLVED DUPLICATE of bug 83046
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: openacc, openmp
Depends on:
Blocks:
 
Reported: 2017-04-12 09:59 UTC by Thomas Schwinge
Modified: 2024-04-02 03:59 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-04-12 00:00:00


Attachments
dce-vs-offloading.c (238 bytes, text/x-csrc)
2017-04-12 09:59 UTC, Thomas Schwinge
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schwinge 2017-04-12 09:59:27 UTC
Created attachment 41187 [details]
dce-vs-offloading.c

With "-O1" and higher, and "-fopenacc" or "-fopenmp", different passes (see below) that optimize away dead code, remove the libgomp calls to invoke the offloaded functions.  But: the latter ones are still being referenced later on (have not yet worked on figuring out, why/where exactly), and then things explode:

With "-foffload=disable":

    /tmp/ccXNDvkg.o:(.gnu.offload_funcs+0x0): undefined reference to `main._omp_fn.0'
    /tmp/ccXNDvkg.o:(.gnu.offload_funcs+0x8): undefined reference to `main._omp_fn.1'
    collect2: error: ld returned 1 exit status

With "-foffload=nvptx-none":

    lto1: internal compiler error: Segmentation fault
    0x104a7f93 crash_signal
            [...]/gcc/toplev.c:333
    0x1037bdc8 input_offload_tables
            [...]/gcc/lto-cgraph.c:2024
    0x1037bdc8 input_offload_data(bool)
            [...]/gcc/lto-cgraph.c:1932
    0x1005ba93 read_cgraph_and_symbols
            [...]/gcc/lto/lto.c:2861
    0x1005ba93 lto_main()
            [...]/gcc/lto/lto.c:3341

On trunk as of r246724, can use "-O2 -fno-tree-ccp -fno-tree-forwprop -fno-tree-fre -fno-tree-vrp" to make this compile/link.
Comment 1 Richard Biener 2017-04-12 11:17:59 UTC
They are probably referenced in the global tables we build for offloading?  The symtab code isn't made aware of those references though.

.offload_var_table:
        .section        .gnu.offload_funcs,"aw",@progbits
        .align 8
        .type   .offload_func_table, @object
        .size   .offload_func_table, 16
.offload_func_table:
        .quad   main._omp_fn.0
        .quad   main._omp_fn.1
        .comm   __gnu_lto_v1,1,1

not sure where we emit the above.
Comment 2 Jakub Jelinek 2017-04-18 12:10:19 UTC
So, do we want to force output of everything we reference from the offload tables, like untested:
--- gcc/omp-offload.c.jj	2017-03-29 07:11:21.000000000 +0200
+++ gcc/omp-offload.c	2017-04-18 14:08:25.154650257 +0200
@@ -152,6 +152,11 @@ add_decls_addresses_to_decl_constructor
       CONSTRUCTOR_APPEND_ELT (v_ctor, NULL_TREE, addr);
       if (is_var)
 	CONSTRUCTOR_APPEND_ELT (v_ctor, NULL_TREE, size);
+
+      if (is_var)
+	varpool_node::get (it)->force_output = 1;
+      else
+	cgraph_node::get (it)->mark_force_output ();
     }
 }
 

?
Note I have no idea why the cgraph/symtab code doesn't see those table ctors and figure this out from those.
Comment 3 Andrew Pinski 2024-04-02 03:59:21 UTC
Dup.

*** This bug has been marked as a duplicate of bug 83046 ***