Skip to content

Commit 4b946ba

Browse files
authored
[NFC-for-now] Fix LocalCSE bug in ignoring traps (#8385)
The code did "trap = false; scan()", but that is wrong, as it wants to remove the trap after the scan. Reorder and just use a ShallowEffectAnalyzer. But this logic bug was not actually allowing different behavior, see the detailed comment - we have no effects atm that can distinguish the two cases. If we add new effects, we might, though, so this is worth doing.
1 parent 146905f commit 4b946ba

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src/passes/LocalCSE.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ struct Checker
465465
// Given the current expression, see what it invalidates of the currently-
466466
// hashed expressions, if there are any.
467467
if (!activeOriginals.empty()) {
468-
EffectAnalyzer effects(options, *getModule());
468+
// We only need to visit this node itself, as we have already visited its
469+
// children by the time we get here.
470+
ShallowEffectAnalyzer effects(options, *getModule(), curr);
469471
// We can ignore traps here:
470472
//
471473
// (ORIGINAL)
@@ -475,10 +477,15 @@ struct Checker
475477
// We are some code in between an original and a copy of it, and we are
476478
// trying to turn COPY into a local.get of a value that we stash at the
477479
// original. If |curr| traps then we simply don't reach the copy anyhow.
480+
//
481+
// Note, however, that this is really for future use, as atm this does not
482+
// help: the only effect a trap can interact with is a set of global state
483+
// (the trap could prevent that writing, which would be noticeable) - but
484+
// LocalCSE does not deduplicate expressions with such effects, as they
485+
// must happen twice. That is, removing trapping from (curr) in the
486+
// example above has no effect as (ORIGINAL) never has global write
487+
// effects.
478488
effects.trap = false;
479-
// We only need to visit this node itself, as we have already visited its
480-
// children by the time we get here.
481-
effects.visit(curr);
482489

483490
auto idempotent = isIdempotent(curr, *getModule());
484491

0 commit comments

Comments
 (0)