[PATCH] D12958: Refactor computeKnownBits alignment handling code
Artur Pilipenko via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 18 06:01:43 PDT 2015
apilipenko created this revision.
apilipenko added reviewers: hfinkel, reames.
apilipenko added a subscriber: llvm-commits.
This is a preparatory refactoring for using new alignment attributes/metadata (D12844, D12853) in computeKnownBits.
http://reviews.llvm.org/D12958
Files:
lib/Analysis/ValueTracking.cpp
Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -1462,9 +1462,18 @@
return;
}
- // The address of an aligned GlobalValue has trailing zeros.
+ // Start out not knowing anything.
+ KnownZero.clearAllBits(); KnownOne.clearAllBits();
+
+ // Limit search depth.
+ // All recursive calls that increase depth must come after this.
+ if (Depth == MaxDepth)
+ return;
+
+ // If V is a pointer check if we know it's alignment
+ unsigned Align = 0;
if (auto *GO = dyn_cast<GlobalObject>(V)) {
- unsigned Align = GO->getAlignment();
+ Align = GO->getAlignment();
if (Align == 0) {
if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
Type *ObjectType = GVar->getType()->getElementType();
@@ -1479,49 +1488,20 @@
}
}
}
- if (Align > 0)
- KnownZero = APInt::getLowBitsSet(BitWidth,
- countTrailingZeros(Align));
- else
- KnownZero.clearAllBits();
- KnownOne.clearAllBits();
- return;
- }
-
- if (Argument *A = dyn_cast<Argument>(V)) {
- unsigned Align = A->getType()->isPointerTy() ? A->getParamAlignment() : 0;
+ } else if (Argument *A = dyn_cast<Argument>(V)) {
+ Align = A->getType()->isPointerTy() ? A->getParamAlignment() : 0;
if (!Align && A->hasStructRetAttr()) {
// An sret parameter has at least the ABI alignment of the return type.
Type *EltTy = cast<PointerType>(A->getType())->getElementType();
if (EltTy->isSized())
Align = DL.getABITypeAlignment(EltTy);
}
-
- if (Align)
- KnownZero = APInt::getLowBitsSet(BitWidth, countTrailingZeros(Align));
- else
- KnownZero.clearAllBits();
- KnownOne.clearAllBits();
-
- // Don't give up yet... there might be an assumption that provides more
- // information...
- computeKnownBitsFromAssume(V, KnownZero, KnownOne, DL, Depth, Q);
-
- // Or a dominating condition for that matter
- if (EnableDomConditions && Depth <= DomConditionsMaxDepth)
- computeKnownBitsFromDominatingCondition(V, KnownZero, KnownOne, DL,
- Depth, Q);
- return;
}
- // Start out not knowing anything.
- KnownZero.clearAllBits(); KnownOne.clearAllBits();
-
- // Limit search depth.
- // All recursive calls that increase depth must come after this.
- if (Depth == MaxDepth)
- return;
+ // Aligned pointers have trailing zeros
+ if (Align)
+ KnownZero = APInt::getLowBitsSet(BitWidth, countTrailingZeros(Align));
// A weak GlobalAlias is totally unknown. A non-weak GlobalAlias has
// the bits of its aliasee.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D12958.35076.patch
Type: text/x-patch
Size: 2744 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150918/f8d14777/attachment.bin>
More information about the llvm-commits
mailing list