[llvm] c2f29f2 - [ValueMapper] allow mapping ConstantTargetNone to its layout type

Bing1 Yu via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 25 00:48:38 PDT 2023


Author: Bing1 Yu
Date: 2023-04-25T15:48:28+08:00
New Revision: c2f29f24c2997952b080ce5b0a5301408d932d28

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

LOG: [ValueMapper] allow mapping ConstantTargetNone to its layout type

zeroinitializer is allowed for spirv TargetExtType.
This PR allows ValueMapper to map TargetExtType ConstantTargetNone to '0' constant of its layout type.

Reviewed By: jcranmer-intel

Differential Revision: https://reviews.llvm.org/D148774

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/ValueMapper.cpp
    llvm/unittests/Transforms/Utils/ValueMapperTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 6fd608737ec40..cad523ce9e3eb 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -529,6 +529,8 @@ Value *Mapper::mapValue(const Value *V) {
     return getVM()[V] = UndefValue::get(NewTy);
   if (isa<ConstantAggregateZero>(C))
     return getVM()[V] = ConstantAggregateZero::get(NewTy);
+  if (isa<ConstantTargetNone>(C))
+    return getVM()[V] = Constant::getNullValue(NewTy);
   assert(isa<ConstantPointerNull>(C));
   return getVM()[V] = ConstantPointerNull::get(cast<PointerType>(NewTy));
 }

diff  --git a/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp b/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
index a4cff86f533cf..af20f5af36bb4 100644
--- a/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
+++ b/llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
@@ -421,4 +421,19 @@ TEST(ValueMapperTest, mapValuePoisonWithTypeRemap) {
   EXPECT_EQ(NewPoison, Mapper.mapValue(*OldPoison));
 }
 
+TEST(ValueMapperTest, mapValueConstantTargetNoneToLayoutTypeNullValue) {
+  LLVMContext C;
+  auto *OldTy = TargetExtType::get(C, "spirv.Image");
+  Type *NewTy = OldTy->getLayoutType();
+
+  TestTypeRemapper TM(NewTy);
+  ValueToValueMapTy VM;
+  ValueMapper Mapper(VM, RF_None, &TM);
+
+  // Check that ConstantTargetNone is mapped to '0' constant of its layout type.
+  auto *OldConstant = ConstantTargetNone::get(OldTy);
+  auto *NewConstant = Constant::getNullValue(NewTy);
+  EXPECT_EQ(NewConstant, Mapper.mapValue(*OldConstant));
+}
+
 } // end namespace


        


More information about the llvm-commits mailing list