Skip to content

Commit 2697574

Browse files
committed
AMDGPU: Fix runtime unrolling when cascaded GEPs present
1 parent 4be3e95 commit 2697574

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,13 @@ void AMDGPUTTIImpl::getUnrollingPreferences(
216216
// a variable, most likely we will be unable to combine it.
217217
// Do not unroll too deep inner loops for local memory to give a chance
218218
// to unroll an outer loop for a more important reason.
219-
if (LocalGEPsSeen > 1 || L->getLoopDepth() > 2 ||
220-
(!isa<GlobalVariable>(GEP->getPointerOperand()) &&
221-
!isa<Argument>(GEP->getPointerOperand())))
219+
if (LocalGEPsSeen > 1 || L->getLoopDepth() > 2)
222220
continue;
221+
222+
const Value *V = getUnderlyingObject(GEP->getPointerOperand());
223+
if (!isa<GlobalVariable>(V) && !isa<Argument>(V))
224+
continue;
225+
223226
LLVM_DEBUG(dbgs() << "Allow unroll runtime for loop:\n"
224227
<< *L << " due to LDS use.\n");
225228
UP.Runtime = UnrollRuntimeLocal;
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; RUN: opt -mtriple=amdgcn-unknown-amdhsa -passes=loop-unroll -S %s | FileCheck %s
2+
3+
%struct.wombat = type { %struct.zot, i32, [16 x i32], [16 x i32], i32, i32, [16 x i32], i32 }
4+
%struct.zot = type { i32, i32, [1024 x i32] }
5+
6+
@global = external addrspace(3) global %struct.wombat
7+
8+
; Ensure that a cascaded GEP for local address space does not inhibit unrolling
9+
;
10+
; CHECK-LABEL: @unroll_when_cascaded_gep
11+
; CHECK: bb:
12+
; CHECK: br {{.*}}, label %bb2.unr-lcssa, label %bb.new
13+
; CHECK: bb.new:
14+
; CHECK: %unroll_iter =
15+
; CHECK: br label %bb1
16+
; CHECK: bb1:
17+
; CHECK: br {{.*}}, label %bb2.unr-lcssa.loopexit, label %bb1
18+
; CHECK: bb2.unr-lcssa.loopexit:
19+
; CHECK: br label %bb2.unr-lcssa
20+
; CHECK: bb2.unr-lcssa:
21+
; CHECK: br {{.*}}, label %bb1.epil.preheader, label %bb2
22+
; CHECK: bb1.epil.preheader:
23+
; CHECK: br label %bb1.epil
24+
; CHECK: bb1.epil:
25+
; CHECK: br {{.*}}, label %bb1.epil, label %bb2.epilog-lcssa
26+
; CHECK: bb2.epilog-lcssa:
27+
; CHECK: br label %bb2
28+
; CHECK: bb2:
29+
; CHECK: ret void
30+
define amdgpu_kernel void @unroll_when_cascaded_gep(i32 %arg) {
31+
bb:
32+
br label %bb1
33+
34+
bb1: ; preds = %bb1, %bb
35+
%phi = phi i32 [ 0, %bb ], [ %add, %bb1 ]
36+
%getelementptr = getelementptr [1024 x i32], ptr addrspace(3) getelementptr inbounds nuw (i8, ptr addrspace(3) @global, i32 8), i32 0, i32 0
37+
%add = add i32 %phi, 1
38+
%icmp = icmp eq i32 %phi, %arg
39+
br i1 %icmp, label %bb2, label %bb1
40+
41+
bb2: ; preds = %bb1
42+
ret void
43+
}
44+

0 commit comments

Comments
 (0)