@whitequark try using different constants to suicide by; this is a special case of since mine and this approach usually requires a small correction afterwards (to the tube of conditionally adding one or something like that).
Or am I misreading and this is more witchy?
@whitequark of I remember by the time I'm home in the evening I will get godbolt to spit out the more general case of this witchery
All compilers I've seen can do this optimization. See for example https://godbolt.org/z/v34E58deK, which has the "add a fixup from the upper word of the multiplication result". The reason why it's necessary is that you don't actually want multiplicative inverse modulo 2^wordsize in the case when the input value is not divisible by the constant.
@whitequark Sorry, my example was wrong (the weirdness in there was purely to handle rounding in negatives).
https://godbolt.org/z/WTajrPKze is an example with the additional weirdness I was thinking of.
@robryk fwiw this was emitted by msvc