[polly] r311042 - [GPGPU] Also record invariant loads as kernel subtree values
Tobias Grosser via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 16 14:37:53 PDT 2017
Author: grosser
Date: Wed Aug 16 14:37:53 2017
New Revision: 311042
URL: http://llvm.org/viewvc/llvm-project?rev=311042&view=rev
Log:
[GPGPU] Also record invariant loads as kernel subtree values
Before this change kernels that used invariant loads would have resulted in
invalid PTX code.
Added:
polly/trunk/test/GPGPU/invariant-load-hoisting-read-in-kernel.ll
Modified:
polly/trunk/lib/CodeGen/IslNodeBuilder.cpp
Modified: polly/trunk/lib/CodeGen/IslNodeBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslNodeBuilder.cpp?rev=311042&r1=311041&r2=311042&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslNodeBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslNodeBuilder.cpp Wed Aug 16 14:37:53 2017
@@ -196,8 +196,13 @@ int IslNodeBuilder::getNumberOfIteration
/// Extract the values and SCEVs needed to generate code for a block.
static int findReferencesInBlock(struct SubtreeReferences &References,
- const ScopStmt *Stmt, const BasicBlock *BB) {
- for (const Instruction &Inst : *BB)
+ const ScopStmt *Stmt, BasicBlock *BB) {
+ for (Instruction &Inst : *BB) {
+ // Include invariant loads
+ if (isa<LoadInst>(Inst))
+ if (Value *InvariantLoad = References.GlobalMap.lookup(&Inst))
+ References.Values.insert(InvariantLoad);
+
for (Value *SrcVal : Inst.operands()) {
auto *Scope = References.LI.getLoopFor(BB);
if (canSynthesize(SrcVal, References.S, &References.SE, Scope)) {
@@ -206,6 +211,7 @@ static int findReferencesInBlock(struct
} else if (Value *NewVal = References.GlobalMap.lookup(SrcVal))
References.Values.insert(NewVal);
}
+ }
return 0;
}
@@ -218,7 +224,7 @@ isl_stat addReferencesFromStmt(const Sco
else {
assert(Stmt->isRegionStmt() &&
"Stmt was neither block nor region statement");
- for (const BasicBlock *BB : Stmt->getRegion()->blocks())
+ for (BasicBlock *BB : Stmt->getRegion()->blocks())
findReferencesInBlock(References, Stmt, BB);
}
Added: polly/trunk/test/GPGPU/invariant-load-hoisting-read-in-kernel.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/GPGPU/invariant-load-hoisting-read-in-kernel.ll?rev=311042&view=auto
==============================================================================
--- polly/trunk/test/GPGPU/invariant-load-hoisting-read-in-kernel.ll (added)
+++ polly/trunk/test/GPGPU/invariant-load-hoisting-read-in-kernel.ll Wed Aug 16 14:37:53 2017
@@ -0,0 +1,35 @@
+; RUN: opt %loadPolly -disable-output -polly-acc-dump-kernel-ir \
+; RUN: -polly-codegen-ppcg -polly-scops \
+; RUN: -polly-invariant-load-hoisting < %s | FileCheck %s
+
+; Verify that invariant loads used in a kernel statement are correctly forwarded
+; as subtree value to the GPU kernel.
+
+; CHECK: define ptx_kernel void @FUNC_foo_SCOP_0_KERNEL_0({{.*}} float %polly.access.p.load)
+; CHECK: store float %polly.access.p.load, float* %indvar2f.phiops
+
+define void @foo(float* %A, float* %p) {
+entry:
+ br label %loop
+
+loop:
+ %indvar = phi i64 [0, %entry], [%indvar.next, %loop]
+ %indvar.next = add i64 %indvar, 1
+ %invariant = load float, float* %p
+ %ptr = getelementptr float, float* %A, i64 %indvar
+ store float 42.0, float* %ptr
+ %cmp = icmp sle i64 %indvar, 1024
+ br i1 %cmp, label %loop, label %loop2
+
+loop2:
+ %indvar2 = phi i64 [0, %loop], [%indvar2.next, %loop2]
+ %indvar2f = phi float [%invariant, %loop], [%indvar2f, %loop2]
+ %indvar2.next = add i64 %indvar2, 1
+ store float %indvar2f, float* %A
+ %cmp2 = icmp sle i64 %indvar2, 1024
+ br i1 %cmp2, label %loop2, label %end
+
+end:
+ ret void
+
+}
More information about the llvm-commits
mailing list