Skip to content

tests: -Copt-level=3 instead of -O in codegen tests #136761

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/codegen/abi-repr-ext.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

//@ revisions:x86_64 i686 aarch64-apple aarch64-windows aarch64-linux arm riscv

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/align-offset.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/alloc-optimisation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
#![crate_type = "lib"]

#[no_mangle]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/array-clone.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/array-codegen.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O -C no-prepopulate-passes
//@ compile-flags: -Copt-level=3 -C no-prepopulate-passes

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/array-equality.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O -Z merge-functions=disabled
//@ compile-flags: -Copt-level=3 -Z merge-functions=disabled
//@ only-x86_64
#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/array-optimized.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/array-repeat.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]
#![feature(array_repeat)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/asm/goto.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ only-x86_64

#![crate_type = "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/asm/may_unwind.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ only-x86_64

#![crate_type = "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/asm/maybe-uninit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ only-x86_64

#![crate_type = "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/asm/multiple-options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ only-x86_64

#![crate_type = "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/asm/options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ only-x86_64

#![crate_type = "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/asm/x86-clobber_abi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ only-x86_64

#![crate_type = "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/asm/x86-clobbers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ only-x86_64

#![crate_type = "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/atomic-operations.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Code generation of atomic operations.
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
#![crate_type = "lib"]

use std::sync::atomic::AtomicI32;
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/atomicptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// ensures that we do not have such a round-trip for AtomicPtr::swap, because LLVM supports pointer
// arguments to `atomicrmw xchg`.

//@ compile-flags: -O -Cno-prepopulate-passes
//@ compile-flags: -Copt-level=3 -Cno-prepopulate-passes
#![crate_type = "lib"]
#![feature(strict_provenance_atomic_ptr)]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/avr/avr-func-addrspace.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O --target=avr-unknown-gnu-atmega328 --crate-type=rlib -C panic=abort
//@ compile-flags: -Copt-level=3 --target=avr-unknown-gnu-atmega328 --crate-type=rlib -C panic=abort
//@ needs-llvm-components: avr

// This test validates that function pointers can be stored in global variables
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/binary-heap-peek-mut-pop-no-panic.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ ignore-std-debug-assertions
#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/binary-search-index-no-bound-check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
#![crate_type = "lib"]

// Make sure no bounds checks are emitted when slicing or indexing
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/box-uninit-bytes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
#![crate_type = "lib"]

use std::mem::MaybeUninit;
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/call-metadata.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Checks that range metadata gets emitted on calls to functions returning a
// scalar value.

//@ compile-flags: -O -C no-prepopulate-passes
//@ compile-flags: -Copt-level=3 -C no-prepopulate-passes
//@ max-llvm-major-version: 18

#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/cast-optimized.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O -Z merge-functions=disabled
//@ compile-flags: -Copt-level=3 -Z merge-functions=disabled
#![crate_type = "lib"]

// This tests that LLVM can optimize based on the niches in the source or
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/cast-target-abi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ignore-tidy-linelength
//@ revisions:aarch64 loongarch64 powerpc64 sparc64 x86_64
//@ min-llvm-version: 19
//@ compile-flags: -O -Cno-prepopulate-passes -Zlint-llvm-ir -Cllvm-args=-lint-abort-on-error
//@ compile-flags: -Copt-level=3 -Cno-prepopulate-passes -Zlint-llvm-ir -Cllvm-args=-lint-abort-on-error

//@[aarch64] compile-flags: --target aarch64-unknown-linux-gnu
//@[aarch64] needs-llvm-components: arm
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/catch-unwind.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

// On x86 the closure is inlined in foo() producing something like
// define i32 @foo() [...] {
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/char-ascii-branchless.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Checks that these functions are branchless.
//
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/checked_ilog.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/checked_math.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O -Z merge-functions=disabled
//@ compile-flags: -Copt-level=3 -Z merge-functions=disabled

#![crate_type = "lib"]
#![feature(unchecked_shifts)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/clone_as_copy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ revisions: DEBUGINFO NODEBUGINFO
//@ compile-flags: -Zunsound-mir-opts
// FIXME: see <https://github.com/rust-lang/rust/issues/132353>
//@ compile-flags: -O -Cno-prepopulate-passes
//@ compile-flags: -Copt-level=3 -Cno-prepopulate-passes
//@ [DEBUGINFO] compile-flags: -Cdebuginfo=full

// From https://github.com/rust-lang/rust/issues/128081.
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/common_prim_int_ptr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]
#![feature(core_intrinsics)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/const-array.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/cross-crate-inlining/always-inline.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ aux-build:always.rs

#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/cross-crate-inlining/auxiliary/always.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O -Zcross-crate-inline-threshold=always
//@ compile-flags: -Copt-level=3 -Zcross-crate-inline-threshold=always

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/cross-crate-inlining/auxiliary/leaf.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/cross-crate-inlining/auxiliary/never.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O -Zcross-crate-inline-threshold=never
//@ compile-flags: -Copt-level=3 -Zcross-crate-inline-threshold=never

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/cross-crate-inlining/leaf-inlining.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O -Zcross-crate-inline-threshold=yes
//@ compile-flags: -Copt-level=3 -Zcross-crate-inline-threshold=yes
//@ aux-build:leaf.rs

#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/cross-crate-inlining/never-inline.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ aux-build:never.rs

#![crate_type = "lib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/dealloc-no-unwind.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/debug-fndef-size.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Verify that `i32::cmp` FnDef type is declared with a size of 0 and an
// alignment of 8 bits (1 byte) in LLVM debuginfo.

//@ compile-flags: -O -g -Cno-prepopulate-passes
//@ compile-flags: -Copt-level=3 -g -Cno-prepopulate-passes
//@ ignore-msvc the types are mangled differently

use std::cmp::Ordering;
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/debuginfo-constant-locals.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -g -O
//@ compile-flags: -g -Copt-level=3

// Check that simple constant values are preserved in debuginfo across both MIR opts and LLVM opts

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/debuginfo-inline-callsite-location.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -g -O -C panic=abort
//@ compile-flags: -g -Copt-level=3 -C panic=abort

// Check that each inline call site for the same function uses the same "sub-program" so that LLVM
// can correctly merge the debug info if it merges the inlined code (e.g., for merging of tail
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/deduced-param-attrs.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]
#![allow(incomplete_features)]
Expand Down
38 changes: 38 additions & 0 deletions tests/codegen/dont-shuffle-bswaps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//@ revisions: OPT2 OPT3
//@[OPT2] compile-flags: -Copt-level=2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit odd to not have OPT2 filecheck comments, but I guess the idea here is to check for the lack of a shufflevector at level 2, and check that we get the slick bswap codegen at level 3?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, we're checking for "no shufflevector plz" at both levels and then for the bswap at OPT3

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for OPT3 the only way it could have a shufflevector instruction is if it smuggled itself in right between start: and the actual checked lines, but, idk, might as well?

//@[OPT3] compile-flags: -C opt-level=3
// some targets don't do the opt we are looking for
//@[OPT3] only-64bit
//@ min-llvm-version: 18.1.3

#![crate_type = "lib"]
#![no_std]

// The code is from https://github.com/rust-lang/rust/issues/122805.
// Ensure we do not generate the shufflevector instruction
// to avoid complicating the code.
// CHECK-LABEL: define{{.*}}void @convert(
// CHECK-NOT: shufflevector
// On higher opt levels, this should just be a bswap:
// OPT3: load <8 x i16>
// OPT3-NEXT: call <8 x i16> @llvm.bswap
// OPT3-NEXT: store <8 x i16>
// OPT3-NEXT: ret void
Comment on lines +16 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This load is missing (or different) on test-various at -O3

#[no_mangle]
pub fn convert(value: [u16; 8]) -> [u8; 16] {
#[cfg(target_endian = "little")]
let bswap = u16::to_be;
#[cfg(target_endian = "big")]
let bswap = u16::to_le;
let addr16 = [
bswap(value[0]),
bswap(value[1]),
bswap(value[2]),
bswap(value[3]),
bswap(value[4]),
bswap(value[5]),
bswap(value[6]),
bswap(value[7]),
];
unsafe { core::mem::transmute::<_, [u8; 16]>(addr16) }
}
2 changes: 1 addition & 1 deletion tests/codegen/drop-in-place-noalias.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O -C no-prepopulate-passes
//@ compile-flags: -Copt-level=3 -C no-prepopulate-passes

// Tests that the compiler can apply `noalias` and other &mut attributes to `drop_in_place`.
// Note that non-Unpin types should not get `noalias`, matching &mut behavior.
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/dst-vtable-align-nonzero.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O -Z merge-functions=disabled
//@ compile-flags: -Copt-level=3 -Z merge-functions=disabled

#![crate_type = "lib"]
#![feature(core_intrinsics)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/dst-vtable-size-range.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O -Z merge-functions=disabled
//@ compile-flags: -Copt-level=3 -Z merge-functions=disabled

#![crate_type = "lib"]
#![feature(core_intrinsics)]
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/emscripten-catch-unwind-js-eh.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O --target wasm32-unknown-emscripten
//@ compile-flags: -Copt-level=3 --target wasm32-unknown-emscripten
//@ needs-llvm-components: webassembly

// Emscripten has its own unique implementation of catch_unwind (in `codegen_emcc_try`),
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/emscripten-catch-unwind-wasm-eh.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O --target wasm32-unknown-emscripten -Z emscripten-wasm-eh
//@ compile-flags: -Copt-level=3 --target wasm32-unknown-emscripten -Z emscripten-wasm-eh
//@ needs-llvm-components: webassembly

// Emscripten catch_unwind using wasm exceptions
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/enum/enum-bounds-check-derived-idx.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This test checks an optimization that is not guaranteed to work. This test case should not block
// a future LLVM update.
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/enum/enum-bounds-check-issue-13926.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This test checks an optimization that is not guaranteed to work. This test case should not block
// a future LLVM update.
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/enum/enum-bounds-check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/enum/enum-early-otherwise-branch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/enum/unreachable_enum_default_branch.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3

#![crate_type = "lib"]

Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/error-provide.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Codegen test for #126242

//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
#![crate_type = "lib"]
#![feature(error_generic_member_access)]
use std::error::Request;
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/external-no-mangle-statics.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ revisions: lib staticlib
//@ ignore-emscripten default visibility is hidden
//@ compile-flags: -O
//@ compile-flags: -Copt-level=3
//@ [lib] compile-flags: --crate-type lib
//@ [staticlib] compile-flags: --crate-type staticlib
// `#[no_mangle]`d static variables always have external linkage, i.e., no `internal` in their
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/f128-wasm32-callconv.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Verify that Rust implements the expected calling convention for `f128`

//@ add-core-stubs
//@ compile-flags: -O --target wasm32-wasip1
//@ compile-flags: -Copt-level=3 --target wasm32-wasip1
//@ needs-llvm-components: webassembly

#![crate_type = "lib"]
Expand Down
Loading
Loading