Skip to content

Commit

Permalink
Fix LTO Detection in LLVM Intrinsic Build (#36)
Browse files Browse the repository at this point in the history
Fixes #33 

This PR fixes LTO detection in the LLVM intrinsic build script. It turns
out that around Rust 1.55, `cargo` stopped propagating `RUSTFLAGS`
environment variable to the build script invocation (and even actively
removing it). It is replaced with `CARGO_ENCODED_RUSTFLAGS` which is
meant to more accurately set the actual `rustc` flags that are being
used.

Turning this on yields an immediate improvement in benchmarks:

```
U256::add               time:   [15.726 ns 15.764 ns 15.808 ns]
                        change: [-34.507% -34.304% -34.099%] (p = 0.00 < 0.05)
                        Performance has improved.
```
  • Loading branch information
nlordell committed Nov 16, 2023
1 parent 1cd9388 commit b66678b
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions intrinsics/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ fn main() -> Result<(), Box<dyn Error>> {
let mut build = Build::new();
build.compiler(&clang).file(intrinsics_ir_path).opt_level(3);

let linker_plugin_lto =
matches!(env::var("RUSTFLAGS"), Ok(flags) if flags.contains("-Clinker-plugin-lto"));
let linker_plugin_lto = matches!(env::var("CARGO_ENCODED_RUSTFLAGS"), Ok(flags) if flags.contains("-Clinker-plugin-lto"));
if linker_plugin_lto {
build.flag("-flto=thin");
}
Expand Down

0 comments on commit b66678b

Please sign in to comment.