diff options
author | Craig Topper <craig.topper@gmail.com> | 2017-04-26 16:39:58 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2017-04-26 16:39:58 +0000 |
commit | b45eabcf82da2360b4243c820cd32b706f671c1a (patch) | |
tree | 472f7d59139627ccf935d11f6700cc226a3d4534 /llvm/lib/Analysis/Lint.cpp | |
parent | eec01adde3ac789fe5e032ce34da3b2266830308 (diff) | |
download | bcm5719-llvm-b45eabcf82da2360b4243c820cd32b706f671c1a.tar.gz bcm5719-llvm-b45eabcf82da2360b4243c820cd32b706f671c1a.zip |
[ValueTracking] Introduce a KnownBits struct to wrap the two APInts for computeKnownBits
This patch introduces a new KnownBits struct that wraps the two APInt used by computeKnownBits. This allows us to treat them as more of a unit.
Initially I've just altered the signatures of computeKnownBits and InstCombine's simplifyDemandedBits to pass a KnownBits reference instead of two separate APInt references. I'll do similar to the SelectionDAG version of computeKnownBits/simplifyDemandedBits as a separate patch.
I've added a constructor that allows initializing both APInts to the same bit width with a starting value of 0. This reduces the repeated pattern of initializing both APInts. Once place default constructed the APInts so I added a default constructor for those cases.
Going forward I would like to add more methods that will work on the pairs. For example trunc, zext, and sext occur on both APInts together in several places. We should probably add a clear method that can be used to clear both pieces. Maybe a method to check for conflicting information. A method to return (Zero|One) so we don't write it out everywhere. Maybe a method for (Zero|One).isAllOnesValue() to determine if all bits are known. I'm sure there are many other methods we can come up with.
Differential Revision: https://reviews.llvm.org/D32376
llvm-svn: 301432
Diffstat (limited to 'llvm/lib/Analysis/Lint.cpp')
-rw-r--r-- | llvm/lib/Analysis/Lint.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/llvm/lib/Analysis/Lint.cpp b/llvm/lib/Analysis/Lint.cpp index 2ca46b1fe87..0f04af54cdc 100644 --- a/llvm/lib/Analysis/Lint.cpp +++ b/llvm/lib/Analysis/Lint.cpp @@ -70,6 +70,7 @@ #include "llvm/Pass.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/KnownBits.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include <cassert> @@ -534,10 +535,9 @@ static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, VectorType *VecTy = dyn_cast<VectorType>(V->getType()); if (!VecTy) { unsigned BitWidth = V->getType()->getIntegerBitWidth(); - APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0); - computeKnownBits(V, KnownZero, KnownOne, DL, 0, AC, - dyn_cast<Instruction>(V), DT); - return KnownZero.isAllOnesValue(); + KnownBits Known(BitWidth); + computeKnownBits(V, Known, DL, 0, AC, dyn_cast<Instruction>(V), DT); + return Known.Zero.isAllOnesValue(); } // Per-component check doesn't work with zeroinitializer @@ -556,9 +556,9 @@ static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, if (isa<UndefValue>(Elem)) return true; - APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0); - computeKnownBits(Elem, KnownZero, KnownOne, DL); - if (KnownZero.isAllOnesValue()) + KnownBits Known(BitWidth); + computeKnownBits(Elem, Known, DL); + if (Known.Zero.isAllOnesValue()) return true; } |