Skip to content
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

Emit the enum range assumption if the range only contains one element #83020

Merged
merged 1 commit into from
Mar 13, 2021

Conversation

Rustin170506
Copy link
Member

close #82871

@rust-highfive
Copy link
Contributor

r? @lcnr

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 11, 2021
@the8472
Copy link
Member

the8472 commented Mar 11, 2021

Naive question, but couldn't it be turned into a constant instead if there can only be a single value?

@nikic
Copy link
Contributor

nikic commented Mar 11, 2021

This needs a codegen test to make sure the desired optimization takes place. The src/test/codegen/enum-bounds-check*.rs tests can serve as inspiration.

@Rustin170506
Copy link
Member Author

Now it's look like:

	.section	__TEXT,__text,regular,pure_instructions
	.macosx_version_min 10, 7
	.globl	_index
	.p2align	4, 0x90
_index:
	.cfi_startproc
	pushq	%rbp
	.cfi_def_cfa_offset 16
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
	.cfi_def_cfa_register %rbp
	movl	(%rdi), %eax
	popq	%rbp
	retq
	.cfi_endproc

.subsections_via_symbols

@rust-log-analyzer

This comment has been minimized.

@Rustin170506
Copy link
Member Author

I think it's ready for review.

@lcnr
Copy link
Contributor

lcnr commented Mar 12, 2021

this does seem fine to me, would it be possible to instead emit a constant if start == end? it feels a bit weird to me to use range assumptions for this.

edit: ah, that was already asked in #83020 (comment)

@nikic
Copy link
Contributor

nikic commented Mar 12, 2021

this does seem fine to me, would it be possible to instead emit a constant if start == end? it feels a bit weird to me to use range assumptions for this.

That would be possible, but maybe not worth the bother to special case it? LLVM will end up replacing the value with a constant based on the assumption, so I don't think it will make much of a difference.

@lcnr
Copy link
Contributor

lcnr commented Mar 12, 2021

in this case

@bors r+

@bors
Copy link
Collaborator

bors commented Mar 12, 2021

📌 Commit d180f91 has been approved by lcnr

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 12, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Mar 12, 2021
Emit the enum range assumption if the range only contains one element

close rust-lang#82871
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 13, 2021
Rollup of 6 pull requests

Successful merges:

 - rust-lang#82984 (Simplify ast block lowering)
 - rust-lang#83012 (Update Clippy)
 - rust-lang#83020 (Emit the enum range assumption if the range only contains one element)
 - rust-lang#83037 (Support merge_functions option in NewPM since LLVM >= 12)
 - rust-lang#83052 (updated vulnerable deps)
 - rust-lang#83059 (Allow configuring `rustdoc --disable-minification` in config.toml)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 04e24ae into rust-lang:master Mar 13, 2021
@rustbot rustbot added this to the 1.52.0 milestone Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Array bounds check not elided when indexing with ZST enum
8 participants