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

Replace llvm.fmuladd.v1f* with llvm.fmuladd.f* since OpenCL doesn't support length-1 vector. #2868

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

haonanya1
Copy link

No description provided.

@CLAassistant
Copy link

CLAassistant commented Nov 19, 2024

CLA assistant check
All committers have signed the CLA.

@haonanya1
Copy link
Author

@svenvh , @MrSidims, can you please take a look? Thanks.

Copy link
Contributor

@MrSidims MrSidims left a comment

Choose a reason for hiding this comment

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

I won't resist to merge the patch, yet my preference to fix this earlier in the compilation stack (before the translator) by replacing all <1 x ...> vectors in the module with scalars. My opinion that we better not to do such replacements in the translator. The reason is that we don't know the environment for which LLVM IR was compiled and I can imagine an unlikely yet possible situation, when LLVM IR compiled for RISC-V architecture comes as an input to the translator and AFAIK <1 x ...> vectors in LLVM IR can be used to represent scalable vectors RISC-V extension. So replacing them with scalars in the translator would be incorrect. Counterargument would be: for this RISC-V folks should add a new extension in SPIR-V, so until it's enabled we could replace vectors with scalars, but IMO it's still better not to do so and continue to emit an error.

UPD: ... LLVM IR are used ... -> ... LLVM IR can be used ...

@@ -0,0 +1,109 @@
; RUN: llvm-as < %s -o %t.bc
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_vector_compute -o %t.spv
Copy link
Contributor

Choose a reason for hiding this comment

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

This extension is not standard and we shouldn't rely on it. Meanwhile you have to use it as there are <1 x ...> vectors in the module.

@haonanya1
Copy link
Author

Thanks for quick reply, @MrSidims, the IR is valid, the number of elements for vector type is a constant integer value larger than 0 in llvm ir https://llvm.org/docs/LangRef.html#vector-type. Component Count of spirv OpTypeVector must be at least 2 https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpTypeVector. There are gaps for IR and spirv. @bashbaug , what do you think? Thanks very much.

@MrSidims
Copy link
Contributor

MrSidims commented Nov 19, 2024

the IR is valid, the number of elements for vector type is a constant integer value larger than 0 in llvm ir

@haonanya1 that's correct. But here comes the question whether we consider https://github.com/KhronosGroup/SPIRV-LLVM-Translator as a proper backend with instructions/intrinsics lowering and types legalization or just as a translator, which just translates one IR form into another form of IR. Currently we are positioning it somewhere in between, doing lowering and not doing legalization. Yet again, it might be OK to add mapping for <1 x ...> vectors to scalars, but I'm a bit afraid to break existing or future flows as <1 x ...> can be also a scalable vector. May be it's fine to break it, at least we would know if we have such customers from incoming llvm-spirv github issue(s) :-)

I'd like to hear opinion from @svenvh . I'll propose the PR to OpenCL TSG meeting.

@svenvh
Copy link
Member

svenvh commented Nov 19, 2024

I'm a bit afraid to break existing or future flows as <1 x ...> can be also a scalable vector

Aren't scalable vectors represented using <vscale x ...>?

I don't have strong objections against doing a vec1 -> scalar replacement in the translator. However I would suggest to implement that as a separate pass, and not only for the fmuladd intrinsic, but for all instructions in the module with <1 x ...> vector types.

@MrSidims
Copy link
Contributor

Aren't scalable vectors represented using <vscale x ...>?

Oh, indeed, not sure why I though it's just <1 x ...>. So no objections from me to do such transformation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants