Handling PHIs in Uniformity Analysis

Is it possible for uniformity analysis to mark an instruction as uniform after it has already been identified as divergent?

In the above CFG, the terminator of Flow2 is identified as divergent and hence Flow2 is inserted into the DivergentTermBlocks set. However, upon a query of the branch instruction br i1 %8, label %if1, label %endloop is uniform or not, uniformity analysis returns true. That is, DivergentTermBlocks does not contain Flow2.

Having not looked at the code at all, I’d assume the analysis is supposed to flow in one direction and doesn’t go back to fixup mistakes

Or to put it differently, the analysis runs until it reaches a fixed point, and the set of divergent operations keeps increasing monotonically. It does not backtrack on operations that are identified as divergent.

What you are seeing could potentially be a bug. Can you please provide the IR for this graph?

llvm-project/llvm/test/CodeGen/AMDGPU/divergent-branch-uniform-condition.ll

When isUniform(..) runs to check whether br i1 %8, label %if1, label %endloop is uniform or not, UA returns true if its parent basic block Flow2 is in the DivergentTermBlocks set.