Skip to content

Commit

Permalink
Merge pull request #1096 from reactorlabs/reportChanges
Browse files Browse the repository at this point in the history
better change tracking in constantfold and gvn
  • Loading branch information
o- authored Sep 6, 2021
2 parents b217283 + 97a3654 commit aee2f43
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions rir/src/compiler/opt/constantfold.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SEXP qt(SEXP c, Preserve& p) {
auto res = Rf_eval( \
p(Rf_lang3(Operation, qt(lhs, p), qt(rhs, p))), \
R_BaseEnv); \
anyChange = true; \
iterAnyChange = true; \
instr->replaceUsesWith(cmp.module->c(res)); \
next = bb->remove(ip); \
} \
Expand Down Expand Up @@ -154,9 +154,7 @@ static bool isStaticallyNA(Value* i) {
bool Constantfold::apply(Compiler& cmp, ClosureVersion* cls, Code* code,
LogStream& log, size_t iteration) const {
EarlyConstantfold cf;
cf.apply(cmp, cls, code, log, iteration);

bool anyChange = false;
bool anyChange = cf.apply(cmp, cls, code, log, iteration);

Preserve p;
std::unordered_map<BB*, bool> branchRemoval;
Expand Down Expand Up @@ -1056,6 +1054,7 @@ bool Constantfold::apply(Compiler& cmp, ClosureVersion* cls, Code* code,
}
for (auto bb : dead) {
assert(!reachable.count(bb));
anyChange = true;
delete bb;
}

Expand Down
8 changes: 4 additions & 4 deletions rir/src/compiler/opt/gvn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace pir {

bool GVN::apply(Compiler&, ClosureVersion* cls, Code* code, LogStream& log,
size_t) const {
bool changed = false;
std::unordered_map<size_t, SmallSet<Value*>> reverseNumber;
std::unordered_map<Value*, size_t> number;
{
Expand Down Expand Up @@ -213,6 +214,8 @@ bool GVN::apply(Compiler&, ClosureVersion* cls, Code* code, LogStream& log,
auto i = Instruction::Cast(*p);
p++;
if (i && i != firstInstr) {
if (i->bb() != firstInstr->bb())
changed = true;
if (!firstInstr->type.isA(i->type))
continue;
if (i->bb() == firstInstr->bb()) {
Expand Down Expand Up @@ -269,10 +272,7 @@ bool GVN::apply(Compiler&, ClosureVersion* cls, Code* code, LogStream& log,
// Sometimes a dead instruction will trip the verifier.
BBTransform::removeDeadInstrs(code, 1);

// The current implementation of GVN almost always finds something to
// change. We use the changed flag to determine when to stop optimizing and
// it is thus just too noisy.
return false;
return changed;
}

} // namespace pir
Expand Down

0 comments on commit aee2f43

Please sign in to comment.