https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112102
Bug ID: 112102 Summary: Inefficient Integer multiplication on MIPS processors Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: kazeemanuar at googlemail dot com Target Milestone: --- Running integer multiplication with the -Os flag enabled can generate 2 unnecessary NOP instructions. This increases the cost of integer multiplication from 7 to 9 cycles in most cases. Example code: int test(int a, int b, int c, int d) { return 788*a + 789 * b + 187 + c + d; } output: li $2,788 mult $4,$2 li $2,789 <--- could be moved down into one of the NOPs mflo $4 nop nop mult $5,$2 mflo $5 addu $4,$4,$5 addiu $4,$4,187 <--- could be moved up into one of the NOPs addu $4,$4,$6 <--- could be moved up into one of the NOPs jr $31 addu $2,$4,$7 This happens on all GCC versions as far as I can tell. Compiler explorer link: https://godbolt.org/z/M3x3s3KhM