[Bug target/105521] missed optimization in modulo arithmetic

goswin-v-b at web dot de gcc-bugzilla@gcc.gnu.org
Sun May 8 12:45:41 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105521

--- Comment #3 from Goswin von Brederlow <goswin-v-b at web dot de> ---
(In reply to Andrew Pinski from comment #1)
> This requires having a, 64bit/32bit (and 128bit/64bit) pattern really. So
> this is both a middle-end issue and a target issue.
> 
> Note there might be another bug asking for the same optimization.
> 
> Also note x86_64 might be the only popular target which has this kind of div
> instruction so this might not get any attention as it is also a small
> peephole where most people don't use 128bit integers either (they are
> non-standard even).

I know m68k had a 64bit/32bit pattern but it is indeed rare.

On x86_64 a (32bit * 32bit = 64bit) % 32bit uses the 128bit/64bit DIV
instruction and two extra truncation to 32bit for the input registers. On many
cpus that is significantly (factor 3-10) slower than the 64bit/32bit version.

This could potentially affect every / and % operation and preceding *, allowing
for the faster opcodes with fewer bits to be used where the compiler can reason
about the magnitude of the arguments.


More information about the Gcc-bugs mailing list