Try to break a multiplication with a specific immediate to
an/a addition/subtraction of left shifts.
Details
- Reviewers
zixuan-wu - Commits
- rG6d05f3f56e22: [CSKY] Optimize multiplication with immediates
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
It's better to add extra test case file to test every condition of // Break MULT into LSLI + ADDU/SUBU.
llvm/lib/Target/CSKY/CSKYISelLowering.cpp | ||
---|---|---|
119–121 | No related code change. | |
1386 | As this line code shows, it try to avoid data type larger than machine register size. And, CSKY is always 32-bit machine. | |
1394 | Does (-1 - Imm).isPowerOf2() also make sense? |
Thanks. I will create a new test file for all the cases.
llvm/lib/Target/CSKY/CSKYISelLowering.cpp | ||
---|---|---|
119–121 | This is modified by clang-format. | |
1394 | (-1 - Imm).isPowerOf2() will generate more instructions, I am not sure this is a win, though the multiplication is eliminated. So I left (-1 - Imm) unchanged. Maybe we can decide this case later. |
llvm/lib/Target/CSKY/CSKYISelLowering.cpp | ||
---|---|---|
1394 | Especially, for example, a * -4097 will be generated to lsli16, a1, a0, 12 addu16 a1, a0 movi16 a0, 0 subu16 a0, a1 An extra 'movi16` is needed. |
llvm/lib/Target/CSKY/CSKYISelLowering.cpp | ||
---|---|---|
1386 | Thanks. I have fixed this issue in my new uploaded patch. |
llvm/test/CodeGen/CSKY/mul-imm.ll | ||
---|---|---|
270 | This is the negative case, which can not be optimized due to data size exceeds 32-bit. |
LGTM. With minor change that the title of this revision can be more concrete.
llvm/lib/Target/CSKY/CSKYISelLowering.cpp | ||
---|---|---|
1386 | Can the 32 hard code be const variable which can be defined in Subtarget consistently? |
llvm/lib/Target/CSKY/CSKYISelLowering.cpp | ||
---|---|---|
1386 | Done. I have created a CSKYSubtarget::getDataSizeInBits() for that. |
This patch relies on https://reviews.llvm.org/D153105, which also needs your approval.
llvm/lib/Target/CSKY/CSKYSubtarget.h | ||
---|---|---|
210 | I think the name getDataSizeInBits is not precise about target machine. static const unsigned XLEN = 32; may be better? |
llvm/lib/Target/CSKY/CSKYSubtarget.h | ||
---|---|---|
210 | I prefer const unsigned XLen = 32;. |
llvm/lib/Target/CSKY/CSKYSubtarget.h | ||
---|---|---|
210 | LGTM |
No related code change.