rust/compiler
Matthias Krüger c3f811f02f
Rollup merge of #139700 - EnzymeAD:autodiff-flags, r=oli-obk
Autodiff flags

Interestingly, it seems that some other projects have conflicts with exactly the same LLVM optimization passes as autodiff.
At least `LLVMRustOptimize` has exactly the flags that we need to disable problematic opt passes.

This PR enables us to compile code where users differentiate two identical functions in the same module. This has been especially common in test cases, but it's not impossible to encounter in the wild.

It also enables two new flags for testing/debugging. I consider writing an MCP to upgrade PrintPasses to be a standalone -Z flag, since it is *not* the same as `-Z print-llvm-passes`, which IMHO gives less useful output. A discussion can be found here: [#t-compiler/llvm > Print llvm passes. @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/187780-t-compiler.2Fllvm/topic/Print.20llvm.20passes.2E/near/511533038)

Finally, it improves `PrintModBefore` and `PrintModAfter`. They used to work reliable, but now we just schedule enzyme as part of an existing ModulePassManager (MPM). Since Enzyme is last in the MPM scheduling, PrintModBefore became very inaccurate. It used to print the input module, which we gave to the Enzyme and was great to create llvm-ir reproducer. However, lately the MPM would run the whole `default<O3>` pipeline, which heavily modifies the llvm module, before we pass it to Enzyme. That made it impossible to use the flag to create llvm-ir reproducers for Enzyme bugs. We now schedule a PrintModule pass just before Enzyme, solving this problem.

Based on the PrintPass output, it also _seems_ like changing `registerEnzymeAndPassPipeline(PB, true);` to `registerEnzymeAndPassPipeline(PB, false);` has no effect. In theory, the bool should tell Enzyme to schedule some helpful passes in the PassBuilder. However, since it doesn't do anything and I'm not 100% sure anymore on whether we really need it, I'll just disable it for now and postpone investigations.

r? ``@oli-obk``

closes #139471

Tracking:

- https://github.com/rust-lang/rust/issues/124509
2025-04-24 17:19:44 +02:00
..
rustc
rustc_abi Initial UnsafePinned/UnsafeUnpin impl [Part 1: Libs] 2025-04-13 01:11:04 -04:00
rustc_arena
rustc_ast Auto merge of #139897 - nnethercote:rm-OpenDelim-CloseDelim, r=petrochenkov 2025-04-22 01:15:06 +00:00
rustc_ast_ir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_ast_lowering Extend HIR to track the source and syntax of a lifetime 2025-04-23 16:37:39 -04:00
rustc_ast_passes Rollup merge of #139615 - nnethercote:rm-name_or_empty, r=jdonszelmann 2025-04-18 05:16:29 +02:00
rustc_ast_pretty Rollup merge of #140232 - nnethercote:rm-unnecessary-clones, r=SparrowLii 2025-04-24 08:13:01 +02:00
rustc_attr_data_structures Remove #[rustc_macro_edition_2021]. 2025-04-20 11:15:46 +02:00
rustc_attr_parsing Auto merge of #139897 - nnethercote:rm-OpenDelim-CloseDelim, r=petrochenkov 2025-04-22 01:15:06 +00:00
rustc_baked_icu_data
rustc_borrowck Rollup merge of #140160 - oli-obk:lang-items, r=jieyouxu 2025-04-23 00:43:07 +00:00
rustc_builtin_macros Rollup merge of #140104 - Shourya742:2025-04-21-auto-diff-fails-on-impl-block, r=ZuseZ4 2025-04-22 15:24:07 +00:00
rustc_codegen_cranelift Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc 2025-04-24 13:14:36 +07:00
rustc_codegen_gcc Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc 2025-04-24 13:14:36 +07:00
rustc_codegen_llvm Rollup merge of #139700 - EnzymeAD:autodiff-flags, r=oli-obk 2025-04-24 17:19:44 +02:00
rustc_codegen_ssa Rollup merge of #137953 - RalfJung:simd-intrinsic-masks, r=WaffleLapkin 2025-04-20 13:02:48 +00:00
rustc_const_eval add comment for "Other" case 2025-04-22 11:40:48 +02:00
rustc_data_structures Switch to diagnostic::on_unimplemented 2025-04-14 01:38:18 +02:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl Auto merge of #124141 - nnethercote:rm-Nonterminal-and-TokenKind-Interpolated, r=petrochenkov 2025-04-14 03:56:55 +00:00
rustc_error_codes stabilize naked_functions 2025-04-20 11:18:38 +02:00
rustc_error_messages update cfgs 2025-04-09 12:29:59 +01:00
rustc_errors Move eager translation to a method on Diag 2025-04-16 21:38:59 -04:00
rustc_expand Auto merge of #139897 - nnethercote:rm-OpenDelim-CloseDelim, r=petrochenkov 2025-04-22 01:15:06 +00:00
rustc_feature Rollup merge of #134213 - folkertdev:stabilize-naked-functions, r=tgross35,Amanieu,traviscross 2025-04-21 18:53:15 +00:00
rustc_fluent_macro Replace proc_macro::SourceFile by Span::{file, local_file}. 2025-04-11 15:07:08 +02:00
rustc_fs_util
rustc_graphviz
rustc_hashes
rustc_hir Extend HIR to track the source and syntax of a lifetime 2025-04-23 16:37:39 -04:00
rustc_hir_analysis Use is_lang_item and as_lang_item instead of handrolling their logic 2025-04-22 11:02:37 +00:00
rustc_hir_pretty Fix HIR pretty-printing of fns with just a variadic arg. 2025-04-15 10:41:10 +10:00
rustc_hir_typeck Rollup merge of #140028 - dianne:lit-deref-pats-p1, r=oli-obk 2025-04-24 08:13:00 +02:00
rustc_incremental Replace infallible name_or_empty methods with fallible name methods. 2025-04-17 09:50:52 +10:00
rustc_index Add copy_within to IndexSlice 2025-04-15 10:44:28 -04:00
rustc_index_macros In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
rustc_infer More 2025-04-23 15:09:25 +00:00
rustc_interface Rollup merge of #139042 - compiler-errors:do-not-optimize-switchint, r=saethlin 2025-04-19 19:30:46 +00:00
rustc_lexer Replace rustc_lexer/unescape with rustc-literal-escaper crate 2025-04-04 14:44:45 +02:00
rustc_lint Rollup merge of #138282 - beetrees:repr128-not-ffi-safe, r=oli-obk 2025-04-24 17:19:43 +02:00
rustc_lint_defs Suggest {to,from}_ne_bytes for transmutations between arrays and integers, etc 2025-04-24 13:14:36 +07:00
rustc_llvm fix LooseTypes flag and PrintMod behaviour, add debug helper 2025-04-12 01:36:44 -04:00
rustc_log Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_macros Remove synstructure::Structure::underscore_const calls. 2025-04-23 11:14:27 +10:00
rustc_metadata Rollup merge of #139834 - ChrisDenton:spf, r=WaffleLapkin 2025-04-19 15:09:35 +00:00
rustc_middle Auto merge of #138845 - compiler-errors:stall-generators, r=lcnr 2025-04-23 21:35:15 +00:00
rustc_mir_build Rollup merge of #140028 - dianne:lit-deref-pats-p1, r=oli-obk 2025-04-24 08:13:00 +02:00
rustc_mir_dataflow Remove unnecessary lifetime on ResultsVisitor. 2025-04-22 10:08:05 +10:00
rustc_mir_transform Rollup merge of #136083 - bend-n:⃤⃤, r=lcnr 2025-04-24 17:19:42 +02:00
rustc_monomorphize Rollup merge of #139809 - alexcrichton:wasm-simd-safe, r=RalfJung 2025-04-24 08:12:58 +02:00
rustc_next_trait_solver Rollup merge of #140214 - compiler-errors:remove-hack, r=lcnr 2025-04-24 11:40:46 +02:00
rustc_parse Rollup merge of #140228 - fmease:revert-overzealous-colon-recovery, r=jieyouxu 2025-04-24 11:40:47 +02:00
rustc_parse_format Update rustc-literal-escaper version to 0.0.2 2025-04-04 22:26:10 +02:00
rustc_passes stabilize naked_functions 2025-04-20 11:18:38 +02:00
rustc_pattern_analysis Move eager translation to a method on Diag 2025-04-16 21:38:59 -04:00
rustc_privacy Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_query_impl Auto merge of #124141 - nnethercote:rm-Nonterminal-and-TokenKind-Interpolated, r=petrochenkov 2025-04-14 03:56:55 +00:00
rustc_query_system Rollup merge of #139236 - Zoxc:anon-counter, r=davidtwco 2025-04-17 00:14:24 +02:00
rustc_resolve Remove #[rustc_macro_edition_2021]. 2025-04-20 11:15:46 +02:00
rustc_sanitizers Rollup merge of #139669 - nnethercote:overhaul-AssocItem, r=oli-obk 2025-04-15 15:47:27 +10:00
rustc_serialize Bump FileEncoder buffer size to 64 kB 2025-04-10 18:52:03 +02:00
rustc_session Rollup merge of #139700 - EnzymeAD:autodiff-flags, r=oli-obk 2025-04-24 17:19:44 +02:00
rustc_smir Rollup merge of #140232 - nnethercote:rm-unnecessary-clones, r=SparrowLii 2025-04-24 08:13:01 +02:00
rustc_span Remove #[rustc_macro_edition_2021]. 2025-04-20 11:15:46 +02:00
rustc_symbol_mangling Rollup merge of #139848 - nnethercote:kw-Empty-5, r=compiler-errors 2025-04-15 21:16:05 +02:00
rustc_target Rollup merge of #139261 - RalfJung:msvc-align-mitigation, r=oli-obk 2025-04-24 11:40:35 +02:00
rustc_trait_selection Auto merge of #140245 - matthiaskrgr:rollup-e0fwsfv, r=matthiaskrgr 2025-04-24 12:06:16 +00:00
rustc_traits re-use sized fast path 2025-04-09 10:42:26 +00:00
rustc_transmute transmutability: Mark edges by ranges, not values 2025-04-23 11:45:00 -07:00
rustc_ty_utils Rollup merge of #139261 - RalfJung:msvc-align-mitigation, r=oli-obk 2025-04-24 11:40:35 +02:00
rustc_type_ir More 2025-04-23 15:09:25 +00:00
rustc_type_ir_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00
stable_mir let rustc_smir host stable_mir for refactoring 2025-04-05 18:23:07 +08:00