Repository navigation
Run the FatLtoCleanup pass to lower llvm.type.checked.load - #165572
Conversation
f68d0fb to
a4ec404
Compare
There was a problem hiding this comment.
r? nikic (or someone else familiar with the LLVM side)
cc @bjorn3 (because LTO)
| ModuleAnalysisManager MAM; | ||
| FatLtoCleanup().run(*unwrap(M), MAM); |
There was a problem hiding this comment.
Is some fancier pass manager thing needed/desirable here?
There was a problem hiding this comment.
The pass doesn't actually use any analyses, so this is fine.
| // Rustc emits checked loads when using `-Zvirtual-function-elimination`. | ||
| // This flag implies fat LTO, but for non-LTO compilations (e.g. building | ||
| // an rlib, or when passing --emit=asm) the checked loads are not supported. | ||
| unsafe { llvm::LLVMRustRunFatLtoCleanup(llmod) }; |
There was a problem hiding this comment.
This is the only location that seems to work. Putting it earlier removes the checked loads from the bitcode (or from the IR, making .bc and .ll inconsistent) defeating the purpose, doing it later makes non-LTO compilations hit the error this PR is supposed to fix.
There was a problem hiding this comment.
Can this be done at the end of lto::run_pass_manager? That would make sure it doesn't get run before emitting pre-LTO bitcode, but does get run before emitting post-LTO bitcode.
There was a problem hiding this comment.
I think that doesn't actually run for non-LTO compilations, like creating an rlib here, going off of the test I added here failing when moving the logic there, and this function:
rust/compiler/rustc_codegen_ssa/src/back/write.rs
Lines 805 to 810 in fd4400d
I think we want the rlib case to work?
There was a problem hiding this comment.
Right, missed that this PR is about non-LTO builds.
There was a problem hiding this comment.
It's confusing because we only actually need to run this pass if -Clto=fat is passed, but then internally that doesn't mean that the fat LTO logic actually runs.
| // This flag implies fat LTO, but for non-LTO compilations (e.g. building | ||
| // an rlib, or when passing --emit=asm) the checked loads are not supported, | ||
| // and they must be removed. | ||
| extern "C" void LLVMRustRunFatLtoCleanup(LLVMModuleRef M) { |
There was a problem hiding this comment.
I previously gated this on whether the Virtual Function Elim module flag was set, but the FatLtoCleanup pass has a very cheap check for whether it should do any work at all (here), so I don't think that is necessary.
FatLtoCleanup pass when using virtual function eliminationFatLtoCleanup pass to lower llvm.type.checked.load
a4ec404 to
4fea718
Compare
This comment has been minimized.
This comment has been minimized.
|
@bors r+ I feel like it would make more sense for LLVM to just do this itself in the backend, rather than requiring a separate pass... |
|
❌ Cannot approve commit 4fea718, because CI currently fails on this PR. Use |
This LLVM pass lowers `llvm.type.checked.load` into a standard load when doing a non-LTO compilation.
4fea718 to
4484ce5
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
Looks like CI just got stuck before, but it's passing now @bors r=nikic |
Run the `FatLtoCleanup` pass to lower `llvm.type.checked.load` tracking issue: rust-lang#68262 fixes rust-lang#124093 Run the `FatLtoCleanup` pass which lowers `llvm.type.checked.load` into a standard load when doing a non-LTO compilation. Previously using `-Zvirtual-function-elimination` on godbolt would in many cases trigger an error like ``` error: example.rs:21:5: in function _RNvCsjRjZ17mMryE_7example4call i32 (ptr, ptr): llvm.type.checked.load intrinsic must be lowered by the LowerTypeTests pass before code generation ``` Because there `--emit=asm` is passed to `rustc` and that is a non-LTO compilation where checked loads are not supported. --- LLVM uses this pass here as a part of `PassBuilder::buildFatLTODefaultPipeline` https://github.com/llvm/llvm-project/blob/5da6b3c590792a069c40d8982c8b0fb3557f241a/llvm/lib/Passes/PassBuilderPipelines.cpp#L1827-L1837 We don't really have an equivalent to that I think, so I just inserted it right before we start doing instruction selection (but after bitcode/llvm ir has been written), which appears to work.
…uwer Rollup of 17 pull requests Successful merges: - #165572 (Run the `FatLtoCleanup` pass to lower `llvm.type.checked.load`) - #166235 (Keep opening '(' when suggesting to remove '&' from pattern) - #166516 (Fix ICE in iterator method suggestion when the receiver is a block) - #166586 (abby test dsl: one binder to rule them all) - #166604 (fix: embed-source-dwarf test with remapped debuginfo) - #166620 (Change wording of overwrite span in `unused_assignments` lint) - #164289 (Add regression test for self-referential GAT with missing lifetime argument) - #165859 (Add codegen test for MaybeUninit array built in the return slot) - #166092 (add fake borrow tests for divergent match guards) - #166292 (Don't suggest closure braces for errors inside the body) - #166435 (Encode direct const mir) - #166447 (Document allocator behaviour of BTreeMap::append and BTreeSet::append) - #166558 (triagebot: Send "in progress" message when nomination is in progress pt. 2) - #166584 (Arg pos const mismatch ice) - #166599 (add alias-bound test) - #166606 (llvm-wrapper: Pass LibraryOptionsContext to computeDeadSymbolsWithConstProp etc.) - #166623 (Correct feature name for `is_cased()` method) Failed merges: - #166583 (abby dsl tests: the passing test should check-pass)
Rollup of 20 pull requests Successful merges: - #164161 (`-Znext-solver` Support a bit more types for rustdoc auto traits) - #165572 (Run the `FatLtoCleanup` pass to lower `llvm.type.checked.load`) - #166235 (Keep opening '(' when suggesting to remove '&' from pattern) - #166335 (A few fixes in x86 std_detect) - #166516 (Fix ICE in iterator method suggestion when the receiver is a block) - #166586 (abby test dsl: one binder to rule them all) - #166604 (fix: embed-source-dwarf test with remapped debuginfo) - #166620 (Change wording of overwrite span in `unused_assignments` lint) - #166626 (Remove some outdated comments about None terminator) - #164289 (Add regression test for self-referential GAT with missing lifetime argument) - #165859 (Add codegen test for MaybeUninit array built in the return slot) - #166092 (add fake borrow tests for divergent match guards) - #166292 (Don't suggest closure braces for errors inside the body) - #166435 (Encode direct const mir) - #166447 (Document allocator behaviour of BTreeMap::append and BTreeSet::append) - #166558 (triagebot: Send "in progress" message when nomination is in progress pt. 2) - #166584 (Arg pos const mismatch ice) - #166599 (add alias-bound test) - #166606 (llvm-wrapper: Pass LibraryOptionsContext to computeDeadSymbolsWithConstProp etc.) - #166623 (Correct feature name for `is_cased()` method) Failed merges: - #166583 (abby dsl tests: the passing test should check-pass)
Rollup merge of #165572 - folkertdev:fat-lto-cleanup, r=nikic Run the `FatLtoCleanup` pass to lower `llvm.type.checked.load` tracking issue: #68262 fixes #124093 Run the `FatLtoCleanup` pass which lowers `llvm.type.checked.load` into a standard load when doing a non-LTO compilation. Previously using `-Zvirtual-function-elimination` on godbolt would in many cases trigger an error like ``` error: example.rs:21:5: in function _RNvCsjRjZ17mMryE_7example4call i32 (ptr, ptr): llvm.type.checked.load intrinsic must be lowered by the LowerTypeTests pass before code generation ``` Because there `--emit=asm` is passed to `rustc` and that is a non-LTO compilation where checked loads are not supported. --- LLVM uses this pass here as a part of `PassBuilder::buildFatLTODefaultPipeline` https://github.com/llvm/llvm-project/blob/5da6b3c590792a069c40d8982c8b0fb3557f241a/llvm/lib/Passes/PassBuilderPipelines.cpp#L1827-L1837 We don't really have an equivalent to that I think, so I just inserted it right before we start doing instruction selection (but after bitcode/llvm ir has been written), which appears to work.
tracking issue: #68262
fixes #124093
Run the
FatLtoCleanuppass which lowersllvm.type.checked.loadinto a standard load when doing a non-LTO compilation. Previously using-Zvirtual-function-eliminationon godbolt would in many cases trigger an error likeBecause there
--emit=asmis passed torustcand that is a non-LTO compilation where checked loads are not supported.LLVM uses this pass here as a part of
PassBuilder::buildFatLTODefaultPipelinehttps://github.com/llvm/llvm-project/blob/5da6b3c590792a069c40d8982c8b0fb3557f241a/llvm/lib/Passes/PassBuilderPipelines.cpp#L1827-L1837
We don't really have an equivalent to that I think, so I just inserted it right before we start doing instruction selection (but after bitcode/llvm ir has been written), which appears to work.