[PATCH] D36172: [InstCombine] Improve profitability check for folding PHI args

Ulrich Weigand via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 1 13:24:25 PDT 2017


uweigand created this revision.

FoldPHIArgOpIntoPHI and related routines move operations from PHI
arguments to the result of the PHI node.  To avoid creating more
new operations than are removed by the transformation, this is
currently only done if the original operations each have a single
use only (i.e. the PHI node).  This is overly pessimistic for
two reasons:

- A single operation can be used multiple times as input to the same PHI node.  This is called out in a FIXME in the code: // FIXME: The hasOneUse check will fail for PHIs that use the value more // than themselves more than once.

- Sometimes there are two (or more) PHI nodes using the same set of arguments (e.g. if a loop variable is also used after the end of the loop).  If *all* these PHIs are transformed, the original argument operations will still be dead.

This patch implements an IsFoldPHIArgProfitable routine that
performs a more precise check to determine whether after all
PHI nodes are transformed, there will be no more operations
in total than we had before.  This check is then used instead
of the hasOneUse checks throughout FoldPHIArgOpIntoPHI and
related routines.

The existing Transforms/LoopUnroll/runtime-loop-multiple-exits.ll
test case now shows further improvement (it was using a single
operation multiple times in the same PHI).  A new test added to
Transforms/InstCombine/phi.ll demonstrates the multiple-PHI case.


https://reviews.llvm.org/D36172

Files:
  lib/Transforms/InstCombine/InstCombinePHI.cpp
  test/Transforms/InstCombine/phi.ll
  test/Transforms/LoopUnroll/runtime-loop-multiple-exits.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36172.109190.patch
Type: text/x-patch
Size: 11554 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170801/eb08c5b3/attachment.bin>


More information about the llvm-commits mailing list