diff options
author | Kuba Mracek <mracek@apple.com> | 2021-09-13 14:44:49 -0700 |
---|---|---|
committer | Kuba Mracek <mracek@apple.com> | 2021-09-13 15:22:11 -0700 |
commit | e80ee4cbd9a79efa99cabdbb42faba7c7b01e70e (patch) | |
tree | 44bf62747bb88f2317502bd4d78a439736e51b4b /llvm/lib | |
parent | b2032f18c9dec45a9cb4163136fa9dcbe256e772 (diff) | |
download | llvm-e80ee4cbd9a79efa99cabdbb42faba7c7b01e70e.zip llvm-e80ee4cbd9a79efa99cabdbb42faba7c7b01e70e.tar.gz llvm-e80ee4cbd9a79efa99cabdbb42faba7c7b01e70e.tar.bz2 |
[GlobalDCE] In VFE support for relative pointers, allow GEP references to the base symbol
This is for Swift VFE support. In some vtable forms that Swift emits, the "base" of a relative pointer is not the global symbol itself directly, but a GEP into it -- so the pointer is relative to a particular field in the global. So getPointerAtOffset() needs to be able to see through the GEP and allow it in a SUB expression, to correctly recognize the offset as a vtable slot.
Differential Revision: https://reviews.llvm.org/D109169
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/TypeMetadataUtils.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/TypeMetadataUtils.cpp b/llvm/lib/Analysis/TypeMetadataUtils.cpp index c55071a..65fa2bb 100644 --- a/llvm/lib/Analysis/TypeMetadataUtils.cpp +++ b/llvm/lib/Analysis/TypeMetadataUtils.cpp @@ -173,10 +173,19 @@ Constant *llvm::getPointerAtOffset(Constant *I, uint64_t Offset, Module &M, case Instruction::Sub: { auto *Operand0 = cast<Constant>(C->getOperand(0)); auto *Operand1 = cast<Constant>(C->getOperand(1)); - auto *Operand1TargetGlobal = getPointerAtOffset(Operand1, 0, M); + + auto StripGEP = [](Constant *C) { + auto *CE = dyn_cast<ConstantExpr>(C); + if (!CE) + return C; + if (CE->getOpcode() != Instruction::GetElementPtr) + return C; + return CE->getOperand(0); + }; + auto *Operand1TargetGlobal = StripGEP(getPointerAtOffset(Operand1, 0, M)); // Check that in the "sub (@a, @b)" expression, @b points back to the top - // level global that we're processing. Otherwise bail. + // level global (or a GEP thereof) that we're processing. Otherwise bail. if (Operand1TargetGlobal != TopLevelGlobal) return nullptr; |