Swap loop invariant GEP with loop variant GEP to allow more LICM.
authorLawrence Hu <lawrence@codeaurora.org>
Wed, 23 Sep 2015 19:25:30 +0000 (19:25 +0000)
committerLawrence Hu <lawrence@codeaurora.org>
Wed, 23 Sep 2015 19:25:30 +0000 (19:25 +0000)
commitff25c07a59d6b98f87532e0d9e218f8247cdfd75
treefd70e3f3ecdf4a3b0b00918902f220fde26c1e0a
parent84e146173d700db89ec28a7e4c4ea38e2062d1b1
Swap loop invariant GEP with loop variant GEP to allow more LICM.

    This patch changes the order of GEPs generated by Splitting GEPs
    pass, specially when one of the GEPs has constant and the base is
    loop invariant, then we will generate the GEP with constant first
    when beneficial, to expose more cases for LICM.

    If originally Splitting GEP generate the following:
      do.body.i:
        %idxprom.i = sext i32 %shr.i to i64
        %2 = bitcast %typeD* %s to i8*
        %3 = shl i64 %idxprom.i, 2
        %uglygep = getelementptr i8, i8* %2, i64 %3
        %uglygep7 = getelementptr i8, i8* %uglygep, i64 1032
      ...
    Now it genereates:
      do.body.i:
        %idxprom.i = sext i32 %shr.i to i64
        %2 = bitcast %typeD* %s to i8*
        %3 = shl i64 %idxprom.i, 2
        %uglygep = getelementptr i8, i8* %2, i64 1032
        %uglygep7 = getelementptr i8, i8* %uglygep, i64 %3
      ...

    For no-loop cases, the original way of generating GEPs seems to
    expose more CSE cases, so we don't change the logic for no-loop
    cases, and only limit our change to the specific case we are
    interested in.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248420 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp
test/CodeGen/AArch64/aarch64-loop-gep-opt.ll [new file with mode: 0644]