Open Rudxain opened 2 weeks ago
isqrt is internally implemented with the help of a lookup table. It looks like LLVM is unable to optimize based on properties of the lookup table like in this case all entries for an input 4 and higher being at least 2.
I was about to suggest assume(TABLE.is_sorted())
, but the docs were prepared to stop me!:
The more complicated the condition, the less likely this is to be useful. For example,
assert_unchecked(foo.is_sorted())
is a complex enough value that the compiler is unlikely to be able to take advantage of it.
Thank you, to whoever wrote that ❤️
Adding assume(output.unchecked_mul(output) <= input)
at the end might work. Though a more realistic testcase to show that this benefits some code would be nice.
Edit, nevermind, you want a lower bound, not an upper bound.
I tried this code:
I expected to see this happen: 2nd assertion non-existent in assembly.
Instead, this happened:
Meta
Playground
rustc --version --verbose
:No Backtrace
@rustbot label: +I-slow, -C-bug