This patch adds support of conversion (mul x, 2^N + 1) => (add (shl x, N), x) and (mul x, 2^N - 1) => (sub (shl x, N), x) if the multiplication can not be converted to LEA + SHL or LEA + LEA. LLVM has already supported this on ARM, and it should also be useful on X86. Note the patch currently only applies to cases where the constant operand is positive, and I am planing to add another patch to support negative cases after this.
Details
- Reviewers
RKSimon craig.topper - Commits
- rG1b26b9ec9dab: [X86ISelLowering] Add additional support for multiplication-to-shift conversion.
rGe8f9387e0cae: [X86ISelLowering] Add additional support for multiplication-to-shift conversion.
rL255415: [X86ISelLowering] Add additional support for multiplication-to-shift conversion.
rL255391: [X86ISelLowering] Add additional support for multiplication-to-shift conversion.
Diff Detail
Event Timeline
lib/Target/X86/X86ISelLowering.cpp | ||
---|---|---|
24313 | There doesn't appear to be anything to prevent overflow here - e.g. for a 32-bit multiply by 0xFFFFFFFF. Do we need an initial patch that replaces the uint64_t MulAmt with APInt MulAmt? |
lib/Target/X86/X86ISelLowering.cpp | ||
---|---|---|
24313 | I think you are correct. I can create a separate patch to replace uint64_t with APInt in this function. |
LGTM - with a couple of minor diffs.
lib/Target/X86/X86ISelLowering.cpp | ||
---|---|---|
24307 | Rephrase the assert message to make it clear that they are the cases that would involve overflow. | |
test/CodeGen/X86/imul.ll | ||
150 | Please add overflow test cases - I don't see them in this file although they maybe somewhere else? | |
151 | Missing newline |
Rephrase the assert message to make it clear that they are the cases that would involve overflow.