- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          Add #[optimize(none)]
          #128657
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
  
    Add #[optimize(none)]
  
  #128657
              
            Conversation
| r? @fee1-dead rustbot has assigned @fee1-dead. Use  | 
| While writing a codegen test, looks like there's some extra work to do - pub fn none() -> i32 {
    2 + 2
}emits overflow checks in opt-level=0 but not =1. It looks like with overflow checks disabled this is constant folded to  | 
42ac3f0    to
    94815e5      
    Compare
  
    | You may need to skip mir opts too. | 
| I've turned off MIR opts in the tests for now, but I think ideally we'd want to skip running them for  | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| Unhelpfully, LLVM doesn't seem to fully account for  | 
94815e5    to
    7154533      
    Compare
  
    | Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt | 
| } | ||
|  | ||
| fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
| if body.optimization_disabled { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is actually correct - some of these should run in debug mode. Not sure how best to decide which passes should be omitted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed incorrect. There are required passes that must be run on every MIR for soundness IIRC.
@rust-lang/wg-mir-opt: Anyone willing to provide assistance to how to disable MIR optimizations while only keeping the required passes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe check it against the opt level of the pass. If it runs on opt level 0, then don't disable it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a brief look, there are 3 or 4 passes that need keeping, including marking the mir phase.
The easiest way would be to compute the list of passes based on the opt level, or tweak the pass manager to compare default opt level with this flag.
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
7154533    to
    976f3e0      
    Compare
  
    
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
976f3e0    to
    64434e3      
    Compare
  
    | } | ||
|  | ||
| fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
| if body.optimization_disabled { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is indeed incorrect. There are required passes that must be run on every MIR for soundness IIRC.
@rust-lang/wg-mir-opt: Anyone willing to provide assistance to how to disable MIR optimizations while only keeping the required passes?
| } | ||
|  | ||
| fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | ||
| if body.optimization_disabled { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From a brief look, there are 3 or 4 passes that need keeping, including marking the mir phase.
The easiest way would be to compute the list of passes based on the opt level, or tweak the pass manager to compare default opt level with this flag.
| Pushed an approach which adds a  | 
| @bors try @rust-timer queue | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
Add `#[optimize(none)]` cc rust-lang#54882 This extends the `optimize` attribute to add `none`, which corresponds to the LLVM `OptimizeNone` attribute. Not sure if an MCP is required for this, happy to file one if so.
| ☀️ Try build successful - checks-actions | 
      
        
              This comment has been minimized.
        
        
      
    
  This comment has been minimized.
| Finished benchmarking commit (334c324): comparison URL. Overall result: no relevant changes - no action neededBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. @bors rollup=never Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -0.4%, secondary 3.6%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment. 
 CyclesResults (secondary 2.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment. 
 Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 762.637s -> 762.18s (-0.06%) | 
826dca2    to
    a084f26      
    Compare
  
    | My one concern is that #134082 added  | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpicks
a084f26    to
    e0a17a8      
    Compare
  
    e0a17a8    to
    23b10ee      
    Compare
  
    Co-authored-by: Waffle Lapkin <waffle.lapkin@gmail.com>
23b10ee    to
    7a9661d      
    Compare
  
    | @bors r=fee1-dead,WaffleLapkin | 
| ☀️ Test successful - checks-actions | 
| Finished benchmarking commit (6365178): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise. 
 Max RSS (memory usage)Results (primary -2.2%, secondary -5.2%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment. 
 CyclesResults (primary 1.2%, secondary 1.7%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment. 
 Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 772.322s -> 771.261s (-0.14%) | 
| 
 Based on what I found in #135760 (comment), it looks like the LLVM APIs won't emit  So it's expected that even with optimize(none) that the IR won't have that addition. | 
cc #54882
This extends the
optimizeattribute to addnone, which corresponds to the LLVMOptimizeNoneattribute.Not sure if an MCP is required for this, happy to file one if so.