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

Use poison instead of undef values wherever possible #2960

Merged
merged 4 commits into from
Jan 20, 2025

Conversation

vmaksimo
Copy link
Contributor

In reverse translation always use poison values except cases where we translate OpUndef. In other cases common sense was used to define where it is safe to replace undef to poison (e.g. in creating structures, regularization passes).

This resolves #2953 and aligns us with the LLVM community in terms of generating IR.

In reverse translation always use `poison` values except cases where we
translate `OpUndef`. In other cases common sense helped to define where
it is safe to replace `undef` to `poison` (e.g. in creating structions,
regularization passes).

This resolves KhronosGroup#2953 and aligns us with the LLVM community in terms of
generating IR.
@@ -231,7 +231,7 @@ void SPIRVRegularizeLLVMBase::buildUMulWithOverflowFunc(Function *UMulFunc) {
// umul.with.overflow intrinsic return a structure, where the first element
// is the multiplication result, and the second is an overflow bit.
auto *StructTy = UMulFunc->getReturnType();
auto *Agg = Builder.CreateInsertValue(UndefValue::get(StructTy), Mul, {0});
auto *Agg = Builder.CreateInsertValue(PoisonValue::get(StructTy), Mul, {0});
Copy link
Contributor

Choose a reason for hiding this comment

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

Why changes in SPIRVRegularizeLLVM don't break tests? We don't have poison in SPIR-V, meanwhile you add it to the input LLVM IR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, maybe because I changed check-lines in tests as well?
But whatever the reason, I think that we can safely use poison instead of undef here because it's not the actual input, but the value we insert ourselves. This way we should not break input semantics.
What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

But whatever the reason, I think that we can safely use poison instead of undef here because it's not the actual input, but the value we insert ourselves. This way we should not break input semantics.

Incorrect. If we insert something in LLVM IR that SPIRVWriter doesn't support - it will emit an error.

So I meant to say: if the translator doesn't handle poison, then this change would result in a regression when compiling a user code. But I've double checked it, and it seems like the translator is actually handling poison values (at least at some extend). For example in transConstant for the following LLVM IR snippet:

%structtype = type { i32, float }

define spir_func %structtype @foo() {
entry:
  ret %structtype { i32 1, float poison }
}

this check results in true, so OpUndef is added instead of poison.

So at least for constants we are safe. Revisiting our offline conversation: guess we can replace more 'undef' code to 'poison' during forward translation.

test/extensions/KHR/SPV_KHR_untyped_pointers/basic.ll Outdated Show resolved Hide resolved
@vmaksimo vmaksimo requested a review from MrSidims January 13, 2025 11:28
@MrSidims
Copy link
Contributor

Restarting CI

@MrSidims MrSidims closed this Jan 16, 2025
@MrSidims MrSidims reopened this Jan 16, 2025
@MrSidims MrSidims requested a review from svenvh January 16, 2025 12:32
Copy link
Member

@svenvh svenvh left a comment

Choose a reason for hiding this comment

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

LGTM, just a small nit.

lib/SPIRV/SPIRVUtil.cpp Show resolved Hide resolved
@MrSidims MrSidims merged commit cec12d6 into KhronosGroup:main Jan 20, 2025
9 checks passed
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.

Generate poison values instead of undef in reverse translation to align with the LLVM community
3 participants