[PowerPC] Prepare loops for pre-increment loads/stores
authorHal Finkel <hfinkel@anl.gov>
Thu, 5 Feb 2015 18:43:00 +0000 (18:43 +0000)
committerHal Finkel <hfinkel@anl.gov>
Thu, 5 Feb 2015 18:43:00 +0000 (18:43 +0000)
commitb8a6712c275d4d40996308a6c35f5470e48dec09
tree4d97b7211b9fd51fdea9842e718a25b2594a01d6
parent885b67a5c38222ef0523f83cc2e8bf6f151c264a
[PowerPC] Prepare loops for pre-increment loads/stores

PowerPC supports pre-increment load/store instructions (except for Altivec/VSX
vector load/stores). Using these on embedded cores can be very important, but
most loops are not naturally set up to use them. We can often change that,
however, by placing loops into a non-canonical form. Generically, this means
transforming loops like this:

  for (int i = 0; i < n; ++i)
    array[i] = c;

to look like this:

  T *p = array[-1];
  for (int i = 0; i < n; ++i)
    *++p = c;

the key point is that addresses accessed are pulled into dedicated PHIs and
"pre-decremented" in the loop preheader. This allows the use of pre-increment
load/store instructions without loop peeling.

A target-specific late IR-level pass (running post-LSR), PPCLoopPreIncPrep, is
introduced to perform this transformation. I've used this code out-of-tree for
generating code for the PPC A2 for over a year. Somewhat to my surprise,
running the test suite + externals on a P7 with this transformation enabled
showed no performance regressions, and one speedup:

External/SPEC/CINT2006/483.xalancbmk/483.xalancbmk
-2.32514% +/- 1.03736%

So I'm going to enable it on everything for now. I was surprised by this
because, on the POWER cores, these pre-increment load/store instructions are
cracked (and, thus, harder to schedule effectively). But seeing no regressions,
and feeling that it is generally easier to split instructions apart late than
it is to combine them late, this might be the better approach regardless.

In the future, we might want to integrate this functionality into LSR (but
currently LSR does not create new PHI nodes, so (for that and other reasons)
significant work would need to be done).

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@228328 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Target/PowerPC/CMakeLists.txt
lib/Target/PowerPC/PPC.h
lib/Target/PowerPC/PPCLoopPreIncPrep.cpp [new file with mode: 0644]
lib/Target/PowerPC/PPCTargetMachine.cpp
test/CodeGen/PowerPC/addi-licm.ll
test/CodeGen/PowerPC/code-align.ll