Skip to content

Commit

Permalink
[SimpleLoopUnswitch] Early check exit for trivial unswitch with Memor…
Browse files Browse the repository at this point in the history
…ySSA.

Summary:
If MemorySSA is avaiable, we can skip checking all instructions if block has any Defs.
(volatile loads are also Defs).
We still need to check all instructions for "canThrow", even if no Defs are found.

Reviewers: chandlerc

Subscribers: sanjoy, jlebar, Prazek, george.burgess.iv, llvm-commits

Differential Revision: https://reviews.llvm.org/D57129

llvm-svn: 352393
  • Loading branch information
alinas committed Jan 28, 2019
1 parent 3720e2b commit 9321087
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
Expand Up @@ -847,6 +847,10 @@ static bool unswitchAllTrivialConditions(Loop &L, DominatorTree &DT,
// Check if there are any side-effecting instructions (e.g. stores, calls,
// volatile loads) in the part of the loop that the code *would* execute
// without unswitching.
if (MSSAU) // Possible early exit with MSSA
if (auto *Defs = MSSAU->getMemorySSA()->getBlockDefs(CurrentBB))
if (!isa<MemoryPhi>(*Defs->begin()) || (++Defs->begin() != Defs->end()))
return Changed;
if (llvm::any_of(*CurrentBB,
[](Instruction &I) { return I.mayHaveSideEffects(); }))
return Changed;
Expand Down

0 comments on commit 9321087

Please sign in to comment.