The algorithm is borrowed from the Mips backend.
This also makes jumptables more efficient, they no longer require
a libcall.
Differential D36061
[MSP430] Implement multiplication by a constant pftbest on Jul 30 2017, 9:00 AM. Authored by
Details
Diff Detail
Event TimelineComment Actions
This looks like target-independent code, and if multiple backends will be using it, please turn it into a target-independent utility, and use that function from both backends, or make it part of the default lowering. Comment Actions
You are right, genConstMult function is target-independent.
I don't think that would work, because we use this function differently.
Can you please suggest where can I put this function? I've never heard about target-independent utilities. Comment Actions
For this particular function, if you just want to share the code between MSP430 and MIPS, probably makes sense to stick it into the SelectionDAG class The alternative would be to make this a target-independent lowering in LegalizeDAG. 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. Comment Actions
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. 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. Comment Actions @efriedma ; BB#0: mov.w r12, r13 rla.w r12 add.w r12, r13 rla.w r12 rla.w r12 rla.w r12 mov.w r12, r14 sub.w r13, r14 rla.w r12 rla.w r12 mov.w r12, r13 sub.w r14, r13 rla.w r12 rla.w r12 mov.w r12, r14 sub.w r13, r14 rla.w r12 rla.w r12 mov.w r12, r13 sub.w r14, r13 rla.w r12 rla.w r12 mov.w r12, r14 sub.w r13, r14 rla.w r12 rla.w r12 sub.w r14, r12 ret Comment Actions Moved the algorithm into SelectionDAG Comment Actions Fixed an issue with i8 not being promoted to i16 in case we fall back Added more tests. Comment Actions I'm not really the best person to review this (since I'm not really that familiar with either MIPS or MSP430), but I can provide some more comments.
|
I'm not sure this algorithm is right? In any case, it's a lot different from what getMulByConstant is actually doing, so needs a lot of comments.