ThinLTO at -O0: flang does not mark -O0 functions noinline Only clang marks every function noinline at -O0, which the ThinLTO importer skips. flang's -O0 objects import fine, so the Fortran test needs no -force-import-all, and the README says the limitation is clang's. Assisted-by: Claude Code (Opus 5.5)
diff --git a/enzyme/Fortran/README.md b/enzyme/Fortran/README.md index 8b5afd4..c543659 100644 --- a/enzyme/Fortran/README.md +++ b/enzyme/Fortran/README.md
@@ -43,7 +43,7 @@ The compile step asks ThinLTO to import the function passed to `__enzyme_autodiff` and the functions it calls. ThinLTO still applies its size limit to functions further down the call graph, and never imports functions marked `noinline` (which includes -everything compiled at `-O0`). When such a function is missing, Enzyme reports that +everything clang compiles at `-O0`; flang does not mark them). When such a function is missing, Enzyme reports that it has no derivative for it; compile it in the same file as the call, raise the limit with `-Wl,-mllvm,-import-instr-limit=<N>`, or use full `-flto`.
diff --git a/enzyme/test/Fortran/ReverseMode/config_file_lto.f90 b/enzyme/test/Fortran/ReverseMode/config_file_lto.f90 index 4de620a..022a843 100644 --- a/enzyme/test/Fortran/ReverseMode/config_file_lto.f90 +++ b/enzyme/test/Fortran/ReverseMode/config_file_lto.f90
@@ -12,11 +12,10 @@ ! RUN: %fc -cpp -DCALLEE_ONLY -flto=thin -O2 -c %flangEnzymeConfig %s -o %t.callee.thin.o ! RUN: %fc -cpp -DCALLER_ONLY -flto=thin -O2 -c %flangEnzymeConfig %s -o %t.caller.thin.o ! RUN: %fc -flto=thin -O2 %flangEnzymeConfig %t.caller.thin.o %t.callee.thin.o -o %t2 && %t2 | FileCheck %s -! At -O0 the pre-link run defers as well (LLVM 24 and later). Every function -! compiled at -O0 is noinline, which ThinLTO only imports with -force-import-all. +! At -O0 the pre-link run defers as well (LLVM 24 and later). ! RUN: if [ %llvmver -ge 24 ]; then %fc -cpp -DCALLEE_ONLY -flto=thin -O0 -c %flangEnzymeConfig %s -o %t.callee.thin0.o; fi ! RUN: if [ %llvmver -ge 24 ]; then %fc -cpp -DCALLER_ONLY -flto=thin -O0 -c %flangEnzymeConfig %s -o %t.caller.thin0.o; fi -! RUN: if [ %llvmver -ge 24 ]; then %fc -flto=thin -O2 %flangEnzymeConfig -Wl,-mllvm,-force-import-all %t.caller.thin0.o %t.callee.thin0.o -o %t3 && %t3 | FileCheck %s; fi +! RUN: if [ %llvmver -ge 24 ]; then %fc -flto=thin -O2 %flangEnzymeConfig %t.caller.thin0.o %t.callee.thin0.o -o %t3 && %t3 | FileCheck %s; fi #ifndef CALLER_ONLY real function cube(x)