Skip to content

Miscompilation(s) due to MIR inlining #105344

Closed
@saethlin

Description

@saethlin

I just figured I'd try running some tests and benchmarks with -Zmir-opt-level=3 and it is not going well. I realize I'm painting a rather grim picture here, but to be clear some code does in fact seem to compile correctly.

On commit e1d819583f0bf13b016b119c1c2c43e6d3979450 I ran:

$ RUSTFLAGS_NOT_BOOTSTRAP=-Zmir-opt-level=3 ./x.py test --stage 1 library/core

And I see 6 test failures in core_simd all like this:

---- src/../../portable-simd/crates/core_simd/src/swizzle.rs - core_simd::swizzle::Simd<T,LANES>::deinterleave (line 339) stdout ----
Invalid bitcast
  %29 = bitcast <4 x i32> %24 to [4 x i32]
Invalid bitcast
  %38 = bitcast <4 x i32> %28 to [4 x i32]
in function _ZN8rust_out4main75_doctest_main_src_______portable_simd_crates_core_simd_src_swizzle_rs_339_017h788d0453a929bc62E
LLVM ERROR: Broken function found, compilation aborted!
Couldn't compile the test.

I also tried running the tinyvec benchmark suite, commit cd8b94964ffd857119c2095ad3d232a4e16a2ad0 of https://github.com/lokathor/tinyvec

$ RUSTFLAGS="-Zmir-opt-level=3" cargo +nightly bench --features=alloc
   Compiling tinyvec v1.6.0 (/home/ben/tinyvec)
    Finished bench [optimized + debuginfo] target(s) in 2.22s
     Running unittests src/lib.rs (target/release/deps/tinyvec-031d885bae3cce6f)

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

     Running benches/macros.rs (target/release/deps/macros-c4a72fc6cba5f49d)
WARNING: HTML report generation will become a non-default optional feature in Criterion.rs 0.4.0.
This feature is being moved to cargo-criterion (https://github.com/bheisler/cargo-criterion) and will be optional in a future version of Criterion.rs. To silence this warning, either switch to cargo-criterion or enable the 'html_reports' feature in your Cargo.toml.

Gnuplot not found, using plotters backend
thread 'main' panicked at 'Unable to parse report_link template.: ParseError { msg: "Expected a closing '}' but found end-of-line instead.", line: 1, column: 14 }', /home/ben/.cargo/registry/src/github.com-1ecc6299db9ec823/criterion-0.3.6/src/html/mod.rs:280:14
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: bench failed, to rerun pass `--bench macros`

(this is not supposed to panic)


I also tried running the test suite for https://github.com/rust-lang/regex on commit ac2d0e1b33b4674ad9b26266ef4b828d7200ec0f

$ RUSTFLAGS="-Zmir-opt-level=3" cargo +nightly test --release
   Compiling memchr v2.5.0
   Compiling aho-corasick v0.7.20
   Compiling regex v1.7.0 (/home/ben/regex)
    Finished release [optimized + debuginfo] target(s) in 20.59s
     Running unittests src/lib.rs (target/release/deps/regex-0d0deeb6b9675203)

running 36 tests
error: test failed, to rerun pass `--lib`

Caused by:
  process didn't exit successfully: `/home/ben/regex/target/release/deps/regex-0d0deeb6b9675203` (signal: 4, SIGILL: illegal instruction)
rustc 1.67.0-nightly (53e4b9dd7 2022-12-04)
binary: rustc
commit-hash: 53e4b9dd74c29cc9308b8d0f10facac70bb101a7
commit-date: 2022-12-04
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions