Issue 150973
Summary [Machine uniformity Analysis] uniformity of a value inside and outside a loop
Labels new issue
Assignees
Reporter jgu222
    There are cases that a value inside a loop is uniform, but outside a loop, it is divergent.
For example,
```
;
; opt -mtriple amdgcn-unknown-amdhsa -passes='print<uniformity>' -disable-output phi_loop_issue.ll
;
define amdgpu_kernel void @test_ctrl_divergence() {
B0:
  %tid = call i32 @llvm.amdgcn.workitem.id.x()
  br label %B1

B1:
  %i = phi i32 [0, %B0], [%i_n, %B1]
  %div.cond = icmp slt i32 %tid, %i
  %i_n = add i32 %i, 1
  br i1 %div.cond, label %B1, label %B2

B2:
  %a = add i32 %i, 10
  ret void
}

declare i32 @llvm.amdgcn.workitem.id.x() #0

attributes #0 = {nounwind readnone }
```

The result from uniformity analysis:

```
UniformityInfo for function 'test_ctrl_divergence':
CYCLES WITH DIVERGENT EXIT:
  depth=1: entries(B1)

TEMPORAL DIVERGENCE LIST:
Value         :  %i = phi i32 [ 0, %B0 ], [ %i_n, %B1 ]
Used by       :  %a = add i32 %i, 10
Outside cycle :depth=1: entries(B1)


BLOCK B0
DEFINITIONS
  DIVERGENT:   %tid = call i32 @llvm.amdgcn.workitem.id.x()
TERMINATORS
               br label %B1
END BLOCK

BLOCK B1
DEFINITIONS
               %i = phi i32 [ 0, %B0 ], [ %i_n, %B1 ]
  DIVERGENT:   %div.cond = icmp slt i32 %tid, %i
 %i_n = add i32 %i, 1
TERMINATORS
  DIVERGENT:   br i1 %div.cond, label %B1, label %B2
END BLOCK

BLOCK B2
DEFINITIONS
  DIVERGENT:   %a = add i32 %i, 10
TERMINATORS
               ret void
END BLOCK

```
As the loop (B1) has a divergent condition, the %i would be divergent outside the loop as each lane would exit the loop with different %i.  But within the loop, %i is uniform.  As %i is the same both inside the loop and outside the loop, there is no way to represent uniformity for %i.

Traditionally, this is resolved by using LCSSA to separate a value inside a loop and one outside the loop. However, there is no Machine function pass LCSSA so far. 

The purpose of the issue is to invite the input to see what is a better solution to this issue, would it be better to port Function pass LCSSA into MachineFunction pass ?
  
   
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to