[PATCH] D36753: [SimplifyCFG] Do not perform tail sinking if there are extra moves introduced

Rong Xu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 15 09:54:47 PDT 2017


xur created this revision.

SinkThenElseCodeToEnd() tries to sink the common instructions to a new BB (sink.split).
But it does not take account of the potential moves in the original BBs.

As shown in the newly added test case (test19 in sink-common-code.ll), we have
extra moves in the final assembly (which also prevents the constant folding). This
optimization hurts the performance and not reduce the code size either.

This patch checks if the phi-operand are of constants. If that's the case,
an extra move is likely needed. If the total number of moves inserted is greater
than the number instructions saved by tail sinking, we should not perform.

It only applies to the following pattern:
 if (a)

  f1;

else if (b)

  f2;

For pattern of

  if(a)
    f1;
  else
    f2;

If the condition is simple and the constants in f1 and f2 are in close range,
tail sinking could remove the branch. This patch won't touch this case


https://reviews.llvm.org/D36753

Files:
  lib/Transforms/Utils/SimplifyCFG.cpp
  test/Transforms/SimplifyCFG/sink-common-code.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36753.111192.patch
Type: text/x-patch
Size: 4812 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170815/e0d336bb/attachment-0001.bin>


More information about the llvm-commits mailing list