Skip to content

isqrt treated as a black_box #132763

Description

@Rudxain

I tried this code:

#[inline(never)]
pub const fn f(n: u8) {
    assert!(n >= 4);
    assert!(2 <= n.isqrt());
}

Note

I've tried:

  • removing const
  • replacing u8 by usize
  • replacing 4 by 9 and 2 by 3

Outcome was the same

I expected to see this happen: 2nd assertion non-existent in assembly.

Instead, this happened:

# ... (snip)
.LBB0_4:
	leaq	.L__unnamed_4(%rip), %rdi
	leaq	.L__unnamed_5(%rip), %rdx
	movl	$32, %esi
	callq	*core::panicking::panic@GOTPCREL(%rip)
# ...
.L__unnamed_4:
	.ascii	"assertion failed: 2 <= n.isqrt()"
# ...

Meta

Playground

rustc --version --verbose:

1.84.0-nightly (2024-11-06 8549802939cd01111c46)

No Backtrace

@rustbot label: +I-slow, -C-bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchI-slowIssue: Problems and improvements with respect to performance of generated code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions