Skip to content

Commit 677cd0e

Browse files
LU-JOHNagainull
authored andcommitted
Allow ICmpInst in transValue assert (#1948)
Fix assertion failure in transValue when ICmpInst is hit when icmp is used in constexpr. Signed-off-by: Lu, John <john.lu@intel.com> Original commit: KhronosGroup/SPIRV-LLVM-Translator@954202d
1 parent 0599a69 commit 677cd0e

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ SPIRVValue *LLVMToSPIRVBase::transValue(Value *V, SPIRVBasicBlock *BB,
13851385

13861386
SPIRVDBG(dbgs() << "[transValue] " << *V << '\n');
13871387
assert((!isa<Instruction>(V) || isa<GetElementPtrInst>(V) ||
1388-
isa<CastInst>(V) || isa<ExtractElementInst>(V) ||
1388+
isa<CastInst>(V) || isa<ExtractElementInst>(V) || isa<ICmpInst>(V) ||
13891389
isa<BinaryOperator>(V) || BB) &&
13901390
"Invalid SPIRV BB");
13911391

llvm-spirv/test/constexpr_icmp.ll

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv %t.bc -o %t.spv
3+
; RUN: llvm-spirv %t.spv -o %t.spt --to-text
4+
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o %t.bc
5+
; RUN: llvm-dis %t.bc -o %t.ll
6+
; RUN: FileCheck %s --input-file %t.spt -check-prefix=CHECK-SPIRV
7+
; RUN: FileCheck %s --input-file %t.ll -check-prefix=CHECK-LLVM
8+
9+
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"
10+
target triple = "spir64"
11+
12+
define linkonce_odr hidden spir_func void @foo() {
13+
entry:
14+
; CHECK-SPIRV: [[#]] ExtInst [[#]] [[#]] [[#]] DebugValue [[#]] [[#]] [[#]]
15+
; CHECK-LLVM: call void @llvm.dbg.value(metadata <2 x i8> <i8 zext (i1 icmp ne (i8 extractelement (<16 x i8> bitcast (<2 x i64> <i64 72340172838076673, i64 72340172838076673> to <16 x i8>), i32 0), i8 0) to i8), i8 zext (i1 icmp ne (i8 extractelement (<16 x i8> bitcast (<2 x i64> <i64 72340172838076673, i64 72340172838076673> to <16 x i8>), i32 0), i8 0) to i8)>, metadata ![[#]], metadata !DIExpression()), !dbg ![[#]]
16+
17+
call void @llvm.dbg.value(
18+
metadata <2 x i8> <i8 zext (i1 icmp ne (i8 extractelement (<16 x i8> bitcast (<2 x i64> <i64 72340172838076673, i64 72340172838076673> to <16 x i8>), i64 0), i8 0) to i8),
19+
i8 zext (i1 icmp ne (i8 extractelement (<16 x i8> bitcast (<2 x i64> <i64 72340172838076673, i64 72340172838076673> to <16 x i8>), i64 0), i8 0) to i8)>,
20+
metadata !12,
21+
metadata !DIExpression()), !dbg !7
22+
ret void
23+
}
24+
25+
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
26+
declare void @llvm.dbg.value(metadata, metadata, metadata)
27+
28+
!llvm.dbg.cu = !{!0}
29+
!llvm.module.flags = !{!3, !4}
30+
!opencl.used.extensions = !{!2}
31+
!opencl.used.optional.core.features = !{!2}
32+
!opencl.compiler.options = !{!2}
33+
!llvm.ident = !{!5}
34+
35+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0 (https://github.com/intel/llvm.git)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
36+
!1 = !DIFile(filename: "main.cpp", directory: "/export/users")
37+
!2 = !{}
38+
!3 = !{i32 2, !"Debug Info Version", i32 3}
39+
!4 = !{i32 1, !"wchar_size", i32 4}
40+
!5 = !{!"clang version 13.0.0"}
41+
!6 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 1, type: !8, scopeLine: 4, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
42+
!7 = !DILocation(line: 1, scope: !6, inlinedAt: !11)
43+
!8 = !DISubroutineType(types: !9)
44+
!9 = !{!10}
45+
!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
46+
!11 = !DILocation(line: 1, column: 0, scope: !6)
47+
!12 = !DILocalVariable(name: "resVec", scope: !6, file: !1, line: 1, type: !13)
48+
!13 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "vec<cl::sycl::detail::half_impl::half, 3>", scope: !6, file: !1, line: 1, size: 64, flags: DIFlagTypePassByValue, elements: !2)

0 commit comments

Comments
 (0)