Skip to content

Translate OpUndef to poison instead of undef in SPIR-V reader#3661

Open
aobolensk wants to merge 1 commit intoKhronosGroup:mainfrom
aobolensk:undef-to-poison
Open

Translate OpUndef to poison instead of undef in SPIR-V reader#3661
aobolensk wants to merge 1 commit intoKhronosGroup:mainfrom
aobolensk:undef-to-poison

Conversation

@aobolensk
Copy link
Contributor

@aobolensk aobolensk commented Mar 17, 2026

LLVM is migrating from undef to poison values. Update the OpUndef translation in SPIRVReader to produce PoisonValue instead of UndefValue.

Enable round-trip for test/var_undef.ll where the only difference between the approaches was related to undef vs poison

@aobolensk
Copy link
Contributor Author

@MrSidims please, take a look

Copy link
Contributor

@vmaksimo vmaksimo left a comment

Choose a reason for hiding this comment

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

I seriously doubt we should make this change before LLVM totally removes undef.
We already aligned to the community wherever possible (cec12d6) in terms of using poison, but translation of OpUndef to poison does not seem reasonable to me right now.

@aobolensk
Copy link
Contributor Author

I seriously doubt we should make this change before LLVM totally removes undef. We already aligned to the community wherever possible (cec12d6) in terms of using poison, but translation of OpUndef to poison does not seem reasonable to me right now.

Actually, that was done now for the purpose of alignment with SPIR-V backend in LLVM

@MrSidims
Copy link
Contributor

I seriously doubt we should make this change before LLVM totally removes undef.

LLVM is not going to remove undef.

Actually, that was done now for the purpose of alignment with SPIR-V backend in LLVM

Do we understand, why SPIR-V module produced by the backend results in poison creation after reverse translation when SPIR-V module produced by the translator is resulting in undef after the round trip?


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.

@aobolensk aobolensk requested a review from MrSidims March 18, 2026 13:53
@aobolensk
Copy link
Contributor Author

Do we understand, why SPIR-V module produced by the backend results in poison creation after reverse translation when SPIR-V module produced by the translator is resulting in undef after the round trip?

Backend does not produce OpUndef by itself, while translator does. That creates the difference

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.

3 participants