[llvm] 108989b - [IR] Disallow ZeroInit for spirv.Image (#73887)

via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 18 21:54:30 PST 2023


Author: Wenju He
Date: 2023-12-19T13:54:25+08:00
New Revision: 108989b7176651d7a0f3161a7baba588f7c4ea52

URL: https://github.com/llvm/llvm-project/commit/108989b7176651d7a0f3161a7baba588f7c4ea52
DIFF: https://github.com/llvm/llvm-project/commit/108989b7176651d7a0f3161a7baba588f7c4ea52.diff

LOG: [IR] Disallow ZeroInit for spirv.Image (#73887)

According to spirv spec, OpConstantNull's result type can't be image
type. So we can't generate zeroinitializer for spirv.Image.

Added: 
    

Modified: 
    llvm/lib/IR/Type.cpp
    llvm/unittests/Transforms/Utils/ValueMapperTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp
index 85d779c98a9b14..c59bc3622fde5e 100644
--- a/llvm/lib/IR/Type.cpp
+++ b/llvm/lib/IR/Type.cpp
@@ -834,6 +834,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.starts_with("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 17083b3846430d..c0c9d383ac1816 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);


        


More information about the llvm-commits mailing list