Open jrmuizel opened 2 years ago
Possibly related: https://github.com/rust-lang/rust/issues/46515
Cannot reproduce with nightly rust: https://godbolt.org/z/M5vvsbGnK
Cc @Nilstrieb
This always worked with -C opt-level=3
but failed (and still fails) with -C opt-level=2
.
I think LLVM inlined the function anyways and that's why it's not reproducible anymore (even with -Zbox-noalias=no
). Interestingly, if the function is made truly opaque my passing a function pointer instead, the assert is not optimized away with -Zbox-noalias=no
, but it is optimized away with -Zbox-noalias=yes
. So this indeed seems like a case where noalias
on box improves codegen.
Edit: It's obviously not inlined for codegen as the assembly shows the call, but there seems to be some smarter analysis going on.
@Nilstrieb Yes, LLVM infers that the return value is noalias in this case (noinline does not affect IPO inference passes).
I tried this code:
I expect the assert_eq! to be compiled away. However, this only happens with
-C panic=abort
.I'm using rustc 1.61.0-nightly (c84f39e6c 2022-03-20)