aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorDavid Green <david.green@arm.com>2021-11-05 14:41:37 +0000
committerDavid Green <david.green@arm.com>2021-11-05 14:41:37 +0000
commit61225c081858efe55dfc7051b338c797fab07cff (patch)
treea0c07cec2d91d002a9c2b56febac22d5ecbbf52c /llvm/lib/Analysis/ValueTracking.cpp
parent9e6506299a10884ae20a51d8c91a812a73c16433 (diff)
downloadllvm-61225c081858efe55dfc7051b338c797fab07cff.zip
llvm-61225c081858efe55dfc7051b338c797fab07cff.tar.gz
llvm-61225c081858efe55dfc7051b338c797fab07cff.tar.bz2
[ValueTracking][InstCombine] Introduce and use ComputeMinSignedBits
This introduces a new ComputeMinSignedBits method for ValueTracking that returns the BitWidth - SignBits + 1 from ComputeSignBits, and represents the minimum bit size for the value as a signed integer. Similar to the existing APInt::getMinSignedBits method, this can make some of the reasoning around ComputeSignBits more natural. See https://reviews.llvm.org/D112298
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 0585a63..0e07017 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -396,6 +396,14 @@ unsigned llvm::ComputeNumSignBits(const Value *V, const DataLayout &DL,
V, Depth, Query(DL, AC, safeCxtI(V, CxtI), DT, UseInstrInfo));
}
+unsigned llvm::ComputeMinSignedBits(const Value *V, const DataLayout &DL,
+ unsigned Depth, AssumptionCache *AC,
+ const Instruction *CxtI,
+ const DominatorTree *DT) {
+ unsigned SignBits = ComputeNumSignBits(V, DL, Depth, AC, CxtI, DT);
+ return V->getType()->getScalarSizeInBits() - SignBits + 1;
+}
+
static void computeKnownBitsAddSub(bool Add, const Value *Op0, const Value *Op1,
bool NSW, const APInt &DemandedElts,
KnownBits &KnownOut, KnownBits &Known2,