Skip to content

Commit 8e53f09

Browse files
VyacheslavLevytskyysys-ce-bb
authored andcommitted
add support for the 'fcmp false' instruction (#2251)
* add support for the 'fcmp false' instruction * fcmp false: present vector of false values as ConstantNull Original commit: KhronosGroup/SPIRV-LLVM-Translator@aeeaf6c
1 parent b3dbd48 commit 8e53f09

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,6 +2109,13 @@ LLVMToSPIRVBase::transValueWithoutDecoration(Value *V, SPIRVBasicBlock *BB,
21092109
}
21102110

21112111
if (CmpInst *Cmp = dyn_cast<CmpInst>(V)) {
2112+
if (Cmp->getPredicate() == CmpInst::Predicate::FCMP_FALSE) {
2113+
auto *CmpTy = Cmp->getType();
2114+
SPIRVValue *FalseValue = CmpTy->isVectorTy()
2115+
? BM->addNullConstant(transType(CmpTy))
2116+
: BM->addConstant(BM->addBoolType(), 0);
2117+
return mapValue(V, FalseValue);
2118+
}
21122119
SPIRVInstruction *BI = transCmpInst(Cmp, BB);
21132120
return mapValue(V, BI);
21142121
}

llvm-spirv/test/FCmpFalse.ll

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text -o %t.spt
3+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
4+
; RUN: llvm-spirv %t.bc -o %t.spv
5+
; RUN: spirv-val %t.spv
6+
7+
; CHECK-SPIRV: ConstantFalse [[#]] [[#FalseVal:]]
8+
; CHECK-SPIRV: ReturnValue [[#FalseVal]]
9+
10+
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"
11+
target triple = "spir64-unknown-unknown"
12+
13+
define spir_func i1 @f(float %0) {
14+
%2 = fcmp false float %0, %0
15+
ret i1 %2
16+
}

llvm-spirv/test/FCmpFalse_Vec.ll

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -spirv-text -o %t.spt
3+
; RUN: FileCheck < %t.spt %s --check-prefix=CHECK-SPIRV
4+
; RUN: llvm-spirv %t.bc -o %t.spv
5+
; RUN: spirv-val %t.spv
6+
7+
; CHECK-SPIRV: TypeBool [[#BoolTy:]]
8+
; CHECK-SPIRV: TypeVector [[#VecTy:]] [[#BoolTy]] 4
9+
; CHECK-SPIRV: ConstantNull [[#VecTy]] [[#VecNullVal:]]
10+
; CHECK-SPIRV: ReturnValue [[#VecNullVal]]
11+
12+
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"
13+
target triple = "spir64-unknown-unknown"
14+
15+
define spir_func <4 x i1> @f(<4 x float> %0) {
16+
%2 = fcmp false <4 x float> %0, %0
17+
ret <4 x i1> %2
18+
}

0 commit comments

Comments
 (0)