[PowerPC] Strength reduction of multiply by a constant by shift and add/sub in place
authorZi Xuan Wu <wuzish@cn.ibm.com>
Fri, 29 Mar 2019 03:08:39 +0000 (03:08 +0000)
committerZi Xuan Wu <wuzish@cn.ibm.com>
Fri, 29 Mar 2019 03:08:39 +0000 (03:08 +0000)
commit1445b77e8c6da8e43ba12f86b010852b97aea4fb
tree01f3f19b65c3acce66a70cf93bfed7d5bda3f7ed
parent2a3f42c90d4ba2860e039e4de92a75c75cfdc351
[PowerPC] Strength reduction of multiply by a constant by shift and add/sub in place

A shift and add/sub sequence combination is faster in place of a multiply by constant.
Because the cycle or latency of multiply is not huge, we only consider such following
worthy patterns.

```
(mul x, 2^N + 1) => (add (shl x, N), x)
(mul x, -(2^N + 1)) => -(add (shl x, N), x)
(mul x, 2^N - 1) => (sub (shl x, N), x)
(mul x, -(2^N - 1)) => (sub x, (shl x, N))
```

And the cycles or latency is subtarget-dependent so that we need consider the
subtarget to determine to do or not do such transformation.
Also data type is considered for different cycles or latency to do multiply.

Differential Revision: https://reviews.llvm.org/D58950

llvm-svn: 357233
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/lib/Target/PowerPC/PPCISelLowering.h
llvm/test/CodeGen/PowerPC/mul-const-i64.ll [new file with mode: 0644]
llvm/test/CodeGen/PowerPC/mul-const-vector.ll [new file with mode: 0644]
llvm/test/CodeGen/PowerPC/mul-const.ll [new file with mode: 0644]
llvm/test/CodeGen/PowerPC/mul-neg-power-2.ll [deleted file]
llvm/test/CodeGen/PowerPC/mulli64.ll [deleted file]