Skip to content

Commit b9df4ab

Browse files
Fznamznonvmaksimo
authored andcommitted
Allow to translate llvm.fabs with half arguments
The OpenCL SPIR-V Environment Specification seems to allow corresponding instruction.
1 parent 2cf914a commit b9df4ab

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

llvm-spirv/lib/SPIRV/SPIRVUtil.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,7 +1542,7 @@ bool checkTypeForSPIRVExtendedInstLowering(IntrinsicInst *II, SPIRVModule *BM) {
15421542
NumElems = VecTy->getNumElements();
15431543
Ty = VecTy->getElementType();
15441544
}
1545-
if ((!Ty->isFloatTy() && !Ty->isDoubleTy()) ||
1545+
if ((!Ty->isFloatTy() && !Ty->isDoubleTy() && !Ty->isHalfTy()) ||
15461546
((NumElems > 4) && (NumElems != 8) && (NumElems != 16))) {
15471547
BM->getErrorLog().checkError(false, SPIRVEC_InvalidFunctionCall,
15481548
II->getCalledOperand()->getName().str(), "",

llvm-spirv/test/llvm.fabs.ll

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,21 @@ target triple = "spir64-unknown-unknown"
88

99
; CHECK: ExtInstImport [[extinst_id:[0-9]+]] "OpenCL.std"
1010

11+
; CHECK: 3 TypeFloat [[var0:[0-9]+]] 16
1112
; CHECK: 3 TypeFloat [[var1:[0-9]+]] 32
1213
; CHECK: 3 TypeFloat [[var2:[0-9]+]] 64
13-
; CHECK: 4 TypeVector [[var3:[0-9]+]] 2 4
14+
; CHECK: 4 TypeVector [[var3:[0-9]+]] [[var1]] 4
15+
16+
; CHECK: Function
17+
; CHECK: 6 ExtInst [[var0]] {{[0-9]+}} [[extinst_id]] fabs
18+
; CHECK: FunctionEnd
19+
20+
; Function Attrs: nounwind readnone
21+
define spir_func half @TestFabs16(half %x) local_unnamed_addr #0 {
22+
entry:
23+
%0 = tail call half @llvm.fabs.f16(half %x)
24+
ret half %0
25+
}
1426

1527
; CHECK: Function
1628
; CHECK: 6 ExtInst [[var1]] {{[0-9]+}} [[extinst_id]] fabs
@@ -45,6 +57,9 @@ entry:
4557
ret <4 x float> %0
4658
}
4759

60+
; Function Attrs: nounwind readnone
61+
declare half @llvm.fabs.f16(half) #1
62+
4863
; Function Attrs: nounwind readnone
4964
declare float @llvm.fabs.f32(float) #1
5065

0 commit comments

Comments
 (0)