[clang] [flang] [flang][DOCONCURRENT] Device versions of pure procedures for device mapping (PR #236886)

Alessandro Fanfarillo via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 23 07:56:01 PST 2026


afanfa wrote:

@mjklemm , here is an analysis of how marking many PURE procedures declare target affects compile time and LTO link time. It uses two synthetic benchmarks:

- a whole-program A/B test, with and without the flag, on a multi-file program with no OpenMP directives, whose do concurrent loops call pure procedures from 10 different files, and where most pure procedures are never called on the device;
- a sweep with up to 4000 pure procedures in a single file, which isolates the cost per procedure and shows where it goes.

 for a program of 128 files with 100 pure procedures each (12800 in total). Each file has a do concurrent loop that calls 10 pure procedures, 1280 in total. No source file has any OpenMP directive. Four builds are compared:

- A-local (current behavior, no -fdo-concurrent-device-pure-procedures): each loop calls 10 procedures from its own file, which is the only layout that builds today without directives.

- B-local: the same sources, with -fdo-concurrent-device-pure-procedures.

- B-cross (with the flag): each loop calls one procedure from each of 10 different files. The called procedures, their bodies and the kernels are the same as in the local layout.

Here are the findings summarized:

- Unused pure procedures never reach device LTO. With the flag, the objects carry device bitcode for all 12800 procedures, but only the called ones enter the device LTO optimizer. In the local layout, that is 1280 procedures without -O and 0 at -O3, where the compile step has already inlined them; it is the same for A and B. In the cross layout, it is exactly the 1280 called procedures in every configuration. The rest are hidden and unreferenced, so they are dropped while the LTO module is built.

- Device link, same sources (B-local vs A-local): no change. It differs by at most 1.9% in all 18 configurations.

- Device link with cross-file calls (B-cross vs A-local): no change without -O (within 2.0%). **At -O3, it is 10.77 s (+24%) longer with 128 files**. The cause is that the callees live in other files, so the compile step can no longer inline them, and device LTO does it instead: 1280 procedures enter the LTO optimizer instead of 0. LTO optimization takes 10.34 s longer; codegen +0.09 s. This cost depends on the 1280 called procedures, not on the 11520 unused ones.

- Host LTO link: at most 0.85 s more, outside the device link. At -O3 with 128 files, B-local links 1.22 s (1.6%) slower than A-local with -flto=full and 0.65 s (1.4%) slower with -flto=thin. The host linker step itself takes at most 0.44 s longer in either layout. The extra time is mostly spent reading the larger objects (61 MB instead of 35 MB).

- Compile at -O3: +14% CPU time (B-local vs A-local) with 128 files, +15% with -flto=full and +21% with -flto=thin. All of it is in the device job, which now optimizes the 11520 procedures that A doesn't compile for the device, at 12.8 to 13.3 ms per extra procedure.

+24% for this case when LTO is on seems reasonable to me. What do you think?

https://github.com/llvm/llvm-project/pull/236886


More information about the cfe-commits mailing list