aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBing1 Yu <bing1.yu@intel.com>2023-04-25 15:47:33 +0800
committerBing1 Yu <bing1.yu@intel.com>2023-04-25 15:48:28 +0800
commitc2f29f24c2997952b080ce5b0a5301408d932d28 (patch)
tree97ad56dbad9d4accaf7d06b887a142af76db72f0
parentd6c5804344077a089e584f7a21865eaec24009d4 (diff)
downloadllvm-c2f29f24c2997952b080ce5b0a5301408d932d28.zip
llvm-c2f29f24c2997952b080ce5b0a5301408d932d28.tar.gz
llvm-c2f29f24c2997952b080ce5b0a5301408d932d28.tar.bz2
[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
-rw-r--r--llvm/lib/Transforms/Utils/ValueMapper.cpp2
-rw-r--r--llvm/unittests/Transforms/Utils/ValueMapperTest.cpp15
2 files changed, 17 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 6fd6087..cad523c 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 a4cff86..af20f5a 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