@@ -550,23 +550,28 @@ pub(crate) unsafe fn llvm_optimize(
550550 let unroll_loops;
551551 let vectorize_slp;
552552 let vectorize_loop;
553+ let run_enzyme;
553554
554- let run_enzyme = cfg ! ( llvm_enzyme) ;
555555 // When we build rustc with enzyme/autodiff support, we want to postpone size-increasing
556- // optimizations until after differentiation. FIXME(ZuseZ4): Before shipping on nightly,
556+ // optimizations until after differentiation. Our pipeline is thus: (opt + enzyme), (full opt).
557+ // We therefore have two calls to llvm_optimize, if autodiff is used.
558+ //
559+ // FIXME(ZuseZ4): Before shipping on nightly,
557560 // we should make this more granular, or at least check that the user has at least one autodiff
558561 // call in their code, to justify altering the compilation pipeline.
559- if skip_size_increasing_opts && run_enzyme {
562+ if skip_size_increasing_opts && cfg ! ( llvm_enzyme ) {
560563 unroll_loops = false ;
561564 vectorize_slp = false ;
562565 vectorize_loop = false ;
566+ run_enzyme = true ;
563567 } else {
564568 unroll_loops =
565569 opt_level != config:: OptLevel :: Size && opt_level != config:: OptLevel :: SizeMin ;
566570 vectorize_slp = config. vectorize_slp ;
567571 vectorize_loop = config. vectorize_loop ;
572+ run_enzyme = false ;
568573 }
569- trace ! ( ?unroll_loops, ?vectorize_slp, ?vectorize_loop) ;
574+ trace ! ( ?unroll_loops, ?vectorize_slp, ?vectorize_loop, ?run_enzyme ) ;
570575 let using_thin_buffers = opt_stage == llvm:: OptStage :: PreLinkThinLTO || config. bitcode_needed ( ) ;
571576 let pgo_gen_path = get_pgo_gen_path ( config) ;
572577 let pgo_use_path = get_pgo_use_path ( config) ;
0 commit comments