[PATCH] D35195: [WIP][PowerPC] run additional InstCombine pass after PPCCTRLoop pass

Hiroshi Inoue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 10 04:34:23 PDT 2017


inouehrs created this revision.

This patch add an additional InstCombine pass executed after PPCCTRLoop pass.
The intention of this additional InstCombine pass is to clean up accesses to induction variables in a loop if PPCCTRLoop pass makes them dead code. 
A motivating example is as follow:

  bool func(long a[N][N], long row, long col) {
      for (long i = row, j = col; j >= 0 && i < N; i++, j--)
          if (a[i][j]) return false;
      return true;
  }

This loop is compiled into

  .LBB0_2:                                # %for.body
  	ldu 7, 56(6)
  	cmpldi	 7, 0
  	bne	 0, .LBB0_5
  	addi 4, 4, 1
  	addi 5, 5, -1
  	bdnz .LBB0_2

Two `addi` for r4 and r5 are not used here.
By running InstCombine (even with ExpensiveCombines = false), these instructions are eliminated.

By adding the last InstCombine pass, 43 test cases (including those not optimized by PPCCTRLoop) fail. So it looks like this last InstCombine pass cleanup the code in many cases. 
I observed that adding this pass increases compilation time by about 0.5% (both in # cycles and in # instructions).

I like to hear the opinion on whether adding this last InstCombine pass is reasonable as a trade-off between the compilation cost and code quality before modifying lots of test cases.


https://reviews.llvm.org/D35195

Files:
  lib/Target/PowerPC/LLVMBuild.txt
  lib/Target/PowerPC/PPCTargetMachine.cpp


Index: lib/Target/PowerPC/PPCTargetMachine.cpp
===================================================================
--- lib/Target/PowerPC/PPCTargetMachine.cpp
+++ lib/Target/PowerPC/PPCTargetMachine.cpp
@@ -336,9 +336,14 @@
   if (!DisablePreIncPrep && getOptLevel() != CodeGenOpt::None)
     addPass(createPPCLoopPreIncPrepPass(getPPCTargetMachine()));
 
-  if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None)
+  if (!DisableCTRLoops && getOptLevel() != CodeGenOpt::None) {
     addPass(createPPCCTRLoops());
 
+    // Run instcombine to eliminate induction variables unused after
+    // rewritten by CTR loop optimization.
+    addPass(createInstructionCombiningPass(/* ExpensiveCombines = */false));
+  }
+
   return false;
 }
 
Index: lib/Target/PowerPC/LLVMBuild.txt
===================================================================
--- lib/Target/PowerPC/LLVMBuild.txt
+++ lib/Target/PowerPC/LLVMBuild.txt
@@ -31,5 +31,5 @@
 type = Library
 name = PowerPCCodeGen
 parent = PowerPC
-required_libraries = Analysis AsmPrinter CodeGen Core MC PowerPCAsmPrinter PowerPCDesc PowerPCInfo Scalar SelectionDAG Support Target TransformUtils
+required_libraries = Analysis AsmPrinter CodeGen Core InstCombine MC PowerPCAsmPrinter PowerPCDesc PowerPCInfo Scalar SelectionDAG Support Target TransformUtils
 add_to_library_groups = PowerPC


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35195.105821.patch
Type: text/x-patch
Size: 1342 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170710/85df047f/attachment.bin>


More information about the llvm-commits mailing list