[PATCH] D29016: [LoopUnswitch] Do not freeze condition if hoisted branch is guaranteed to be reachable

Juneyoung Lee via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 04:00:59 PST 2017


aqjune created this revision.
Herald added a subscriber: mzolotukhin.

If the branch is hoisted to the loop header, and we know that it was originally
reachable, then no freeze instruction is needed since we are not introducing
a new branch in the dynamic control-flow.

For example:
while (D) {

  I1
  I2
  if (C) { A }
  else   { B }

}

If we know that I1 and I2 always transfer execution to the successor, then we
know that branch on C is reachable if D is true at least once.
Therefore, transforming the code above to the following is correct:

if (D) {

  if (C) {
    do { I1 I2 A } while (D)
  } else {
    do { I1 I2 B } while (D)
  }

}


https://reviews.llvm.org/D29016

Files:
  lib/Transforms/Scalar/LoopUnswitch.cpp
  test/Transforms/LoopUnswitch/2011-11-18-SimpleSwitch.ll
  test/Transforms/LoopUnswitch/2011-11-18-TwoSwitches-Threshold.ll
  test/Transforms/LoopUnswitch/2011-11-18-TwoSwitches.ll
  test/Transforms/LoopUnswitch/2015-06-17-Metadata.ll
  test/Transforms/LoopUnswitch/copy-metadata.ll
  test/Transforms/LoopUnswitch/freeze.ll
  test/Transforms/LoopUnswitch/infinite-loop.ll
  test/Transforms/LoopUnswitch/msan.ll
  test/Transforms/LoopUnswitch/trivial-unswitch.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29016.85348.patch
Type: text/x-patch
Size: 14400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170123/c38a4714/attachment.bin>


More information about the llvm-commits mailing list