[PATCH] D36061: [MSP430] Implement multiplication by a constant
Vadzim Dambrouski via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 31 16:09:19 PDT 2017
pftbest added a comment.
> Do you need to worry about codesize here? Lowering something like "a * 0x3333" to an inline sequence like this is going to generate a lot of code.
The `a * 0x3333` generates the following sequence (the register allocation is not very good in this case):
; BB#0:
mov.b r12, r13
rla.b r13
add.b r13, r12
rla.b r13
rla.b r13
rla.b r13
mov.b r13, r14
sub.b r12, r14
rla.b r13
rla.b r13
sub.b r14, r13
mov.w r13, r12
ret
It is 24 bytes in size and takes only 12 cycles, which is both smaller and faster than a library call.
If we have the hardware multiplier, then a library function is 20 bytes in size (+4 bytes per call), and takes 20 cycles to execute (including interrupts disabling).
But if we don't have a hardware multiplier, the library function is 70 bytes in size and i don't know how much slower.
We can provide an option like Lanai did ("lanai-constant-mul-threshold"), to limit the number of operations, but I think it would only be useful if we have a hardware multiplier.
https://reviews.llvm.org/D36061
More information about the llvm-commits
mailing list