summaryrefslogtreecommitdiff
path: root/src/passes/LoopInvariantCodeMotion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/passes/LoopInvariantCodeMotion.cpp')
-rw-r--r--src/passes/LoopInvariantCodeMotion.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/passes/LoopInvariantCodeMotion.cpp b/src/passes/LoopInvariantCodeMotion.cpp
index 26e2a0844..a80e3a55d 100644
--- a/src/passes/LoopInvariantCodeMotion.cpp
+++ b/src/passes/LoopInvariantCodeMotion.cpp
@@ -114,17 +114,20 @@ struct LoopInvariantCodeMotion
}
if (interestingToMove(curr)) {
// Let's see if we can move this out.
- // Global side effects would prevent this - we might end up
+ // Global state changes would prevent this - we might end up
// executing them just once.
// And we must also move across anything not moved out already,
// so check for issues there too.
// The rest of the loop's effects matter too, we must also
// take into account global state like interacting loads and
// stores.
- bool unsafeToMove = effects.hasGlobalSideEffects() ||
- effectsSoFar.invalidates(effects) ||
- (effects.noticesGlobalSideEffects() &&
- loopEffects.hasGlobalSideEffects());
+ bool unsafeToMove =
+ effects.writesGlobalState() || effectsSoFar.invalidates(effects) ||
+ (effects.readsGlobalState() && loopEffects.writesGlobalState());
+ // TODO: look into optimizing this with exceptions. for now, disallow
+ if (effects.throws || loopEffects.throws) {
+ unsafeToMove = true;
+ }
if (!unsafeToMove) {
// So far so good. Check if our local dependencies are all
// outside of the loop, in which case everything is good -