dberlin added a comment. See https://reviews.llvm.org/D8688#a1aa52c6 computeBarriers, for a way to compute the barriers once and be able to constant time check whether they are in the way. (since you have dfs numbers for the instructions) https://reviews.llvm.org/D29092