Skip to content

Commit d14cf34

Browse files
committed
C++: data flow AlwaysTrueUponEntryLoop perf fix
The predicate `AlwaysTrueUponEntryLoop.getARelevantVariable` was very sensitive to join ordering, and with the 1.19 QL engine it got an unfortunate join order that made it explode on certain snapshots. With this change, it goes from taking minutes to taking less than a second on a libretro-uae snapshot.
1 parent 608d84c commit d14cf34

File tree

1 file changed

+10
-4
lines changed
  • cpp/ql/src/semmle/code/cpp/dataflow/internal

1 file changed

+10
-4
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/FlowVar.qll

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,17 +292,23 @@ module FlowVar_internal {
292292
* Gets a variable that is assigned in this loop and read outside the loop.
293293
*/
294294
private Variable getARelevantVariable() {
295-
exists(BasicBlock bbAssign |
296-
assignmentLikeOperation(bbAssign.getANode(), result, _) and
297-
this.bbInLoop(bbAssign)
298-
) and
295+
result = this.getAVariableAssignedInLoop() and
299296
exists(VariableAccess va |
300297
va.getTarget() = result and
301298
readAccess(va) and
302299
bbNotInLoop(va.getBasicBlock())
303300
)
304301
}
305302

303+
/** Gets a variable that is assigned in this loop. */
304+
pragma[noinline]
305+
private Variable getAVariableAssignedInLoop() {
306+
exists(BasicBlock bbAssign |
307+
assignmentLikeOperation(bbAssign.getANode(), result, _) and
308+
this.bbInLoop(bbAssign)
309+
)
310+
}
311+
306312
private predicate bbInLoopCondition(BasicBlock bb) {
307313
getCFNParent*(bb.getANode()) = this.(Loop).getCondition()
308314
}

0 commit comments

Comments
 (0)