[PATCH] D33946: [InlineCost] Find identical loads in single block function

Haicheng Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 6 09:40:09 PDT 2017


haicheng created this revision.
Herald added subscribers: kristof.beyls, mehdi_amini, mcrosier, aemerson.

LLVM Inliner encourages to inline single block callee by giving it higher threshold.  However, some large single block callees still cannot be inlined although they have many redundant instructions that can be removed if they are inlined.

The motivation example is in the test case which is a fully unrolled 3x3 matrix multiplication.  It loads every data in matrix a and b three times because of the Stores between them.  The SROA analysis can figure out that these Stores can be simplified and then these redundant loads should also be free.

  define void @outer(%struct.matrix* %a, %struct.matrix* %b) {
    %c = alloca %struct.matrix
    call void @matrix_multiply(%struct.matrix* %a, %struct.matrix* %b, %struct.matrix* %c)
    ret void
  }
  define void @matrix_multiply(%struct.matrix* %a, %struct.matrix* %b, %struct.matrix* %c) {

This simple patch tries to find identical redundant loads enabled by SROA analysis in a single block callee.  It stops finding Loads if there are Stores that cannot be simplified or there are function calls in the callee.  The above restriction can be relaxed to find more CSE opportunities with more expensive analysis.

I tested the patch with SPEC20xx and llvm-test-suite using https://reviews.llvm.org/owners/package/3/+LTO/https://reviews.llvm.org/owners/package/3//https://reviews.llvm.org/owners/package/2//Os on x86 and AArch64.  Only spec2006/milc gets impacted when using https://reviews.llvm.org/owners/package/3/+LTO.  On X86, the performance is improved by +3.6% and the code size is increased by 0.07%.   On AArch64, the performance is improved by +1.5% and code size has no change.


Repository:
  rL LLVM

https://reviews.llvm.org/D33946

Files:
  lib/Analysis/InlineCost.cpp
  test/Transforms/Inline/redundant-loads.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33946.101570.patch
Type: text/x-patch
Size: 14910 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170606/0a51a059/attachment.bin>


More information about the llvm-commits mailing list