aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/ValueMapper.cpp
diff options
context:
space:
mode:
authorLeonard Chan <leonardchan@google.com>2021-03-05 16:11:01 -0800
committerLeonard Chan <leonardchan@google.com>2021-03-09 15:09:48 -0800
commitcf371573b0b841db96df729e5b61c6a6f36c17d2 (patch)
treee2e6d137ee7ab8c7f1ce1c56993f859b92c86973 /llvm/lib/Transforms/Utils/ValueMapper.cpp
parenta776ecb6c2b83454f4cd22a0e302aef558381dab (diff)
downloadllvm-cf371573b0b841db96df729e5b61c6a6f36c17d2.zip
llvm-cf371573b0b841db96df729e5b61c6a6f36c17d2.tar.gz
llvm-cf371573b0b841db96df729e5b61c6a6f36c17d2.tar.bz2
[llvm] Change DSOLocalEquivalent type if the underlying global value type changes
We encountered an issue where LTO running on IR that used the DSOLocalEquivalent constant would result in bad codegen. The underlying issue was ValueMapper wasn't properly handling DSOLocalEquivalent, so this just adds the machinery for handling it. This code path is triggered by a fix to DSOLocalEquivalent::handleOperandChangeImpl where DSOLocalEquivalent could potentially not have the same type as its underlying GV. This updates DSOLocalEquivalent::handleOperandChangeImpl to change the type if the GV type changes and handles this constant in ValueMapper. Differential Revision: https://reviews.llvm.org/D97978
Diffstat (limited to 'llvm/lib/Transforms/Utils/ValueMapper.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/ValueMapper.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index d0ec368..46ba2e7 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -432,6 +432,20 @@ Value *Mapper::mapValue(const Value *V) {
if (BlockAddress *BA = dyn_cast<BlockAddress>(C))
return mapBlockAddress(*BA);
+ if (const auto *E = dyn_cast<DSOLocalEquivalent>(C)) {
+ auto *Val = mapValue(E->getGlobalValue());
+ GlobalValue *GV = dyn_cast<GlobalValue>(Val);
+ if (GV)
+ return getVM()[E] = DSOLocalEquivalent::get(GV);
+
+ auto *Func = cast<Function>(Val->stripPointerCastsAndAliases());
+ Type *NewTy = E->getType();
+ if (TypeMapper)
+ NewTy = TypeMapper->remapType(NewTy);
+ return getVM()[E] = llvm::ConstantExpr::getBitCast(
+ DSOLocalEquivalent::get(Func), NewTy);
+ }
+
auto mapValueOrNull = [this](Value *V) {
auto Mapped = mapValue(V);
assert((Mapped || (Flags & RF_NullMapMissingGlobalValues)) &&