-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[IR] Disallow ZeroInit for spirv.Image #73887
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
Conversation
According to spirv spec, OpConstantNull's result type can't be image type. So we can't generate zeroinitializer for spirv.Image.
@llvm/pr-subscribers-llvm-ir @llvm/pr-subscribers-llvm-transforms Author: Wenju He (wenju-he) ChangesAccording to spirv spec, OpConstantNull's result type can't be image Full diff: https://github.com/llvm/llvm-project/pull/73887.diff 2 Files Affected:
diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 3d2e203a20dac77..e3a09018ad8b98f 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -841,6 +841,8 @@ struct TargetTypeInfo {
static TargetTypeInfo getTargetTypeInfo(const TargetExtType *Ty) {
LLVMContext &C = Ty->getContext();
StringRef Name = Ty->getName();
+ if (Name.equals("spirv.Image"))
+ return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::CanBeGlobal);
if (Name.startswith("spirv."))
return TargetTypeInfo(PointerType::get(C, 0), TargetExtType::HasZeroInit,
TargetExtType::CanBeGlobal);
diff --git a/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp b/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
index 17083b3846430dd..c0c9d383ac18166 100644
--- a/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
+++ b/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
@@ -423,7 +423,7 @@ TEST(ValueMapperTest, mapValuePoisonWithTypeRemap) {
TEST(ValueMapperTest, mapValueConstantTargetNoneToLayoutTypeNullValue) {
LLVMContext C;
- auto *OldTy = TargetExtType::get(C, "spirv.Image");
+ auto *OldTy = TargetExtType::get(C, "spirv.Event");
Type *NewTy = OldTy->getLayoutType();
TestTypeRemapper TM(NewTy);
|
@jcranmer-intel could you please take a look?
llvm-spirv translator isn't able to handle it due to spec requirement. |
kindly ping @jcranmer-intel |
This change causes a number of the spir-v backend tests to crash:
|
backtrace:
SPIRVEmitIntrinsics pass probably needs fix to not generate ConstantTargetNone for spirv.Image. @bogner WDYT? |
- After #73887, spirv.Image cannot has a zeroinitializer, even though it's only used in metadata to pass down the type info to the backend. Instead of creating zeros, create undef ones of that target-specific types.
The spirv.Image target type no longer supports zeroinitializer value (See llvm/llvm-project#73887) Use undef instead. Add a new clspv::GetDummyValue that returns the zeroinitializer value when it can, and otherwise returns the undef value.
The spirv.Image target type no longer supports zeroinitializer value (See llvm/llvm-project#73887) Use undef instead. Add a new clspv::GetDummyValue that returns the zeroinitializer value when it can, and otherwise returns the undef value.
According to spirv spec, OpConstantNull's result type can't be image
type. So we can't generate zeroinitializer for spirv.Image.