[llvm-branch-commits] [llvm] cb317d6 - update form prepare

Chen Zheng via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 17 22:15:13 PDT 2021


Author: Chen Zheng
Date: 2021-07-15T08:02:10Z
New Revision: cb317d60cca17f5ab60bd841b0d25a145cedfa70

URL: https://github.com/llvm/llvm-project/commit/cb317d60cca17f5ab60bd841b0d25a145cedfa70
DIFF: https://github.com/llvm/llvm-project/commit/cb317d60cca17f5ab60bd841b0d25a145cedfa70.diff

LOG: update form prepare

Added: 
    

Modified: 
    llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
    llvm/test/CodeGen/PowerPC/loop-instr-prep-non-const-increasement.ll
    llvm/test/CodeGen/PowerPC/lsr-profitable-chain.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp b/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
index 5f08268277a0e..010f49c8d3ebc 100644
--- a/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
+++ b/llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp
@@ -533,13 +533,6 @@ bool PPCLoopInstrFormPrep::rewriteLoadStores(Loop *L, Bucket &BucketChain,
     return MadeChange;
   }
 
-  // Now we only handle update form for constant increment.
-  // FIXME: add support for non-constant increment UpdateForm.
-  if (!IsConstantInc && Form == UpdateForm) {
-    LLVM_DEBUG(dbgs() << "not a constant incresement for update form!\n");
-    return MadeChange;
-  }
-
   // For some DS form load/store instructions, it can also be an update form,
   // if the stride is a multipler of 4. Use update form if prefer it.
   bool CanPreInc =
@@ -547,10 +540,13 @@ bool PPCLoopInstrFormPrep::rewriteLoadStores(Loop *L, Bucket &BucketChain,
        ((Form == DSForm) && IsConstantInc &&
         !BasePtrIncConstantSCEV->getAPInt().urem(4) && PreferUpdateForm));
   const SCEV *BasePtrStartSCEV = nullptr;
-  if (CanPreInc)
-    BasePtrStartSCEV =
-        SE->getMinusSCEV(BasePtrSCEV->getStart(), BasePtrIncConstantSCEV);
-  else
+  if (CanPreInc) {
+    assert(SE->isLoopInvariant(BasePtrIncSCEV, L) &&
+           "Increment is not loop invariant!\n");
+    BasePtrStartSCEV = SE->getMinusSCEV(BasePtrSCEV->getStart(),
+                                        IsConstantInc ? BasePtrIncConstantSCEV
+                                                      : BasePtrIncSCEV);
+  } else
     BasePtrStartSCEV = BasePtrSCEV->getStart();
 
   if (!isSafeToExpand(BasePtrStartSCEV, *SE))
@@ -588,12 +584,10 @@ bool PPCLoopInstrFormPrep::rewriteLoadStores(Loop *L, Bucket &BucketChain,
   Instruction *PtrInc = nullptr;
   Instruction *NewBasePtr = nullptr;
   if (CanPreInc) {
-    assert(BasePtrIncConstantSCEV &&
-           "update form now only supports constant increment.");
     Instruction *InsPoint = &*Header->getFirstInsertionPt();
-    PtrInc = GetElementPtrInst::Create(
-        I8Ty, NewPHI, BasePtrIncConstantSCEV->getValue(),
-        getInstrName(MemI, GEPNodeIncNameSuffix), InsPoint);
+    PtrInc = GetElementPtrInst::Create(I8Ty, NewPHI, IncNode,
+                                       getInstrName(MemI, GEPNodeIncNameSuffix),
+                                       InsPoint);
     cast<GetElementPtrInst>(PtrInc)->setIsInBounds(IsPtrInBounds(BasePtr));
     for (auto PI : predecessors(Header)) {
       if (PI == LoopPredecessor)

diff  --git a/llvm/test/CodeGen/PowerPC/loop-instr-prep-non-const-increasement.ll b/llvm/test/CodeGen/PowerPC/loop-instr-prep-non-const-increasement.ll
index 6132074004305..6628ac89f79ad 100644
--- a/llvm/test/CodeGen/PowerPC/loop-instr-prep-non-const-increasement.ll
+++ b/llvm/test/CodeGen/PowerPC/loop-instr-prep-non-const-increasement.ll
@@ -85,18 +85,17 @@ define zeroext i8 @foo1(i8* %p, i32 signext %n, i32 signext %count) {
 ; CHECK-NEXT:    cmpwi r4, 1
 ; CHECK-NEXT:    blt cr0, .LBB1_4
 ; CHECK-NEXT:  # %bb.1: # %for.body.preheader
+; CHECK-NEXT:    extsw r5, r5
+; CHECK-NEXT:    sub r3, r3, r5
 ; CHECK-NEXT:    addi r6, r3, 1000
 ; CHECK-NEXT:    clrldi r3, r4, 32
-; CHECK-NEXT:    extsw r5, r5
-; CHECK-NEXT:    li r4, 0
 ; CHECK-NEXT:    mtctr r3
 ; CHECK-NEXT:    li r3, 0
 ; CHECK-NEXT:    .p2align 4
 ; CHECK-NEXT:  .LBB1_2: # %for.body
 ; CHECK-NEXT:    #
-; CHECK-NEXT:    lbzx r7, r6, r4
-; CHECK-NEXT:    add r4, r4, r5
-; CHECK-NEXT:    add r3, r7, r3
+; CHECK-NEXT:    lbzux r4, r6, r5
+; CHECK-NEXT:    add r3, r4, r3
 ; CHECK-NEXT:    bdnz .LBB1_2
 ; CHECK-NEXT:  # %bb.3: # %for.cond.cleanup
 ; CHECK-NEXT:    clrldi r3, r3, 56

diff  --git a/llvm/test/CodeGen/PowerPC/lsr-profitable-chain.ll b/llvm/test/CodeGen/PowerPC/lsr-profitable-chain.ll
index 346353bc12d0a..f2d8157faba32 100644
--- a/llvm/test/CodeGen/PowerPC/lsr-profitable-chain.ll
+++ b/llvm/test/CodeGen/PowerPC/lsr-profitable-chain.ll
@@ -50,26 +50,26 @@ define void @foo(double* readonly %0, double* %1, i64 %2, i64 %3, i64 %4, i64 %5
 ; CHECK-NEXT:    cmpd 6, 24
 ; CHECK-NEXT:    bge 0, .LBB0_2
 ; CHECK-NEXT:  # %bb.4:
-; CHECK-NEXT:    maddld 19, 0, 27, 30
+; CHECK-NEXT:    maddld 21, 0, 27, 30
 ; CHECK-NEXT:    maddld 20, 0, 27, 12
-; CHECK-NEXT:    add 22, 6, 28
-; CHECK-NEXT:    add 21, 6, 8
+; CHECK-NEXT:    add 23, 6, 28
+; CHECK-NEXT:    add 22, 6, 8
 ; CHECK-NEXT:    add 20, 6, 20
-; CHECK-NEXT:    add 19, 6, 19
-; CHECK-NEXT:    sldi 23, 6, 3
+; CHECK-NEXT:    add 19, 6, 21
+; CHECK-NEXT:    sldi 23, 23, 3
 ; CHECK-NEXT:    sldi 22, 22, 3
-; CHECK-NEXT:    sldi 21, 21, 3
-; CHECK-NEXT:    add 23, 4, 23
+; CHECK-NEXT:    sldi 21, 6, 3
+; CHECK-NEXT:    add 23, 29, 23
 ; CHECK-NEXT:    add 22, 29, 22
-; CHECK-NEXT:    add 21, 29, 21
 ; CHECK-NEXT:    sldi 20, 20, 3
 ; CHECK-NEXT:    sldi 19, 19, 3
+; CHECK-NEXT:    add 21, 4, 21
 ; CHECK-NEXT:    add 20, 3, 20
 ; CHECK-NEXT:    add 19, 3, 19
 ; CHECK-NEXT:    .p2align 5
 ; CHECK-NEXT:  .LBB0_5: # Parent Loop BB0_3 Depth=1
 ; CHECK-NEXT:    # => This Inner Loop Header: Depth=2
-; CHECK-NEXT:    lfd 0, 0(23)
+; CHECK-NEXT:    lfd 0, 0(21)
 ; CHECK-NEXT:    lfd 1, 0(20)
 ; CHECK-NEXT:    add 6, 6, 10
 ; CHECK-NEXT:    cmpd 6, 24
@@ -90,15 +90,6 @@ define void @foo(double* readonly %0, double* %1, i64 %2, i64 %3, i64 %4, i64 %5
 ; CHECK-NEXT:    lfd 1, 24(19)
 ; CHECK-NEXT:    add 19, 19, 11
 ; CHECK-NEXT:    xsadddp 0, 0, 1
-; CHECK-NEXT:    lfd 1, -16(21)
-; CHECK-NEXT:    xsadddp 0, 0, 1
-; CHECK-NEXT:    lfd 1, -8(21)
-; CHECK-NEXT:    xsadddp 0, 0, 1
-; CHECK-NEXT:    lfd 1, 0(21)
-; CHECK-NEXT:    xsadddp 0, 0, 1
-; CHECK-NEXT:    lfd 1, 8(21)
-; CHECK-NEXT:    add 21, 21, 11
-; CHECK-NEXT:    xsadddp 0, 0, 1
 ; CHECK-NEXT:    lfd 1, -16(22)
 ; CHECK-NEXT:    xsadddp 0, 0, 1
 ; CHECK-NEXT:    lfd 1, -8(22)
@@ -108,8 +99,17 @@ define void @foo(double* readonly %0, double* %1, i64 %2, i64 %3, i64 %4, i64 %5
 ; CHECK-NEXT:    lfd 1, 8(22)
 ; CHECK-NEXT:    add 22, 22, 11
 ; CHECK-NEXT:    xsadddp 0, 0, 1
-; CHECK-NEXT:    stfd 0, 0(23)
+; CHECK-NEXT:    lfd 1, -16(23)
+; CHECK-NEXT:    xsadddp 0, 0, 1
+; CHECK-NEXT:    lfd 1, -8(23)
+; CHECK-NEXT:    xsadddp 0, 0, 1
+; CHECK-NEXT:    lfd 1, 0(23)
+; CHECK-NEXT:    xsadddp 0, 0, 1
+; CHECK-NEXT:    lfd 1, 8(23)
 ; CHECK-NEXT:    add 23, 23, 11
+; CHECK-NEXT:    xsadddp 0, 0, 1
+; CHECK-NEXT:    stfd 0, 0(21)
+; CHECK-NEXT:    add 21, 21, 11
 ; CHECK-NEXT:    blt 0, .LBB0_5
 ; CHECK-NEXT:    b .LBB0_2
 ; CHECK-NEXT:  .LBB0_6:


        


More information about the llvm-branch-commits mailing list