Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPIR-V] Incorrect builtin implementation work_group_any #97312

Open
michalpaszkowski opened this issue Jul 1, 2024 · 1 comment
Open

[SPIR-V] Incorrect builtin implementation work_group_any #97312

michalpaszkowski opened this issue Jul 1, 2024 · 1 comment
Assignees

Comments

@michalpaszkowski
Copy link
Member

target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v12
8:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024"
target triple = "spir64-unknown-unknown"

; Function Attrs: nounwind
define spir_kernel void @test_wg_any(ptr addrspace(1) %input, ptr addrspace(1) %output) #0 !kernel_arg_addr_space !7 !kernel_arg_access_qual !8 !kernel_arg_type !9
 !kernel_arg_type_qual !10 !kernel_arg_base_type !9 !spirv.ParameterDecorations !11 {
entry:
  %0 = call spir_func i64 @_Z13get_global_idj(i32 0) #1
  %1 = insertelement <3 x i64> undef, i64 %0, i32 0
  %2 = call spir_func i64 @_Z13get_global_idj(i32 1) #1
  %3 = insertelement <3 x i64> %1, i64 %2, i32 1
  %4 = call spir_func i64 @_Z13get_global_idj(i32 2) #1
  %5 = insertelement <3 x i64> %3, i64 %4, i32 2
  %call = extractelement <3 x i64> %5, i32 0
  %conv = trunc i64 %call to i32
  %idxprom = sext i32 %conv to i64
  %arrayidx = getelementptr inbounds float, ptr addrspace(1) %input, i64 %idxprom
  %6 = load float, ptr addrspace(1) %arrayidx, align 4
  %add = add nsw i32 %conv, 1
  %idxprom1 = sext i32 %add to i64
  %arrayidx2 = getelementptr inbounds float, ptr addrspace(1) %input, i64 %idxprom1
  %7 = load float, ptr addrspace(1) %arrayidx2, align 4
  %cmp = fcmp ogt float %6, %7
  %conv3 = select i1 %cmp, i32 1, i32 0
  %8 = icmp ne i32 %conv3, 0
  %9 = zext i1 %8 to i32
  %10 = call spir_func i32 @_Z14work_group_anyi(i32 %9) #2
  %call41 = icmp ne i32 %10, 0
  %call4 = select i1 %call41, i32 1, i32 0
  %idxprom5 = sext i32 %conv to i64
  %arrayidx6 = getelementptr inbounds i32, ptr addrspace(1) %output, i64 %idxprom5
  store i32 %call4, ptr addrspace(1) %arrayidx6, align 4
  ret void
}

; Function Attrs: nounwind willreturn memory(none)
declare spir_func i64 @_Z13get_global_idj(i32) #1

; Function Attrs: convergent nounwind
declare spir_func i32 @_Z14work_group_anyi(i32) #2

attributes #0 = { nounwind }
attributes #1 = { nounwind willreturn memory(none) }
attributes #2 = { convergent nounwind }

!spirv.MemoryModel = !{!0}
!opencl.enable.FP_CONTRACT = !{}
!spirv.Source = !{!1}
!opencl.spir.version = !{!2}
!opencl.ocl.version = !{!3}
!opencl.used.extensions = !{!4}
!opencl.used.optional.core.features = !{!5}
!spirv.Generator = !{!6}

!0 = !{i32 2, i32 2}
!1 = !{i32 3, i32 300000}
!2 = !{i32 2, i32 0}
!3 = !{i32 3, i32 0}
!4 = !{!"cl_khr_subgroups"}
!5 = !{}
!6 = !{i16 6, i16 14}
!7 = !{i32 1, i32 1}
!8 = !{!"none", !"none"}
!9 = !{!"float*", !"int*"}
!10 = !{!"", !""}
!11 = !{!5, !5}

Assertion hit when compiling with SPIR-V backend:

SPIRVBuiltins.cpp:1058: bool llvm::generateGroupInst(const llvm::SPIRV::IncomingCall*, llvm::MachineIRBuilder&, llvm::SPIRVGlobalRegistry*): Assertion `ArgInstruction->getOpcode() == TargetOpcode::G_CONSTANT && "Only constant bool value args are supported"' failed.
@michalpaszkowski
Copy link
Member Author

The above code comes from recent SPIR-V Translator (back translation) from LLVM IR dumped by most recent IGC. The test passes in IGC, since the original LLVM IR coming from the OpenCL CTS test suite has a different builtin call:

%call41 = call spir_func i1 @OpGroupAny_i32_i1(i32 2, i1 %3)
...
declare spir_func i1 @OpGroupAny_i32_i1(i32, i1)

@VyacheslavLevytskyy VyacheslavLevytskyy self-assigned this Aug 12, 2024
VyacheslavLevytskyy added a commit that referenced this issue Aug 12, 2024
… boolean argument (#102902)

This PR resolves a TODO in `generateGroupInst()`
(`lib/Target/SPIRV/SPIRVBuiltins.cpp`) and Issues
#97311 and
#97312 by implementing
support for non-const arguments in a Group builtin that requires a
boolean argument.
bwendling pushed a commit to bwendling/llvm-project that referenced this issue Aug 15, 2024
… boolean argument (llvm#102902)

This PR resolves a TODO in `generateGroupInst()`
(`lib/Target/SPIRV/SPIRVBuiltins.cpp`) and Issues
llvm#97311 and
llvm#97312 by implementing
support for non-const arguments in a Group builtin that requires a
boolean argument.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants