[cfe-commits] Fix bug 12212 Missing mul-to-shift conversion for negative non-power-of 2 constants on ARM

Weiming Zhao weimingz at codeaurora.org
Thu Mar 8 16:01:32 PST 2012


Hello,

 

LLVM supports converting multiplication to shifting and add/sub operations
if possible when one operand is a integer variable and the other is a
positive constant even if the constant is not power of 2.

For example, "x*5" will be converted to "x+x<<2".

 

However, when the constant  is a negative and not power of 2, it always
emits "mul" even if using shifting+add/sub is possible.

For example, "x*-7" should be converted to "x-x<<8"  (sub r0, r0, r0, lsl #3
)

 

I have reported this into the bugzilla. The URL is 

http://llvm.org/bugs/show_bug.cgi?id=12212

 

The cause of the issue is in ARMISelLowering.cpp, it treats the constant
("MulAmt") as uint64_t and therefore it omits the case when MulAmt could be
negative.

So, I'm providing the fix for this issue. 

I also run the unit tests and the test suite. My fix doesn't change any
result from validtion tests. I believe this is good fix.  :D

 

I'm attaching the fix (0001-Bug12212-*.patch) and an updated test case
(0002-neg-mul-const-unit-test.patch) for such scenario as well as my
validation run results (test_results.tar.bz2).

 

Please review it.

 

Thanks,

Weiming Zhao

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120308/2a4edc2d/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Bug12212-LLVM-misses-multiply-by-non-power-of-2-negat.patch
Type: application/octet-stream
Size: 3403 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120308/2a4edc2d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-neg-mul-const-unit-test.patch
Type: application/octet-stream
Size: 1413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120308/2a4edc2d/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_result.tar.bz2
Type: application/octet-stream
Size: 7621 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120308/2a4edc2d/attachment-0002.obj>


More information about the cfe-commits mailing list