[PATCH] D58950: [PowerPC] Strength reduction of multiply by a constant by shift and add/sub in place

Zixuan Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 4 19:42:07 PST 2019


wuzish created this revision.
wuzish added reviewers: hfinkel, nemanjai, jsji.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

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.


Repository:
  rL LLVM

https://reviews.llvm.org/D58950

Files:
  llvm/lib/Target/PowerPC/PPCISelLowering.cpp
  llvm/lib/Target/PowerPC/PPCISelLowering.h
  llvm/test/CodeGen/PowerPC/mul-const-i64.ll
  llvm/test/CodeGen/PowerPC/mul-const-vector.ll
  llvm/test/CodeGen/PowerPC/mul-const.ll
  llvm/test/CodeGen/PowerPC/mul-neg-power-2.ll
  llvm/test/CodeGen/PowerPC/mulli64.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58950.189264.patch
Type: text/x-patch
Size: 30453 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190305/53b56c37/attachment.bin>


More information about the llvm-commits mailing list