[PATCH] D91724: [HardwareLoops] Change order of SCEV expression construction for InitLoopCount.

Janek van Oirschot via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 10:28:28 PST 2020


JanekvO created this revision.
JanekvO added reviewers: samparker, SjoerdMeijer, dmgreen, ZhangKang.
Herald added subscribers: llvm-commits, steven.zhang, hiraditya, nemanjai.
Herald added a project: LLVM.
JanekvO requested review of this revision.

Putting the +1 before the zero-extend will allow scalar evolution to fold the expression in some cases such as the one shown in PowerPC's `shrink-wrap.ll` test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91724

Files:
  llvm/lib/CodeGen/HardwareLoops.cpp
  llvm/test/CodeGen/PowerPC/shrink-wrap.ll


Index: llvm/test/CodeGen/PowerPC/shrink-wrap.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/shrink-wrap.ll
+++ llvm/test/CodeGen/PowerPC/shrink-wrap.ll
@@ -32,9 +32,7 @@
 ; CHECK:         std 
 ; CHECK:         blt 0, .LBB0_3
 ; CHECK:       # %bb.1:
-; CHECK-NEXT:    addi
 ; CHECK-NEXT:    clrldi
-; CHECK-NEXT:    addi
 ; CHECK-NEXT:    mtctr
 ; CHECK-NEXT:    li 
 ; CHECK:       .LBB0_2: 
Index: llvm/lib/CodeGen/HardwareLoops.cpp
===================================================================
--- llvm/lib/CodeGen/HardwareLoops.cpp
+++ llvm/lib/CodeGen/HardwareLoops.cpp
@@ -383,12 +383,12 @@
   // loop counter and tests that is not zero?
 
   SCEVExpander SCEVE(SE, DL, "loopcnt");
+
+  ExitCount = SE.getAddExpr(ExitCount, SE.getOne(ExitCount->getType()));
   if (!ExitCount->getType()->isPointerTy() &&
       ExitCount->getType() != CountType)
     ExitCount = SE.getZeroExtendExpr(ExitCount, CountType);
 
-  ExitCount = SE.getAddExpr(ExitCount, SE.getOne(CountType));
-
   // If we're trying to use the 'test and set' form of the intrinsic, we need
   // to replace a conditional branch that is controlling entry to the loop. It
   // is likely (guaranteed?) that the preheader has an unconditional branch to


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91724.306152.patch
Type: text/x-patch
Size: 1281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201118/d01b8639/attachment.bin>


More information about the llvm-commits mailing list