[PATCH] D148774: [ValueMapper] allow mapping ConstantTargetNone to its layout type
Wenju He via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 19 19:32:41 PDT 2023
wenju created this revision.
wenju added a reviewer: jcranmer-intel.
Herald added a subscriber: hiraditya.
Herald added a project: All.
wenju requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
zeroinitializer is allowed for spirv TargetExtType.
This PR allows ValueMapper to map TargetExtType ConstantTargetNone to '0' constant of its layout type.
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.515182.patch
Type: text/x-patch
Size: 1467 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230420/82396e55/attachment.bin>
More information about the llvm-commits
mailing list