[PATCH] D61607: Introduce an option to stripPointerCasts to force the same bit pattern
Johannes Doerfert via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon May 6 17:09:24 PDT 2019
jdoerfert updated this revision to Diff 198375.
jdoerfert added a comment.
Use a new function for the new behavior
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61607/new/
https://reviews.llvm.org/D61607
Files:
llvm/include/llvm/IR/Value.h
llvm/lib/Analysis/LazyValueInfo.cpp
llvm/lib/IR/Value.cpp
Index: llvm/lib/IR/Value.cpp
===================================================================
--- llvm/lib/IR/Value.cpp
+++ llvm/lib/IR/Value.cpp
@@ -460,6 +460,7 @@
enum PointerStripKind {
PSK_ZeroIndices,
PSK_ZeroIndicesAndAliases,
+ PSK_ZeroIndicesAndAliasesSameBitPattern,
PSK_ZeroIndicesAndAliasesAndInvariantGroups,
PSK_InBoundsConstantIndices,
PSK_InBounds
@@ -479,6 +480,7 @@
if (auto *GEP = dyn_cast<GEPOperator>(V)) {
switch (StripKind) {
case PSK_ZeroIndicesAndAliases:
+ case PSK_ZeroIndicesAndAliasesSameBitPattern:
case PSK_ZeroIndicesAndAliasesAndInvariantGroups:
case PSK_ZeroIndices:
if (!GEP->hasAllZeroIndices())
@@ -494,7 +496,9 @@
break;
}
V = GEP->getPointerOperand();
- } else if (Operator::getOpcode(V) == Instruction::BitCast ||
+ } else if (Operator::getOpcode(V) == Instruction::BitCast) {
+ V = cast<Operator>(V)->getOperand(0);
+ } else if (StripKind != PSK_ZeroIndicesAndAliasesSameBitPattern &&
Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
V = cast<Operator>(V)->getOperand(0);
} else if (auto *GA = dyn_cast<GlobalAlias>(V)) {
@@ -530,6 +534,11 @@
return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(this);
}
+const Value *Value::stripPointerCastsSameBitPattern() const {
+ return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliasesSameBitPattern>(
+ this);
+}
+
const Value *Value::stripPointerCastsNoFollowAliases() const {
return stripPointerCastsAndOffsets<PSK_ZeroIndices>(this);
}
Index: llvm/lib/Analysis/LazyValueInfo.cpp
===================================================================
--- llvm/lib/Analysis/LazyValueInfo.cpp
+++ llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1739,7 +1739,7 @@
// through would still be correct.
const DataLayout &DL = CxtI->getModule()->getDataLayout();
if (V->getType()->isPointerTy() && C->isNullValue() &&
- isKnownNonZero(V->stripPointerCasts(), DL)) {
+ isKnownNonZero(V->stripPointerCastsSameBitPattern(), DL)) {
if (Pred == ICmpInst::ICMP_EQ)
return LazyValueInfo::False;
else if (Pred == ICmpInst::ICMP_NE)
Index: llvm/include/llvm/IR/Value.h
===================================================================
--- llvm/include/llvm/IR/Value.h
+++ llvm/include/llvm/IR/Value.h
@@ -493,7 +493,7 @@
/// swifterror attribute.
bool isSwiftError() const;
- /// Strip off pointer casts, all-zero GEPs, and aliases.
+ /// Strip off pointer casts, all-zero GEPs, address space casts, and aliases.
///
/// Returns the original uncasted value. If this is called on a non-pointer
/// value, it returns 'this'.
@@ -503,6 +503,18 @@
static_cast<const Value *>(this)->stripPointerCasts());
}
+ /// Strip off pointer casts, all-zero GEPs, address space casts, and aliases
+ /// but ensures the bit pattern of the result is equal to the bit pattern of
+ /// the underlying value.
+ ///
+ /// Returns the original uncasted value with the same bit pattern. If this is
+ /// called on a non-pointer value, it returns 'this'.
+ const Value *stripPointerCastsSameBitPattern() const;
+ Value *stripPointerCastsSameBitPattern() {
+ return const_cast<Value *>(
+ static_cast<const Value *>(this)->stripPointerCastsSameBitPattern());
+ }
+
/// Strip off pointer casts, all-zero GEPs, aliases and invariant group
/// info.
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61607.198375.patch
Type: text/x-patch
Size: 3468 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190507/ebf07f78/attachment.bin>
More information about the llvm-commits
mailing list