diff options
Diffstat (limited to 'llvm/lib/IR/Value.cpp')
-rw-r--r-- | llvm/lib/IR/Value.cpp | 55 |
1 files changed, 28 insertions, 27 deletions
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp index 02c16e2..129ca4a 100644 --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -582,16 +582,11 @@ void Value::replaceUsesWithIf(Value *New, } } -/// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB +/// Replace debug record uses of MetadataAsValue(ValueAsMetadata(V)) outside BB /// with New. static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB) { - SmallVector<DbgVariableIntrinsic *> DbgUsers; SmallVector<DbgVariableRecord *> DPUsers; - findDbgUsers(DbgUsers, V, &DPUsers); - for (auto *DVI : DbgUsers) { - if (DVI->getParent() != BB) - DVI->replaceVariableLocationOp(V, New); - } + findDbgUsers(V, DPUsers); for (auto *DVR : DPUsers) { DbgMarker *Marker = DVR->getMarker(); if (Marker->getParent() != BB) @@ -752,28 +747,34 @@ const Value *Value::stripAndAccumulateConstantOffsets( // means when we construct GEPOffset, we need to use the size // of GEP's pointer type rather than the size of the original // pointer type. - APInt GEPOffset(DL.getIndexTypeSizeInBits(V->getType()), 0); - if (!GEP->accumulateConstantOffset(DL, GEPOffset, ExternalAnalysis)) - return V; - - // Stop traversal if the pointer offset wouldn't fit in the bit-width - // provided by the Offset argument. This can happen due to AddrSpaceCast - // stripping. - if (GEPOffset.getSignificantBits() > BitWidth) - return V; - - // External Analysis can return a result higher/lower than the value - // represents. We need to detect overflow/underflow. - APInt GEPOffsetST = GEPOffset.sextOrTrunc(BitWidth); - if (!ExternalAnalysis) { - Offset += GEPOffsetST; + unsigned CurBitWidth = DL.getIndexTypeSizeInBits(V->getType()); + if (CurBitWidth == BitWidth) { + if (!GEP->accumulateConstantOffset(DL, Offset, ExternalAnalysis)) + return V; } else { - bool Overflow = false; - APInt OldOffset = Offset; - Offset = Offset.sadd_ov(GEPOffsetST, Overflow); - if (Overflow) { - Offset = OldOffset; + APInt GEPOffset(CurBitWidth, 0); + if (!GEP->accumulateConstantOffset(DL, GEPOffset, ExternalAnalysis)) + return V; + + // Stop traversal if the pointer offset wouldn't fit in the bit-width + // provided by the Offset argument. This can happen due to AddrSpaceCast + // stripping. + if (GEPOffset.getSignificantBits() > BitWidth) return V; + + // External Analysis can return a result higher/lower than the value + // represents. We need to detect overflow/underflow. + APInt GEPOffsetST = GEPOffset.sextOrTrunc(BitWidth); + if (!ExternalAnalysis) { + Offset += GEPOffsetST; + } else { + bool Overflow = false; + APInt OldOffset = Offset; + Offset = Offset.sadd_ov(GEPOffsetST, Overflow); + if (Overflow) { + Offset = OldOffset; + return V; + } } } V = GEP->getPointerOperand(); |