-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DA] GPUDivergenceAnalysis for unstructured GPU kernels
Summary: This is patch #3 of the new DivergenceAnalysis <https://lists.llvm.org/pipermail/llvm-dev/2018-May/123606.html> The GPUDivergenceAnalysis is intended to eventually supersede the existing LegacyDivergenceAnalysis. The existing LegacyDivergenceAnalysis produces incorrect results on unstructured Control-Flow Graphs: <https://bugs.llvm.org/show_bug.cgi?id=37185> This patch adds the option -use-gpu-divergence-analysis to the LegacyDivergenceAnalysis to turn it into a transparent wrapper for the GPUDivergenceAnalysis. Reviewers: nhaehnle Reviewed By: nhaehnle Subscribers: jholewinski, jvesely, jfb, llvm-commits, alex-t, sameerds, arsenm, nhaehnle Differential Revision: https://reviews.llvm.org/D53493 llvm-svn: 348048
- Loading branch information
Showing
23 changed files
with
1,359 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
llvm/test/Analysis/DivergenceAnalysis/AMDGPU/always_uniform.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
; RUN: opt -mtriple amdgcn-unknown-amdhsa -analyze -divergence -use-gpu-divergence-analysis %s | FileCheck %s | ||
|
||
define amdgpu_kernel void @workitem_id_x() #1 { | ||
%id.x = call i32 @llvm.amdgcn.workitem.id.x() | ||
; CHECK: DIVERGENT: %id.x = call i32 @llvm.amdgcn.workitem.id.x() | ||
%first.lane = call i32 @llvm.amdgcn.readfirstlane(i32 %id.x) | ||
; CHECK-NOT: DIVERGENT: %first.lane = call i32 @llvm.amdgcn.readfirstlane(i32 %id.x) | ||
ret void | ||
} | ||
|
||
declare i32 @llvm.amdgcn.workitem.id.x() #0 | ||
declare i32 @llvm.amdgcn.readfirstlane(i32) #0 | ||
|
||
attributes #0 = { nounwind readnone } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
; RUN: opt -mtriple=amdgcn-- -analyze -divergence -use-gpu-divergence-analysis %s | FileCheck %s | ||
|
||
; CHECK: DIVERGENT: %orig = atomicrmw xchg i32* %ptr, i32 %val seq_cst | ||
define i32 @test1(i32* %ptr, i32 %val) #0 { | ||
%orig = atomicrmw xchg i32* %ptr, i32 %val seq_cst | ||
ret i32 %orig | ||
} | ||
|
||
; CHECK: DIVERGENT: %orig = cmpxchg i32* %ptr, i32 %cmp, i32 %new seq_cst seq_cst | ||
define {i32, i1} @test2(i32* %ptr, i32 %cmp, i32 %new) { | ||
%orig = cmpxchg i32* %ptr, i32 %cmp, i32 %new seq_cst seq_cst | ||
ret {i32, i1} %orig | ||
} | ||
|
||
; CHECK: DIVERGENT: %ret = call i32 @llvm.amdgcn.atomic.inc.i32.p1i32(i32 addrspace(1)* %ptr, i32 %val, i32 0, i32 0, i1 false) | ||
define i32 @test_atomic_inc_i32(i32 addrspace(1)* %ptr, i32 %val) #0 { | ||
%ret = call i32 @llvm.amdgcn.atomic.inc.i32.p1i32(i32 addrspace(1)* %ptr, i32 %val, i32 0, i32 0, i1 false) | ||
ret i32 %ret | ||
} | ||
|
||
; CHECK: DIVERGENT: %ret = call i64 @llvm.amdgcn.atomic.inc.i64.p1i64(i64 addrspace(1)* %ptr, i64 %val, i32 0, i32 0, i1 false) | ||
define i64 @test_atomic_inc_i64(i64 addrspace(1)* %ptr, i64 %val) #0 { | ||
%ret = call i64 @llvm.amdgcn.atomic.inc.i64.p1i64(i64 addrspace(1)* %ptr, i64 %val, i32 0, i32 0, i1 false) | ||
ret i64 %ret | ||
} | ||
|
||
; CHECK: DIVERGENT: %ret = call i32 @llvm.amdgcn.atomic.dec.i32.p1i32(i32 addrspace(1)* %ptr, i32 %val, i32 0, i32 0, i1 false) | ||
define i32 @test_atomic_dec_i32(i32 addrspace(1)* %ptr, i32 %val) #0 { | ||
%ret = call i32 @llvm.amdgcn.atomic.dec.i32.p1i32(i32 addrspace(1)* %ptr, i32 %val, i32 0, i32 0, i1 false) | ||
ret i32 %ret | ||
} | ||
|
||
; CHECK: DIVERGENT: %ret = call i64 @llvm.amdgcn.atomic.dec.i64.p1i64(i64 addrspace(1)* %ptr, i64 %val, i32 0, i32 0, i1 false) | ||
define i64 @test_atomic_dec_i64(i64 addrspace(1)* %ptr, i64 %val) #0 { | ||
%ret = call i64 @llvm.amdgcn.atomic.dec.i64.p1i64(i64 addrspace(1)* %ptr, i64 %val, i32 0, i32 0, i1 false) | ||
ret i64 %ret | ||
} | ||
|
||
declare i32 @llvm.amdgcn.atomic.inc.i32.p1i32(i32 addrspace(1)* nocapture, i32, i32, i32, i1) #1 | ||
declare i64 @llvm.amdgcn.atomic.inc.i64.p1i64(i64 addrspace(1)* nocapture, i64, i32, i32, i1) #1 | ||
declare i32 @llvm.amdgcn.atomic.dec.i32.p1i32(i32 addrspace(1)* nocapture, i32, i32, i32, i1) #1 | ||
declare i64 @llvm.amdgcn.atomic.dec.i64.p1i64(i64 addrspace(1)* nocapture, i64, i32, i32, i1) #1 | ||
|
||
attributes #0 = { nounwind } | ||
attributes #1 = { nounwind argmemonly } |
26 changes: 26 additions & 0 deletions
26
llvm/test/Analysis/DivergenceAnalysis/AMDGPU/hidden_diverge.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
; RUN: opt -mtriple amdgcn-unknown-amdhsa -analyze -divergence -use-gpu-divergence-analysis %s | FileCheck %s | ||
|
||
define amdgpu_kernel void @hidden_diverge(i32 %n, i32 %a, i32 %b) #0 { | ||
; CHECK-LABEL: Printing analysis 'Legacy Divergence Analysis' for function 'hidden_diverge' | ||
entry: | ||
%tid = call i32 @llvm.amdgcn.workitem.id.x() | ||
%cond.var = icmp slt i32 %tid, 0 | ||
br i1 %cond.var, label %B, label %C ; divergent | ||
; CHECK: DIVERGENT: br i1 %cond.var, | ||
B: | ||
%cond.uni = icmp slt i32 %n, 0 | ||
br i1 %cond.uni, label %C, label %merge ; uniform | ||
; CHECK-NOT: DIVERGENT: br i1 %cond.uni, | ||
C: | ||
%phi.var.hidden = phi i32 [ 1, %entry ], [ 2, %B ] | ||
; CHECK: DIVERGENT: %phi.var.hidden = phi i32 | ||
br label %merge | ||
merge: | ||
%phi.ipd = phi i32 [ %a, %B ], [ %b, %C ] | ||
; CHECK: DIVERGENT: %phi.ipd = phi i32 | ||
ret void | ||
} | ||
|
||
declare i32 @llvm.amdgcn.workitem.id.x() #0 | ||
|
||
attributes #0 = { nounwind readnone } |
Oops, something went wrong.