Skip to content

Commit aee2f43

Browse files
authored
Merge pull request #1096 from reactorlabs/reportChanges
better change tracking in constantfold and gvn
2 parents b217283 + 97a3654 commit aee2f43

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

rir/src/compiler/opt/constantfold.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ SEXP qt(SEXP c, Preserve& p) {
4646
auto res = Rf_eval( \
4747
p(Rf_lang3(Operation, qt(lhs, p), qt(rhs, p))), \
4848
R_BaseEnv); \
49-
anyChange = true; \
49+
iterAnyChange = true; \
5050
instr->replaceUsesWith(cmp.module->c(res)); \
5151
next = bb->remove(ip); \
5252
} \
@@ -154,9 +154,7 @@ static bool isStaticallyNA(Value* i) {
154154
bool Constantfold::apply(Compiler& cmp, ClosureVersion* cls, Code* code,
155155
LogStream& log, size_t iteration) const {
156156
EarlyConstantfold cf;
157-
cf.apply(cmp, cls, code, log, iteration);
158-
159-
bool anyChange = false;
157+
bool anyChange = cf.apply(cmp, cls, code, log, iteration);
160158

161159
Preserve p;
162160
std::unordered_map<BB*, bool> branchRemoval;
@@ -1056,6 +1054,7 @@ bool Constantfold::apply(Compiler& cmp, ClosureVersion* cls, Code* code,
10561054
}
10571055
for (auto bb : dead) {
10581056
assert(!reachable.count(bb));
1057+
anyChange = true;
10591058
delete bb;
10601059
}
10611060

rir/src/compiler/opt/gvn.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace pir {
1212

1313
bool GVN::apply(Compiler&, ClosureVersion* cls, Code* code, LogStream& log,
1414
size_t) const {
15+
bool changed = false;
1516
std::unordered_map<size_t, SmallSet<Value*>> reverseNumber;
1617
std::unordered_map<Value*, size_t> number;
1718
{
@@ -213,6 +214,8 @@ bool GVN::apply(Compiler&, ClosureVersion* cls, Code* code, LogStream& log,
213214
auto i = Instruction::Cast(*p);
214215
p++;
215216
if (i && i != firstInstr) {
217+
if (i->bb() != firstInstr->bb())
218+
changed = true;
216219
if (!firstInstr->type.isA(i->type))
217220
continue;
218221
if (i->bb() == firstInstr->bb()) {
@@ -269,10 +272,7 @@ bool GVN::apply(Compiler&, ClosureVersion* cls, Code* code, LogStream& log,
269272
// Sometimes a dead instruction will trip the verifier.
270273
BBTransform::removeDeadInstrs(code, 1);
271274

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

278278
} // namespace pir

0 commit comments

Comments
 (0)