From 323bfde20c5f3e63db3d6b385b394ed38542abe6 Mon Sep 17 00:00:00 2001 From: Connor Abbott Date: Mon, 9 Dec 2019 12:04:00 +0100 Subject: [PATCH] AMDGPU: Fix AMDGPUUnifyDivergentExitNodes with no normal returns Summary: The code was assuming in a few places that if there was only one exit from the function that it was a normal return, which is invalid. It could be an infinite loop, in which case we still need to insert the usual fake edge so that the null export happens. This fixes shaders that end with an infinite loop that discards. Reviewers: arsenm, nhaehnle, critson Subscribers: kzhuravl, jvesely, wdng, yaxunl, dstuttard, tpr, t-tye, hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D71192 --- .../AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp | 4 +--- llvm/test/CodeGen/AMDGPU/kill-infinite-loop.ll | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp b/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp index 01bb60f07f2e..f7bd478d73e6 100644 --- a/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUUnifyDivergentExitNodes.cpp @@ -195,8 +195,6 @@ static BasicBlock *unifyReturnBlockSet(Function &F, bool AMDGPUUnifyDivergentExitNodes::runOnFunction(Function &F) { auto &PDT = getAnalysis().getPostDomTree(); - if (PDT.getRoots().size() <= 1) - return false; LegacyDivergenceAnalysis &DA = getAnalysis(); @@ -321,7 +319,7 @@ bool AMDGPUUnifyDivergentExitNodes::runOnFunction(Function &F) { if (ReturningBlocks.empty()) return false; // No blocks return - if (ReturningBlocks.size() == 1) + if (ReturningBlocks.size() == 1 && !InsertExport) return false; // Already has a single return block const TargetTransformInfo &TTI diff --git a/llvm/test/CodeGen/AMDGPU/kill-infinite-loop.ll b/llvm/test/CodeGen/AMDGPU/kill-infinite-loop.ll index 30280b967ad8..a2358f3a80f4 100644 --- a/llvm/test/CodeGen/AMDGPU/kill-infinite-loop.ll +++ b/llvm/test/CodeGen/AMDGPU/kill-infinite-loop.ll @@ -45,6 +45,22 @@ end: ret void } +; test the case where there's only a kill in an infinite loop +; CHECK-LABEL: only_kill +; CHECK: exp null off, off, off, off done vm +; CHECK-NEXT: s_endpgm +; SIInsertSkips inserts an extra null export here, but it should be harmless. +; CHECK: exp null off, off, off, off done vm +; CHECK-NEXT: s_endpgm +define amdgpu_ps void @only_kill() #0 { +main_body: + br label %loop + +loop: + call void @llvm.amdgcn.kill(i1 false) #3 + br label %loop +} + ; In case there's an epilog, we shouldn't have to do this. ; CHECK-LABEL: return_nonvoid ; CHECK-NOT: exp null off, off, off, off done vm