-
Notifications
You must be signed in to change notification settings - Fork 13.4k
gvn: bail out unavoidable non-ssa locals in repeat #141252
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
Conversation
We cannot transform `*elem` to `array[idx1]` in the following code, as `idx1` has already been modified. ```rust mir! { let array; let elem; { array = [*val; 5]; elem = &array[idx1]; idx1 = idx2; RET = *elem; Return() } } ```
_4 = [copy (*_3); 5]; | ||
_5 = &_4[_1]; | ||
_1 = copy _2; | ||
_0 = copy (*_5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your change does work, but I feel like we have a systematic problem that this patch doesn't fix. Isn't GVN supposed to notice that |
@@ -682,6 +683,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { | |||
} | |||
ProjectionElem::Index(idx) => { | |||
if let Value::Repeat(inner, _) = self.get(value) { | |||
*from_non_ssa_index |= self.locals[idx].is_none(); | |||
return Some(*inner); | |||
} | |||
let idx = self.locals[idx]?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@saethlin Yes, right here. This is an exception for the repeat array, because whichever value we access, it's all the same. However, we have overlooked the out-of-bounds case here.
Sorry it took me a while to convince myself this is a good strategy for fixing this. I now agree. @bors r+ |
Rollup of 8 pull requests Successful merges: - #140367 (add `asm_cfg`: `#[cfg(...)]` within `asm!`) - #140894 (Make check-cfg diagnostics work in `#[doc(cfg(..))]`) - #141252 (gvn: bail out unavoidable non-ssa locals in repeat) - #141517 (rustdoc: use descriptive tooltip if doctest is conditionally ignored) - #141551 (Make two transmute-related MIR lints into HIR lint) - #141591 (ci: fix llvm test coverage) - #141647 (Bump master `stage0` compiler) - #141659 (Add `Result::map_or_default` and `Option::map_or_default`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #141252 - dianqk:gvn-repeat-index, r=saethlin gvn: bail out unavoidable non-ssa locals in repeat Fixes #141251. We cannot transform `*elem` to `array[idx1]` in the following code, as `idx1` has already been modified. ```rust mir! { let array; let elem; { array = [*val; 5]; elem = &array[idx1]; idx1 = idx2; RET = *elem; Return() } } ``` Perhaps I could transform it to `array[0]`, but I prefer the conservative approach. r? mir-opt
Rollup of 8 pull requests Successful merges: - rust-lang/rust#140367 (add `asm_cfg`: `#[cfg(...)]` within `asm!`) - rust-lang/rust#140894 (Make check-cfg diagnostics work in `#[doc(cfg(..))]`) - rust-lang/rust#141252 (gvn: bail out unavoidable non-ssa locals in repeat) - rust-lang/rust#141517 (rustdoc: use descriptive tooltip if doctest is conditionally ignored) - rust-lang/rust#141551 (Make two transmute-related MIR lints into HIR lint) - rust-lang/rust#141591 (ci: fix llvm test coverage) - rust-lang/rust#141647 (Bump master `stage0` compiler) - rust-lang/rust#141659 (Add `Result::map_or_default` and `Option::map_or_default`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 8 pull requests Successful merges: - rust-lang#140367 (add `asm_cfg`: `#[cfg(...)]` within `asm!`) - rust-lang#140894 (Make check-cfg diagnostics work in `#[doc(cfg(..))]`) - rust-lang#141252 (gvn: bail out unavoidable non-ssa locals in repeat) - rust-lang#141517 (rustdoc: use descriptive tooltip if doctest is conditionally ignored) - rust-lang#141551 (Make two transmute-related MIR lints into HIR lint) - rust-lang#141591 (ci: fix llvm test coverage) - rust-lang#141647 (Bump master `stage0` compiler) - rust-lang#141659 (Add `Result::map_or_default` and `Option::map_or_default`) r? `@ghost` `@rustbot` modify labels: rollup
Fixes #141251.
We cannot transform
*elem
toarray[idx1]
in the following code, asidx1
has already been modified.Perhaps I could transform it to
array[0]
, but I prefer the conservative approach.r? mir-opt