rust/tests/mir-opt/optimize_none.rs
Martin Nordholts 52b19f7dda compiler: Don't mark SingleUseConsts MIR pass as "required for soundness"
Because:
* Something like it did not exist before PR 107404
* That it is not run our mir-opt-level 0 indicates that it is not
  required for soundness
* Its `MirPass::can_be_overridden()` is unchanged and thus returns true,
  indicating that it is not a required MIR pass.
* No test fails in PR 151426 that stops enabling by default in non-optimized builds

As can be seen from the updated test `tests/mir-opt/optimize_none.rs`,
this means that `#[optimize(none)]` functions become even less
optimized. As expected and as desired.
2026-02-17 06:22:39 +01:00

33 lines
861 B
Rust

//@ revisions: NO-OPT SPEED-OPT
//@[NO-OPT] compile-flags: -Copt-level=0
//@[SPEED-OPT] compile-flags: -Copt-level=3 -Coverflow-checks=y
#![feature(optimize_attribute)]
#[optimize(none)]
pub fn add_noopt() -> i32 {
// CHECK-LABEL: fn add_noopt(
// CHECK: AddWithOverflow(const 1_i32, const 2_i32);
// CHECK-NEXT: assert
1 + 2
}
#[optimize(none)]
pub fn const_branch() -> i32 {
// CHECK-LABEL: fn const_branch(
// CHECK: [[BOOL:_[0-9]+]] = const true;
// CHECK: switchInt(move [[BOOL]]) -> [0: [[BB_FALSE:bb[0-9]+]], otherwise: [[BB_TRUE:bb[0-9]+]]];
// CHECK-NEXT: }
// CHECK: [[BB_FALSE]]: {
// CHECK-NEXT: _0 = const 0
// CHECK-NEXT: goto
// CHECK-NEXT: }
// CHECK: [[BB_TRUE]]: {
// CHECK-NEXT: _0 = const 1
// CHECK-NEXT: goto
// CHECK-NEXT: }
if true { 1 } else { 0 }
}
fn main() {}