Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ Value *SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
}

case OpUndef:
return mapValue(BV, UndefValue::get(transType(BV->getType())));
return mapValue(BV, PoisonValue::get(transType(BV->getType())));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do the replacement unconditionally. If we really want to invest into this, then we should do this following https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_validity_and_defined_behavior aka check which instruction generates/consume OpUndef and if consuming this undef/poison value is forbidden for an instruction - undef should be generated in LLVM IR, and poison otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Shall we follow the logic described in the spec directly? As I can see, there could be several "forbidden consumers" such as conditional branch instructions. Or are there any other assumptions? The check seems to be very non-elegant, because it tries to evaluate the context of the users (other mappers here do not perform such checks)

Copy link
Contributor

@MrSidims MrSidims Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me if I'm wrong. The patch addresses this fixme, right? If so, I would like to understand, why roundtrip through llvm-spirv alone and through backend + llvm-spirv are different before suggesting an approach.


case OpSizeOf: {
Type *ResTy = transType(BV->getType());
Expand Down
2 changes: 1 addition & 1 deletion test/DebugInfo/DebugInfoLLVMArg.ll
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ entry:
; CHECK-LLVM-OCL: #dbg_value(!DIArgList(ptr %x), ![[#]], !DIExpression(DW_OP_LLVM_arg, 0), ![[#]])
; CHECK-LLVM-200: #dbg_value(!DIArgList(ptr %x), ![[#]], !DIExpression(DW_OP_LLVM_arg, 0), ![[#]])
call void @llvm.dbg.value(metadata !DIArgList(ptr %x), metadata !6, metadata !DIExpression(DW_OP_LLVM_arg, 0)), !dbg !10
; CHECK-LLVM-OCL: #dbg_value(ptr undef, ![[#]], !DIExpression(), ![[#]])
; CHECK-LLVM-OCL: #dbg_value(ptr poison, ![[#]], !DIExpression(), ![[#]])
; CHECK-LLVM-200: #dbg_value(!DIArgList(ptr %x, ptr %x), ![[#]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus)
call void @llvm.dbg.value(metadata !DIArgList(ptr %x, ptr %x), metadata !6, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_plus)), !dbg !10
store i32 42, ptr %x, align 4
Expand Down
2 changes: 1 addition & 1 deletion test/complex-constexpr-vector.ll
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ entry:
; CHECK-LLVM-SAME: i8 add (
; CHECK-LLVM-SAME: i8 extractelement (<8 x i8> bitcast (<2 x i32> splat (i32 65793) to <8 x i8>), i32 2),
; CHECK-LLVM-SAME: i8 extractelement (<8 x i8> bitcast (<2 x i32> splat (i32 131586) to <8 x i8>), i32 2)),
; CHECK-LLVM-SAME: i8 undef>,
; CHECK-LLVM-SAME: i8 poison>,
; CHECK-LLVM-SAME: ![[#]], !DIExpression(), ![[#]])

; CHECK-LLC: target triple = "spir64-unknown-unknown"
Expand Down
4 changes: 2 additions & 2 deletions test/freeze.ll
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ define spir_func i64 @testfunction_ptrB(ptr addrspace(1) %val) {
}

; CHECK-LLC: @testfunction_ptrB
; CHECK-LLC-NEXT: ptrtoint ptr undef to i64
; CHECK-LLC-NEXT: ptrtoint ptr poison to i64

; CHECK-LLVM: @testfunction_ptrC
; Frozen poison/undef should produce a constant.
Expand All @@ -138,4 +138,4 @@ define spir_func i64 @testfunction_ptrC(ptr addrspace(1) %val) {
}

; CHECK-LLC: @testfunction_ptrC
; CHECK-LLC-NEXT: ptrtoint ptr undef to i64
; CHECK-LLC-NEXT: ptrtoint ptr poison to i64
2 changes: 1 addition & 1 deletion test/global-var-name-linkage.ll
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ target triple = "spir64-unknown-unknown"
; CHECK-DAG: Decorate [[#id38]] Constant
; CHECK-DAG: Decorate [[#id38]] Alignment 4

; CHECK-LLVM: @G1 = internal addrspace(1) constant %"class.sycl::_V1::nd_item" undef, align 1
; CHECK-LLVM: @G1 = internal addrspace(1) constant %"class.sycl::_V1::nd_item" poison, align 1
; CHECK-LLVM: @g1 = addrspace(1) global i32 1, align 4
; CHECK-LLVM: @g2 = internal addrspace(1) global i32 2, align 4
; CHECK-LLVM: @g4 = common addrspace(1) global i32 0, align 4
Expand Down
4 changes: 2 additions & 2 deletions test/llvm-intrinsics/frexp.ll
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ define { float, i32 } @frexp_negzero() {
}

; CHECK-SPIRV: ExtInst [[#TypeDouble]] [[#]] [[#ExtInstSetId]] frexp [[#UndefDouble]] [[#]]
; CHECK-LLVM: call spir_func double @_Z5frexpdPi(double undef, ptr %[[#]])
; CHECK-LLVM: call spir_func double @_Z5frexpdPi(double poison, ptr %[[#]])
; CHECK-LLVM: ret %[[StrTypeDoubleInt]]
define { double, i32 } @frexp_undef() {
%ret = call { double, i32 } @llvm.frexp.f64.i32(double undef)
Expand All @@ -104,7 +104,7 @@ define { <2 x float>, <2 x i32> } @frexp_zero_negzero_vector() {
}

; CHECK-SPIRV: ExtInst [[#VecFloat4]] [[#]] [[#ExtInstSetId]] frexp [[#]] [[#]]
; CHECK-LLVM: call spir_func <4 x float> @_Z5frexpDv4_fPDv4_i(<4 x float> <float 1.600000e+01, float -3.200000e+01, float undef, float 9.999000e+03>, ptr %[[#]])
; CHECK-LLVM: call spir_func <4 x float> @_Z5frexpDv4_fPDv4_i(<4 x float> <float 1.600000e+01, float -3.200000e+01, float poison, float 9.999000e+03>, ptr %[[#]])
; CHECK-LLVM: ret %[[StrTypeFloatIntVec4]]
define { <4 x float>, <4 x i32> } @frexp_nonsplat_vector() {
%ret = call { <4 x float>, <4 x i32> } @llvm.frexp.v4f32.v4i32(<4 x float> <float 16.0, float -32.0, float undef, float 9999.0>)
Expand Down
8 changes: 4 additions & 4 deletions test/llvm-intrinsics/uadd.with.overflow.ll
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ entry:
; CHECK-LLVM: %8 = extractvalue [[structtype]] %7, 0
; CHECK-LLVM: %9 = extractvalue [[structtype]] %7, 1
; CHECK-LLVM: %10 = icmp ne i16 %9, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_0]] undef, i16 %8, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_0]] poison, i16 %8, 0
; CHECK-LLVM: %12 = insertvalue [[structtype_0]] %11, i1 %10, 1
; CHECK-LLVM: %13 = extractvalue [[structtype_0]] %12, 0
; CHECK-LLVM: %14 = extractvalue [[structtype_0]] %12, 1
Expand Down Expand Up @@ -126,7 +126,7 @@ entry:
; CHECK-LLVM: %8 = extractvalue [[structtype_1]] %7, 0
; CHECK-LLVM: %9 = extractvalue [[structtype_1]] %7, 1
; CHECK-LLVM: %10 = icmp ne i32 %9, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_2]] undef, i32 %8, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_2]] poison, i32 %8, 0
; CHECK-LLVM: %12 = insertvalue [[structtype_2]] %11, i1 %10, 1
; CHECK-LLVM: %13 = extractvalue [[structtype_2]] %12, 0
; CHECK-LLVM: %14 = extractvalue [[structtype_2]] %12, 1
Expand Down Expand Up @@ -167,7 +167,7 @@ entry:
; CHECK-LLVM: %8 = extractvalue [[structtype_3]] %7, 0
; CHECK-LLVM: %9 = extractvalue [[structtype_3]] %7, 1
; CHECK-LLVM: %10 = icmp ne i64 %9, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_4]] undef, i64 %8, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_4]] poison, i64 %8, 0
; CHECK-LLVM: %12 = insertvalue [[structtype_4]] %11, i1 %10, 1
; CHECK-LLVM: %13 = extractvalue [[structtype_4]] %12, 0
; CHECK-LLVM: %14 = extractvalue [[structtype_4]] %12, 1
Expand Down Expand Up @@ -208,7 +208,7 @@ entry:
; CHECK-LLVM: %8 = extractvalue [[structtype_5]] %7, 0
; CHECK-LLVM: %9 = extractvalue [[structtype_5]] %7, 1
; CHECK-LLVM: %10 = icmp ne <4 x i32> %9, zeroinitializer
; CHECK-LLVM: %11 = insertvalue [[structtype_6]] undef, <4 x i32> %8, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_6]] poison, <4 x i32> %8, 0
; CHECK-LLVM: %12 = insertvalue [[structtype_6]] %11, <4 x i1> %10, 1
; CHECK-LLVM: %13 = extractvalue [[structtype_6]] %12, 0
; CHECK-LLVM: %14 = extractvalue [[structtype_6]] %12, 1
Expand Down
8 changes: 4 additions & 4 deletions test/llvm-intrinsics/usub.with.overflow.ll
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ entry:
; CHECK-LLVM: %8 = extractvalue [[structtype]] %7, 0
; CHECK-LLVM: %9 = extractvalue [[structtype]] %7, 1
; CHECK-LLVM: %10 = icmp ne i16 %9, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_0]] undef, i16 %8, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_0]] poison, i16 %8, 0
; CHECK-LLVM: %12 = insertvalue [[structtype_0]] %11, i1 %10, 1
; CHECK-LLVM: %13 = extractvalue [[structtype_0]] %12, 0
; CHECK-LLVM: %14 = extractvalue [[structtype_0]] %12, 1
Expand Down Expand Up @@ -126,7 +126,7 @@ entry:
; CHECK-LLVM: %8 = extractvalue [[structtype_1]] %7, 0
; CHECK-LLVM: %9 = extractvalue [[structtype_1]] %7, 1
; CHECK-LLVM: %10 = icmp ne i32 %9, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_2]] undef, i32 %8, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_2]] poison, i32 %8, 0
; CHECK-LLVM: %12 = insertvalue [[structtype_2]] %11, i1 %10, 1
; CHECK-LLVM: %13 = extractvalue [[structtype_2]] %12, 0
; CHECK-LLVM: %14 = extractvalue [[structtype_2]] %12, 1
Expand Down Expand Up @@ -167,7 +167,7 @@ entry:
; CHECK-LLVM: %8 = extractvalue [[structtype_3]] %7, 0
; CHECK-LLVM: %9 = extractvalue [[structtype_3]] %7, 1
; CHECK-LLVM: %10 = icmp ne i64 %9, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_4]] undef, i64 %8, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_4]] poison, i64 %8, 0
; CHECK-LLVM: %12 = insertvalue [[structtype_4]] %11, i1 %10, 1
; CHECK-LLVM: %13 = extractvalue [[structtype_4]] %12, 0
; CHECK-LLVM: %14 = extractvalue [[structtype_4]] %12, 1
Expand Down Expand Up @@ -208,7 +208,7 @@ entry:
; CHECK-LLVM: %8 = extractvalue [[structtype_5]] %7, 0
; CHECK-LLVM: %9 = extractvalue [[structtype_5]] %7, 1
; CHECK-LLVM: %10 = icmp ne <4 x i32> %9, zeroinitializer
; CHECK-LLVM: %11 = insertvalue [[structtype_6]] undef, <4 x i32> %8, 0
; CHECK-LLVM: %11 = insertvalue [[structtype_6]] poison, <4 x i32> %8, 0
; CHECK-LLVM: %12 = insertvalue [[structtype_6]] %11, <4 x i1> %10, 1
; CHECK-LLVM: %13 = extractvalue [[structtype_6]] %12, 0
; CHECK-LLVM: %14 = extractvalue [[structtype_6]] %12, 1
Expand Down
4 changes: 2 additions & 2 deletions test/opundef.spt
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@

; CHECK: define spir_func %structtype @foo() #0 {
; CHECK-NEXT: entry:
; CHECK-NEXT: ret %structtype { i32 1, float undef }
; CHECK-NEXT: ret %structtype { i32 1, float poison }
; CHECK-NEXT: }
; CHECK: define spir_func %structtype @bar() #0 {
; CHECK-NEXT: entry:
; CHECK-NEXT: ret %structtype { i32 1, float undef }
; CHECK-NEXT: ret %structtype { i32 1, float poison }
; CHECK-NEXT: }

Loading