OSDN Git Service

[LoopUnswitch] Unswitch on conditions feeding into guards
authorSanjoy Das <sanjoy@playingwithpointers.com>
Sun, 26 Jun 2016 05:10:45 +0000 (05:10 +0000)
committerSanjoy Das <sanjoy@playingwithpointers.com>
Sun, 26 Jun 2016 05:10:45 +0000 (05:10 +0000)
commit075766d9d08fa936297c68074c76cb1c5c08a83b
treea066fb33251a31537ac5e4456d1eb3160035fce6
parente6932065228001fe73a23cbb747ee90197403534
[LoopUnswitch] Unswitch on conditions feeding into guards

Summary:
This is a straightforward extension of what LoopUnswitch does to
branches to guards.  That is, we unswitch

```
for (;;) {
  ...
  guard(loop_invariant_cond);
  ...
}
```

into

```
if (loop_invariant_cond) {
  for (;;) {
    ...
    // There is no need to emit guard(true)
    ...
  }
} else {
  for (;;) {
    ...
    guard(false);
    // SimplifyCFG will clean this up by adding an
    // unreachable after the guard(false)
    ...
  }
}
```

Reviewers: majnemer

Subscribers: mcrosier, llvm-commits, mzolotukhin

Differential Revision: http://reviews.llvm.org/D21725

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273801 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/LoopUnswitch.cpp
test/Transforms/LoopUnswitch/guards.ll [new file with mode: 0644]