Skip to content

Commit 5bb5c34

Browse files
MrSidimsvmaksimo
authored andcommitted
Add load to obtain input for ap/hls instructions in case if its type > 64bits (#1246)
In the LLVM IR if input is an integer with a width more than 64 bits the function will take this input through 'byval' pointer. If we leave the translation as is it will violate the extension spec, which says, that the input must by of an integer type. Add an extra load to fix this. Signed-off-by: Dmitry Sidorov [email protected] Original commit: KhronosGroup/SPIRV-LLVM-Translator@4f3641e
1 parent 4365160 commit 5bb5c34

File tree

3 files changed

+106
-6
lines changed

3 files changed

+106
-6
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4172,8 +4172,11 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
41724172
OpItr++;
41734173
}
41744174

4175-
SPIRVValue *Input =
4176-
transValue(*OpItr++ /* A - integer input of any width */, BB);
4175+
// Input - integer input of any width or 'byval' pointer to this integer
4176+
SPIRVValue *Input = transValue(*OpItr, BB);
4177+
if (OpItr->getType()->isPointerTy())
4178+
Input = BM->addLoadInst(Input, {}, BB);
4179+
OpItr++;
41774180

41784181
std::vector<SPIRVWord> Literals;
41794182
std::transform(OpItr, OpEnd, std::back_inserter(Literals), [](auto *O) {
@@ -4260,14 +4263,18 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
42604263
OpItr++;
42614264
}
42624265

4263-
SPIRVValue *InA = transValue(*OpItr++ /* A - input */, BB);
4266+
// Input - integer input of any width or 'byval' pointer to this integer
4267+
SPIRVValue *Input = transValue(*OpItr, BB);
4268+
if (OpItr->getType()->isPointerTy())
4269+
Input = BM->addLoadInst(Input, {}, BB);
4270+
OpItr++;
42644271

42654272
std::vector<SPIRVWord> Literals;
42664273
std::transform(OpItr, OpEnd, std::back_inserter(Literals), [](auto *O) {
42674274
return cast<llvm::ConstantInt>(O)->getZExtValue();
42684275
});
42694276

4270-
auto *APIntInst = BM->addArbFloatPointIntelInst(OC, transType(ResTy), InA,
4277+
auto *APIntInst = BM->addArbFloatPointIntelInst(OC, transType(ResTy), Input,
42714278
nullptr, Literals, BB);
42724279
if (!CI->hasStructRetAttr())
42734280
return APIntInst;
@@ -4332,12 +4339,22 @@ LLVMToSPIRVBase::transBuiltinToInstWithoutDecoration(Op OC, CallInst *CI,
43324339
OpItr++;
43334340
}
43344341

4335-
SPIRVValue *InA = transValue(*OpItr++ /* A - input */, BB);
4342+
// InA - integer input of any width or 'byval' pointer to this integer
4343+
SPIRVValue *InA = transValue(*OpItr, BB);
4344+
if (OpItr->getType()->isPointerTy())
4345+
InA = BM->addLoadInst(InA, {}, BB);
4346+
OpItr++;
43364347

43374348
std::vector<SPIRVWord> Literals;
43384349
Literals.push_back(cast<llvm::ConstantInt>(*OpItr++)->getZExtValue());
43394350

4340-
SPIRVValue *InB = transValue(*OpItr++ /* B - input */, BB);
4351+
// InB - integer input of any width or 'byval' pointer to this integer
4352+
SPIRVValue *InB = transValue(*OpItr, BB);
4353+
if (OpItr->getType()->isPointerTy()) {
4354+
std::vector<SPIRVWord> Mem;
4355+
InB = BM->addLoadInst(InB, Mem, BB);
4356+
}
4357+
OpItr++;
43414358

43424359
std::transform(OpItr, OpEnd, std::back_inserter(Literals), [](auto *O) {
43434360
return cast<llvm::ConstantInt>(O)->getZExtValue();

llvm-spirv/test/transcoding/capability-arbitrary-precision-fixed-point-numbers.ll

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
; sin_cos_pi<13, 5, false, 2, 2>();
8888
; log<64, 44, true, 24, 22>();
8989
; exp<44, 34, false, 20, 20>();
90+
; exp<68, 68, false, 20, 20>();
9091
; });
9192
; return 0;
9293
; }
@@ -125,6 +126,7 @@
125126
; CHECK-SPIRV: 4 TypeInt [[Ty_44:[0-9]+]] 44 0
126127
; CHECK-SPIRV: 4 TypeInt [[Ty_34:[0-9]+]] 34 0
127128
; CHECK-SPIRV: 4 TypeInt [[Ty_66:[0-9]+]] 66 0
129+
; CHECK-SPIRV: 4 TypeInt [[Ty_68:[0-9]+]] 68 0
128130

129131
; CHECK-SPIRV: 6 Load [[Ty_13]] [[Sqrt_InId:[0-9]+]]
130132
; CHECK-SPIRV-NEXT: 9 FixedSqrtINTEL [[Ty_5]] [[#]] [[Sqrt_InId]] 0 2 2 0 0
@@ -167,6 +169,11 @@
167169
; CHECK-SPIRV-NEXT: 9 FixedSinCosINTEL [[Ty_66]] [[SinCos_ResultId:[0-9]+]] [[SinCos_InId]] 1 3 2 0 0
168170
; CHECK-SPIRV: 3 Store [[#]] [[SinCos_ResultId]]
169171

172+
; CHECK-SPIRV: 6 Load [[Ty_68]] [[ResId:[0-9]+]]
173+
; CHECK-SPIRV-NEXT: 5 Store [[PtrId:[0-9]+]] [[ResId]]
174+
; CHECK-SPIRV-NEXT: 4 Load [[Ty_68]] [[ExpInId2:[0-9]+]] [[PtrId]]
175+
; CHECK-SPIRV-NEXT: 9 FixedExpINTEL [[Ty_68]] [[#]] [[ExpInId2]] 0 20 20 0 0
176+
170177
; CHECK-LLVM: call i5 @intel_arbitrary_fixed_sqrt.i5.i13(i13 %[[#]], i1 false, i32 2, i32 2, i32 0, i32 0)
171178
; CHECK-LLVM: call i13 @intel_arbitrary_fixed_sqrt.i13.i5(i5 %[[#]], i1 false, i32 2, i32 2, i32 0, i32 0)
172179
; CHECK-LLVM: call i13 @intel_arbitrary_fixed_sqrt.i13.i5(i5 %[[#]], i1 false, i32 2, i32 2, i32 0, i32 0)
@@ -181,6 +188,7 @@
181188
; CHECK-LLVM: call i44 @intel_arbitrary_fixed_log.i44.i64(i64 %[[#]], i1 true, i32 24, i32 22, i32 0, i32 0)
182189
; CHECK-LLVM: call i34 @intel_arbitrary_fixed_exp.i34.i44(i44 %[[#]], i1 false, i32 20, i32 20, i32 0, i32 0)
183190
; CHECK-LLVM: call i66 @intel_arbitrary_fixed_sincos.i66.i34(i34 %[[#]], i1 true, i32 3, i32 2, i32 0, i32 0)
191+
; CHECK-LLVM: call i68 @intel_arbitrary_fixed_exp.i68.i68(i68 %[[#]], i1 false, i32 20, i32 20, i32 0, i32 0)
184192

185193
; ModuleID = 'ap_fixed.cpp'
186194
source_filename = "ap_fixed.cpp"
@@ -213,6 +221,8 @@ $_Z3expILi44ELi34ELb0ELi20ELi20EEvv = comdat any
213221

214222
$_Z7sin_cosILi31ELi20ELb1ELi10ELi12EEvv_ = comdat any
215223

224+
$_Z3expILi68ELi68ELb0ELi20ELi20EEvv = comdat any
225+
216226
; Function Attrs: norecurse
217227
define dso_local spir_kernel void @_ZTSZ4mainE15kernel_function() #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 {
218228
entry:
@@ -246,6 +256,7 @@ entry:
246256
call spir_func void @_Z3logILi64ELi44ELb1ELi24ELi22EEvv()
247257
call spir_func void @_Z3expILi44ELi34ELb0ELi20ELi20EEvv()
248258
call spir_func void @_Z7sin_cosILi31ELi20ELb1ELi10ELi12EEvv_()
259+
call spir_func void @_Z3expILi68ELi68ELb0ELi20ELi20EEvv()
249260
ret void
250261
}
251262

@@ -507,6 +518,33 @@ entry:
507518
ret void
508519
}
509520

521+
; Function Attrs: norecurse nounwind
522+
define linkonce_odr dso_local spir_func void @_Z3expILi68ELi68ELb0ELi20ELi20EEvv() #3 comdat {
523+
entry:
524+
%a = alloca i68, align 8
525+
%a.ascast = addrspacecast i68* %a to i68 addrspace(4)*
526+
%ap_fixed_Exp = alloca i68, align 8
527+
%ap_fixed_Exp.ascast = addrspacecast i68* %ap_fixed_Exp to i68 addrspace(4)*
528+
%tmp = alloca i68, align 8
529+
%tmp.ascast = addrspacecast i68* %tmp to i68 addrspace(4)*
530+
%indirect-arg-temp = alloca i68, align 8
531+
%0 = bitcast i68* %a to i8*
532+
call void @llvm.lifetime.start.p0i8(i64 16, i8* %0)
533+
%1 = bitcast i68* %ap_fixed_Exp to i8*
534+
call void @llvm.lifetime.start.p0i8(i64 16, i8* %1)
535+
%2 = load i68, i68 addrspace(4)* %a.ascast, align 8
536+
store i68 %2, i68* %indirect-arg-temp, align 8
537+
call spir_func void @_Z21__spirv_FixedExpINTELILi68ELi68EEU7_ExtIntIXT0_EEiU7_ExtIntIXT_EEibiiii(i68 addrspace(4)* sret(i68) align 8 %tmp.ascast, i68* byval(i68) align 8 %indirect-arg-temp, i1 zeroext false, i32 20, i32 20, i32 0, i32 0) #4
538+
%3 = load i68, i68 addrspace(4)* %tmp.ascast, align 8
539+
store i68 %3, i68 addrspace(4)* %ap_fixed_Exp.ascast, align 8
540+
%4 = bitcast i68* %ap_fixed_Exp to i8*
541+
call void @llvm.lifetime.end.p0i8(i64 16, i8* %4)
542+
%5 = bitcast i68* %a to i8*
543+
call void @llvm.lifetime.end.p0i8(i64 16, i8* %5)
544+
ret void
545+
}
546+
547+
510548
; Function Attrs: nounwind
511549
declare dso_local spir_func signext i5 @_Z22__spirv_FixedSqrtINTELILi13ELi5EEU7_ExtIntIXT0_EEiU7_ExtIntIXT_EEibiiii(i13 signext, i1 zeroext, i32, i32, i32, i32) #4
512550

@@ -546,6 +584,9 @@ declare dso_local spir_func i34 @_Z21__spirv_FixedExpINTELILi44ELi34EEU7_ExtIntI
546584
; Function Attrs: nounwind
547585
declare dso_local spir_func void @_Z24__spirv_FixedSinCosINTELILi34ELi66EEU7_ExtIntIXmlLi2ET0_EEiU7_ExtIntIXT_EEibiiii(i66 addrspace(4)* sret(i66) align 8, i34, i1 zeroext, i32, i32, i32, i32) #4
548586

587+
; Function Attrs: convergent nounwind
588+
declare dso_local spir_func void @_Z21__spirv_FixedExpINTELILi68ELi68EEU7_ExtIntIXT0_EEiU7_ExtIntIXT_EEibiiii(i68 addrspace(4)* sret(i68) align 8, i68* byval(i68) align 8, i1 zeroext, i32, i32, i32, i32) #4
589+
549590
attributes #0 = { norecurse "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "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"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="ap_fixed.cpp" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
550591
attributes #1 = { argmemonly nounwind willreturn }
551592
attributes #2 = { inlinehint norecurse "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "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"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }

llvm-spirv/test/transcoding/capability-arbitrary-precision-floating-point.ll

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@
396396
; ap_float_pow<8, 8, 9, 9, 10, 10>();
397397
; ap_float_powr<18, 35, 19, 35, 20, 35>();
398398
; ap_float_pown<4, 7, 10, 5, 9>();
399+
; ap_float_pown<64, 7, 10, 5, 9>();
399400
; });
400401
; return 0;
401402
; }
@@ -467,6 +468,7 @@
467468
; CHECK-SPIRV: 4 TypeInt [[Ty_56:[0-9]+]] 56 0
468469
; CHECK-SPIRV: 4 TypeInt [[Ty_12:[0-9]+]] 12 0
469470
; CHECK-SPIRV: 4 TypeInt [[Ty_66:[0-9]+]] 66 0
471+
; CHECK-SPIRV: 4 TypeInt [[Ty_72:[0-9]+]] 72 0
470472
; CHECK-SPIRV: 2 TypeBool [[Ty_Bool:[0-9]+]]
471473

472474
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"
@@ -537,6 +539,7 @@ define internal spir_func void @"_ZZ4mainENK3$_0clEv"(%"class._ZTSZ4mainE3$_0.an
537539
call spir_func void @_Z13ap_float_pownILi4ELi7ELi10ELi5ELi9EEvv()
538540
call spir_func void @_Z15ap_float_sincosILi8ELi18ELi10ELi20EEvv_()
539541
call spir_func void @_Z14ap_float_atan2ILi7ELi16ELi7ELi17ELi8ELi18EEvv_()
542+
call spir_func void @_Z13ap_float_pownILi64ELi7ELi10ELi5ELi9EEvv()
540543
ret void
541544
}
542545

@@ -1621,6 +1624,42 @@ define linkonce_odr dso_local spir_func void @_Z14ap_float_atan2ILi7ELi16ELi7ELi
16211624
ret void
16221625
}
16231626

1627+
; Function Attrs: norecurse nounwind
1628+
define linkonce_odr dso_local spir_func void @_Z13ap_float_pownILi64ELi7ELi10ELi5ELi9EEvv() #3 {
1629+
entry:
1630+
%A = alloca i72, align 8
1631+
%A.ascast = addrspacecast i72* %A to i72 addrspace(4)*
1632+
%B = alloca i10, align 2
1633+
%B.ascast = addrspacecast i10* %B to i10 addrspace(4)*
1634+
%pown_res = alloca i15, align 2
1635+
%pown_res.ascast = addrspacecast i15* %pown_res to i15 addrspace(4)*
1636+
%indirect-arg-temp = alloca i72, align 8
1637+
%0 = bitcast i72* %A to i8*
1638+
call void @llvm.lifetime.start.p0i8(i64 16, i8* %0) #5
1639+
%1 = bitcast i10* %B to i8*
1640+
call void @llvm.lifetime.start.p0i8(i64 2, i8* %1) #5
1641+
%2 = bitcast i15* %pown_res to i8*
1642+
call void @llvm.lifetime.start.p0i8(i64 2, i8* %2) #5
1643+
%3 = load i72, i72 addrspace(4)* %A.ascast, align 8
1644+
%4 = load i10, i10 addrspace(4)* %B.ascast, align 2
1645+
store i72 %3, i72* %indirect-arg-temp, align 8
1646+
; CHECK-SPIRV: 6 Load [[Ty_72]] [[ResAId:[0-9]+]]
1647+
; CHECK-SPIRV-NEXT: 6 Load [[Ty_10]] [[PowN_BId:[0-9]+]]
1648+
; CHECK-SPIRV-NEXT: 5 Store [[PtrId:[0-9]+]] [[ResAId]]
1649+
; CHECK-SPIRV-NEXT: 4 Load [[Ty_72]] [[PowN_AId:[0-9]+]]
1650+
; CHECK-SPIRV-NEXT: 10 ArbitraryFloatPowNINTEL [[Ty_15]] [[#]] [[PowN_AId]] 7 [[PowN_BId]] 9 0 2 1
1651+
; CHECK-LLVM: call i15 @intel_arbitrary_float_pown.i15.i72.i10(i72 %[[#]], i32 7, i10 %[[#]], i32 9, i32 0, i32 2, i32 1)
1652+
%call = call spir_func signext i15 @_Z31__spirv_ArbitraryFloatPowNINTELILi72ELi10ELi15EEU7_ExtIntIXT1_EEiU7_ExtIntIXT_EEiiU7_ExtIntIXT0_EEiiiii(i72* byval(i72) align 8 %indirect-arg-temp, i32 7, i10 signext %4, i32 9, i32 0, i32 2, i32 1) #4
1653+
store i15 %call, i15 addrspace(4)* %pown_res.ascast, align 2
1654+
%5 = bitcast i15* %pown_res to i8*
1655+
call void @llvm.lifetime.end.p0i8(i64 2, i8* %5) #5
1656+
%6 = bitcast i10* %B to i8*
1657+
call void @llvm.lifetime.end.p0i8(i64 2, i8* %6) #5
1658+
%7 = bitcast i72* %A to i8*
1659+
call void @llvm.lifetime.end.p0i8(i64 16, i8* %7) #5
1660+
ret void
1661+
}
1662+
16241663
; Function Attrs: nounwind
16251664
declare dso_local spir_func i40 @_Z31__spirv_ArbitraryFloatCastINTELILi40ELi40EEU7_ExtIntIXT0_EEiU7_ExtIntIXT_EEiiiiii(i40, i32, i32, i32, i32, i32) #4
16261665

@@ -1753,6 +1792,9 @@ declare dso_local spir_func void @_Z33__spirv_ArbitraryFloatSinCosINTELILi34ELi6
17531792
; Function Attrs: nounwind
17541793
declare dso_local spir_func void @_Z32__spirv_ArbitraryFloatATan2INTELILi24ELi25ELi66EEU7_ExtIntIXT1_EEiU7_ExtIntIXT_EEiiU7_ExtIntIXT0_EEiiiiii(i66 addrspace(4)* sret(i66) align 8, i24 signext, i32, i25 signext, i32, i32, i32, i32, i32) #4
17551794

1795+
; Function Attrs: nounwind
1796+
declare dso_local spir_func signext i15 @_Z31__spirv_ArbitraryFloatPowNINTELILi72ELi10ELi15EEU7_ExtIntIXT1_EEiU7_ExtIntIXT_EEiiU7_ExtIntIXT0_EEiiiii(i72* byval(i72) align 8, i32, i10 signext, i32, i32, i32, i32) #4
1797+
17561798
attributes #0 = { norecurse "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "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"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
17571799
attributes #1 = { argmemonly nounwind willreturn }
17581800
attributes #2 = { inlinehint norecurse "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "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"="true" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }

0 commit comments

Comments
 (0)