[PATCH] D148774: [ValueMapper] allow mapping ConstantTargetNone to its layout type

Bing Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 25 00:48:41 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc2f29f24c299: [ValueMapper] allow mapping ConstantTargetNone to its layout type (authored by yubing).
Herald added a subscriber: hoy.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D148774/new/

https://reviews.llvm.org/D148774

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


Index: llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
===================================================================
--- llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
+++ llvm/unittests/Transforms/Utils/ValueMapperTest.cpp
@@ -421,4 +421,19 @@
   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
Index: llvm/lib/Transforms/Utils/ValueMapper.cpp
===================================================================
--- llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -529,6 +529,8 @@
     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));
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148774.516690.patch
Type: text/x-patch
Size: 1467 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230425/4f906df0/attachment.bin>


More information about the llvm-commits mailing list