Skip to content

Commit a9f6e51

Browse files
Artem GindinsonAlexander Batashev
authored andcommitted
[SYCL][FPGA] Lift the restriction on LSU intrinsic operands
The initial implementation had required that the first ptr.annotation operand be a result of a load intruction. However, it may be the case that the LSU built-in gets applied to a cast result/to a result of a function call, therefore this patch drops the unfeasible requirement. Signed-off-by: Artem Gindinson <[email protected]>
1 parent b893057 commit a9f6e51

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

llvm-spirv/lib/SPIRV/SPIRVReader.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,12 +3194,10 @@ void generateIntelFPGAAnnotationForStructMember(
31943194
}
31953195

31963196
void SPIRVToLLVM::transIntelFPGADecorations(SPIRVValue *BV, Value *V) {
3197-
if (!BV->isVariable() && BV->getOpCode() != OpLoad &&
3198-
BV->getOpCode() != OpInBoundsPtrAccessChain)
3197+
if (!BV->isVariable() && !BV->isInst())
31993198
return;
32003199

3201-
if (isa<AllocaInst>(V) || isa<LoadInst>(V) || isa<GetElementPtrInst>(V)) {
3202-
auto *Inst = cast<Instruction>(V);
3200+
if (auto *Inst = dyn_cast<Instruction>(V)) {
32033201
auto *AL = dyn_cast<AllocaInst>(Inst);
32043202
Type *AllocatedTy = AL ? AL->getAllocatedType() : Inst->getType();
32053203

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,17 +2227,16 @@ SPIRVValue *LLVMToSPIRV::transIntrinsicInst(IntrinsicInst *II,
22272227
return transValue(BI, BB);
22282228
} else {
22292229
// Memory accesses to a standalone pointer variable
2230-
auto *LI = dyn_cast<LoadInst>(AnnotSubj);
2231-
auto *LoadResPtr = transValue(LI, BB);
2230+
auto *DecSubj = transValue(II->getArgOperand(0), BB);
22322231
if (Decorations.MemoryAccessesVec.empty())
2233-
LoadResPtr->addDecorate(new SPIRVDecorateUserSemanticAttr(
2234-
LoadResPtr, AnnotationString.str()));
2232+
DecSubj->addDecorate(new SPIRVDecorateUserSemanticAttr(
2233+
DecSubj, AnnotationString.str()));
22352234
else
2236-
// Apply the LSU parameter decoration to the pointer result of a load
2235+
// Apply the LSU parameter decoration to the pointer result of an
22372236
// instruction. Note it's the address to the accessed memory that's
22382237
// loaded from the original pointer variable, and not the value
22392238
// accessed by the latter.
2240-
addIntelFPGADecorations(LoadResPtr, Decorations.MemoryAccessesVec);
2239+
addIntelFPGADecorations(DecSubj, Decorations.MemoryAccessesVec);
22412240
II->replaceAllUsesWith(II->getOperand(0));
22422241
}
22432242
}

llvm-spirv/test/transcoding/IntelFPGAMemoryAccesses.ll

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414
; float *x;
1515
; int *y;
1616
; State *z;
17+
; double *t;
1718
; x = __builtin_intel_fpga_mem(A, BURST_COAL | CACHE_SIZE_FLAG, 0);
1819
; y = __builtin_intel_fpga_mem(B, DONT_STATICALLY_COAL | PREFETCH, 0);
1920
; z = __builtin_intel_fpga_mem(C, CACHE_SIZE_FLAG, 127);
2021
; x = __builtin_intel_fpga_mem(&C->Field1, BURST_COAL | CACHE_SIZE_FLAG, 127);
2122
; y = __builtin_intel_fpga_mem(&C->Field2, 0, 127);
2223
; z = __builtin_intel_fpga_mem(C, BURST_COAL | CACHE_SIZE_FLAG | DONT_STATICALLY_COAL | PREFETCH, 127);
24+
; t = __builtin_intel_fpga_mem((double *) A, BURST_COAL | CACHE_SIZE_FLAG, 0);
2325
; }
2426
;
2527
; template <typename name, typename Func>
@@ -47,13 +49,13 @@
4749
; CHECK-SPIRV: Capability FPGAMemoryAccessesINTEL
4850
; CHECK-SPIRV: Extension "SPV_INTEL_fpga_memory_accesses"
4951
; CHECK-SPIRV: Decorate {{[0-9]+}} BurstCoalesceINTEL
52+
; CHECK-SPIRV: Decorate {{[0-9]+}} CacheSizeINTEL 0
5053
; CHECK-SPIRV: Decorate {{[0-9]+}} CacheSizeINTEL 127
5154
; CHECK-SPIRV: Decorate {{[0-9]+}} DontStaticallyCoalesceINTEL
5255
; CHECK-SPIRV: Decorate {{[0-9]+}} PrefetchINTEL 0
5356
; Check that the semantically meaningless decoration was
5457
; translated as a mere annotation
5558
; CHECK-SPIRV: Decorate {{[0-9]+}} UserSemantic "{params:0}{cache-size:127}"
56-
; CHECK-SPIRV: Decorate {{[0-9]+}} CacheSizeINTEL 0
5759

5860
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
5961
target triple = "spir64-unknown-unknown-sycldevice"
@@ -77,6 +79,8 @@ target triple = "spir64-unknown-unknown-sycldevice"
7779
@.str.5 = private unnamed_addr constant [27 x i8] c"{params:0}{cache-size:127}\00", section "llvm.metadata"
7880
; CHECK-LLVM: [[PARAM_15_CACHE_127:@[a-z0-9_.]+]] = {{.*}}{params:15}{cache-size:127}
7981
@.str.6 = private unnamed_addr constant [28 x i8] c"{params:15}{cache-size:127}\00", section "llvm.metadata"
82+
; TODO: Investigate why the same global annotation string shows up twice in backwards translation.
83+
; CHECK-LLVM: [[PARAM_3_CACHE_0_DOUBLE:@[a-z0-9_.]+]] = {{.*}}{params:3}{cache-size:0}
8084

8185
; Function Attrs: norecurse nounwind
8286
define spir_kernel void @_ZTSZ4mainE11fake_kernel() #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !4 !kernel_arg_type !4 !kernel_arg_base_type !4 !kernel_arg_type_qual !4 {
@@ -137,9 +141,11 @@ entry:
137141
; CHECK-LLVM: %[[FLOAT_VAR:[[:alnum:].]+]] = alloca float addrspace(4)*, align 8
138142
; CHECK-LLVM: %[[INT_VAR:[[:alnum:].]+]] = alloca i32 addrspace(4)*, align 8
139143
; CHECK-LLVM: %[[STRUCT_VAR:[[:alnum:].]+]] = alloca %struct{{.*}}State addrspace(4)*, align 8
144+
; CHECK-LLVM: %[[DOUBLE_VAR:[[:alnum:].]+]] = alloca double addrspace(4)*, align 8
140145
%x = alloca float addrspace(4)*, align 8
141146
%y = alloca i32 addrspace(4)*, align 8
142147
%z = alloca %struct._ZTS5State.State addrspace(4)*, align 8
148+
%t = alloca double addrspace(4)*, align 8
143149
store float addrspace(4)* %A, float addrspace(4)** %A.addr, align 8, !tbaa !5
144150
store i32 addrspace(4)* %B, i32 addrspace(4)** %B.addr, align 8, !tbaa !5
145151
store %struct._ZTS5State.State addrspace(4)* %C, %struct._ZTS5State.State addrspace(4)** %C.addr, align 8, !tbaa !5
@@ -190,12 +196,24 @@ entry:
190196
%13 = load %struct._ZTS5State.State addrspace(4)*, %struct._ZTS5State.State addrspace(4)** %C.addr, align 8, !tbaa !5
191197
%14 = call %struct._ZTS5State.State addrspace(4)* @llvm.ptr.annotation.p4s_struct._ZTS5State.States(%struct._ZTS5State.State addrspace(4)* %13, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i32 0, i32 0), i32 0) #6
192198
store %struct._ZTS5State.State addrspace(4)* %14, %struct._ZTS5State.State addrspace(4)** %z, align 8, !tbaa !5
193-
%15 = bitcast %struct._ZTS5State.State addrspace(4)** %z to i8*
194-
call void @llvm.lifetime.end.p0i8(i64 8, i8* %15) #5
195-
%16 = bitcast i32 addrspace(4)** %y to i8*
196-
call void @llvm.lifetime.end.p0i8(i64 8, i8* %16) #5
197-
%17 = bitcast float addrspace(4)** %x to i8*
198-
call void @llvm.lifetime.end.p0i8(i64 8, i8* %17) #5
199+
%15 = bitcast double addrspace(4)** %t to i8*
200+
call void @llvm.lifetime.start.p0i8(i64 8, i8* %15) #5
201+
; CHECK-LLVM: %[[FLOAT_FUNC_PARAM_LOAD:[[:alnum:].]+]] = load float addrspace(4)*, float addrspace(4)** %[[FLOAT_FUNC_PARAM]]
202+
; CHECK-LLVM: %[[BITCAST_FLOAT_TO_DOUBLE:[[:alnum:].]+]] = bitcast float addrspace(4)* %[[FLOAT_FUNC_PARAM_LOAD]] to double addrspace(4)*
203+
; CHECK-LLVM: %[[INTRINSIC_CALL:[[:alnum:].]+]] = call double addrspace(4)* @llvm.ptr.annotation.p4f64(double addrspace(4)* %[[BITCAST_FLOAT_TO_DOUBLE]], i8* getelementptr inbounds ({{.*}} [[PARAM_3_CACHE_0_DOUBLE]]
204+
; CHECK-LLVM: store double addrspace(4)* %[[INTRINSIC_CALL]], double addrspace(4)** %[[DOUBLE_VAR]]
205+
%16 = load float addrspace(4)*, float addrspace(4)** %A.addr, align 8, !tbaa !5
206+
%17 = bitcast float addrspace(4)* %16 to double addrspace(4)*
207+
%18 = call double addrspace(4)* @llvm.ptr.annotation.p4f64(double addrspace(4)* %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i32 0, i32 0), i32 0) #6
208+
store double addrspace(4)* %18, double addrspace(4)** %t, align 8, !tbaa !5
209+
%19 = bitcast double addrspace(4)** %t to i8*
210+
call void @llvm.lifetime.end.p0i8(i64 8, i8* %19) #5
211+
%20 = bitcast %struct._ZTS5State.State addrspace(4)** %z to i8*
212+
call void @llvm.lifetime.end.p0i8(i64 8, i8* %20) #5
213+
%21 = bitcast i32 addrspace(4)** %y to i8*
214+
call void @llvm.lifetime.end.p0i8(i64 8, i8* %21) #5
215+
%22 = bitcast float addrspace(4)** %x to i8*
216+
call void @llvm.lifetime.end.p0i8(i64 8, i8* %22) #5
199217
ret void
200218
}
201219

@@ -208,6 +226,9 @@ declare i32 addrspace(4)* @llvm.ptr.annotation.p4i32(i32 addrspace(4)*, i8*, i8*
208226
; Function Attrs: nounwind willreturn
209227
declare %struct._ZTS5State.State addrspace(4)* @llvm.ptr.annotation.p4s_struct._ZTS5State.States(%struct._ZTS5State.State addrspace(4)*, i8*, i8*, i32) #4
210228

229+
; Function Attrs: nounwind willreturn
230+
declare double addrspace(4)* @llvm.ptr.annotation.p4f64(double addrspace(4)*, i8*, i8*, i32) #4
231+
211232
attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "sycl-module-id"="/tmp/lsu.cpp" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
212233
attributes #1 = { argmemonly nounwind willreturn }
213234
attributes #2 = { inlinehint norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }

0 commit comments

Comments
 (0)