@@ -564,19 +564,16 @@ pub(crate) unsafe fn llvm_optimize(
564564 // FIXME(ZuseZ4): In a future update we could figure out how to only optimize individual functions getting
565565 // differentiated.
566566
567+ let consider_ad = cfg ! ( llvm_enzyme) && config. autodiff . contains ( & config:: AutoDiff :: Enable ) ;
568+ let run_enzyme = autodiff_stage == AutodiffStage :: DuringAD ;
567569 let unroll_loops;
568570 let vectorize_slp;
569571 let vectorize_loop;
570- let run_enzyme = cfg ! ( llvm_enzyme) && autodiff_stage == AutodiffStage :: DuringAD ;
571572
572573 // When we build rustc with enzyme/autodiff support, we want to postpone size-increasing
573574 // optimizations until after differentiation. Our pipeline is thus: (opt + enzyme), (full opt).
574575 // We therefore have two calls to llvm_optimize, if autodiff is used.
575- //
576- // FIXME(ZuseZ4): Before shipping on nightly,
577- // we should make this more granular, or at least check that the user has at least one autodiff
578- // call in their code, to justify altering the compilation pipeline.
579- if cfg ! ( llvm_enzyme) && autodiff_stage != AutodiffStage :: PostAD {
576+ if consider_ad && autodiff_stage != AutodiffStage :: PostAD {
580577 unroll_loops = false ;
581578 vectorize_slp = false ;
582579 vectorize_loop = false ;
@@ -706,10 +703,8 @@ pub(crate) unsafe fn optimize(
706703
707704 // If we know that we will later run AD, then we disable vectorization and loop unrolling.
708705 // Otherwise we pretend AD is already done and run the normal opt pipeline (=PostAD).
709- // FIXME(ZuseZ4): Make this more granular, only set PreAD if we actually have autodiff
710- // usages, not just if we build rustc with autodiff support.
711- let autodiff_stage =
712- if cfg ! ( llvm_enzyme) { AutodiffStage :: PreAD } else { AutodiffStage :: PostAD } ;
706+ let consider_ad = cfg ! ( llvm_enzyme) && config. autodiff . contains ( & config:: AutoDiff :: Enable ) ;
707+ let autodiff_stage = if consider_ad { AutodiffStage :: PreAD } else { AutodiffStage :: PostAD } ;
713708 return unsafe {
714709 llvm_optimize ( cgcx, dcx, module, config, opt_level, opt_stage, autodiff_stage)
715710 } ;
0 commit comments