[PATCH] D97978: [llvm] Change DSOLocalEquivalent type if the underlying global value type changes
Leonard Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 4 13:51:03 PST 2021
leonardchan created this revision.
leonardchan added reviewers: phosek, mcgrathr.
Herald added subscribers: dexonsmith, hiraditya.
leonardchan requested review of this revision.
Herald added a project: LLVM.
We encountered an issue where LTO running on IR that used the `DSOLocalEquivalent` constant would result in bad codegen. The underlying issue was that a DSOLocalEquivalent could have a different type from the underlying GV it's referencing when it should always have the same type as its GV. This updates `DSOLocalEquivalent::handleOperandChangeImpl` to change the type if the GV type changes.
This also caught an issue where the `ValueMapper` wasn't properly handling `DSOLocalEquivalent`, so this just adds the machinery for handling it. This part is mostly mechanical.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D97978
Files:
llvm/lib/IR/Constants.cpp
llvm/lib/Transforms/Utils/ValueMapper.cpp
Index: llvm/lib/Transforms/Utils/ValueMapper.cpp
===================================================================
--- llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -412,6 +412,20 @@
if (BlockAddress *BA = dyn_cast<BlockAddress>(C))
return mapBlockAddress(*BA);
+ if (const auto *Equiv = dyn_cast<DSOLocalEquivalent>(C)) {
+ auto *Val = mapValue(Equiv->getGlobalValue());
+ GlobalValue *GV = dyn_cast<GlobalValue>(Val);
+ if (GV)
+ return getVM()[Equiv] = DSOLocalEquivalent::get(GV);
+
+ auto *Func = cast<Function>(Val->stripPointerCastsAndAliases());
+ Type *NewTy = Equiv->getType();
+ if (TypeMapper)
+ NewTy = TypeMapper->remapType(NewTy);
+ return getVM()[Equiv] = llvm::ConstantExpr::getBitCast(
+ DSOLocalEquivalent::get(Func), NewTy);
+ }
+
auto mapValueOrNull = [this](Value *V) {
auto Mapped = mapValue(V);
assert((Mapped || (Flags & RF_NullMapMissingGlobalValues)) &&
Index: llvm/lib/IR/Constants.cpp
===================================================================
--- llvm/lib/IR/Constants.cpp
+++ llvm/lib/IR/Constants.cpp
@@ -1908,6 +1908,12 @@
getContext().pImpl->DSOLocalEquivalents.erase(getGlobalValue());
NewEquiv = this;
setOperand(0, Func);
+
+ if (Func->getType() != getType()) {
+ // It is ok to mutate the type here because this constant should always
+ // reflect the type of the function it's holding.
+ mutateType(Func->getType());
+ }
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D97978.328297.patch
Type: text/x-patch
Size: 1530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210304/2ac081a4/attachment.bin>
More information about the llvm-commits
mailing list