https://lemire.me/blog/2019/02/08/faster-remainders-when-the-divisor-is-a-constant-beating-compilers-and-libdivide/
Seems to describe a nice optimisation to have.
Maybe this is more on the llvm side than rustc side?
Some complementary comments:
https://news.ycombinator.com/item?id=19116020
LLVM or gcc should be able to do that optimization.
I think this is called strength reduction and LLVM should already do it easily. Even if not, this should be implemented in LLVM, not rustc, so I'll close this. If you can demonstrate the optimization not happening, please post a reproduction and I'll reopen.
Most helpful comment
I think this is called strength reduction and LLVM should already do it easily. Even if not, this should be implemented in LLVM, not rustc, so I'll close this. If you can demonstrate the optimization not happening, please post a reproduction and I'll reopen.