summaryrefslogtreecommitdiffstats
path: root/llvm/unittests/Analysis/ValueTrackingTest.cpp
diff options
context:
space:
mode:
authorSimon Dardis <simon.dardis@mips.com>2017-12-09 23:25:57 +0000
committerSimon Dardis <simon.dardis@mips.com>2017-12-09 23:25:57 +0000
commit70dbd5fbd0a5f869126a944ae7e23058a106f8b7 (patch)
tree6195b209579f6367951d62193713a0f0337f36ec /llvm/unittests/Analysis/ValueTrackingTest.cpp
parentf4e3044db99adc2043bb351da5418ef6af920ca2 (diff)
downloadbcm5719-llvm-70dbd5fbd0a5f869126a944ae7e23058a106f8b7.tar.gz
bcm5719-llvm-70dbd5fbd0a5f869126a944ae7e23058a106f8b7.zip
Infer lowest bits of an integer Multiply when the low bits of the operands are known
When the lowest bits of the operands to an integer multiply are known, the low bits of the result are deducible. Code to deduce known-zero bottom bits already existed, but this change improves on that by deducing known-ones. Patch by: Pedro Ferreira Reviewers: craig.topper, sanjoy, efriedma Differential Revision: https://reviews.llvm.org/D34029 llvm-svn: 320269
Diffstat (limited to 'llvm/unittests/Analysis/ValueTrackingTest.cpp')
-rw-r--r--llvm/unittests/Analysis/ValueTrackingTest.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 3c8ecfbe1ee..cfdf264da31 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -15,6 +15,7 @@
#include "llvm/IR/Module.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/KnownBits.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -258,3 +259,57 @@ TEST(ValueTracking, ComputeNumSignBits_PR32045) {
cast<ReturnInst>(F->getEntryBlock().getTerminator())->getOperand(0);
EXPECT_EQ(ComputeNumSignBits(RVal, M->getDataLayout()), 1u);
}
+
+TEST(ValueTracking, ComputeKnownBits) {
+ StringRef Assembly = "define i32 @f(i32 %a, i32 %b) { "
+ " %ash = mul i32 %a, 8 "
+ " %aad = add i32 %ash, 7 "
+ " %aan = and i32 %aad, 4095 "
+ " %bsh = shl i32 %b, 4 "
+ " %bad = or i32 %bsh, 6 "
+ " %ban = and i32 %bad, 4095 "
+ " %mul = mul i32 %aan, %ban "
+ " ret i32 %mul "
+ "} ";
+
+ LLVMContext Context;
+ SMDiagnostic Error;
+ auto M = parseAssemblyString(Assembly, Error, Context);
+ assert(M && "Bad assembly?");
+
+ auto *F = M->getFunction("f");
+ assert(F && "Bad assembly?");
+
+ auto *RVal =
+ cast<ReturnInst>(F->getEntryBlock().getTerminator())->getOperand(0);
+ auto Known = computeKnownBits(RVal, M->getDataLayout());
+ ASSERT_FALSE(Known.hasConflict());
+ EXPECT_EQ(Known.One.getZExtValue(), 10u);
+ EXPECT_EQ(Known.Zero.getZExtValue(), 4278190085u);
+}
+
+TEST(ValueTracking, ComputeKnownMulBits) {
+ StringRef Assembly = "define i32 @f(i32 %a, i32 %b) { "
+ " %aa = shl i32 %a, 5 "
+ " %bb = shl i32 %b, 5 "
+ " %aaa = or i32 %aa, 24 "
+ " %bbb = or i32 %bb, 28 "
+ " %mul = mul i32 %aaa, %bbb "
+ " ret i32 %mul "
+ "} ";
+
+ LLVMContext Context;
+ SMDiagnostic Error;
+ auto M = parseAssemblyString(Assembly, Error, Context);
+ assert(M && "Bad assembly?");
+
+ auto *F = M->getFunction("f");
+ assert(F && "Bad assembly?");
+
+ auto *RVal =
+ cast<ReturnInst>(F->getEntryBlock().getTerminator())->getOperand(0);
+ auto Known = computeKnownBits(RVal, M->getDataLayout());
+ ASSERT_FALSE(Known.hasConflict());
+ EXPECT_EQ(Known.One.getZExtValue(), 32u);
+ EXPECT_EQ(Known.Zero.getZExtValue(), 95u);
+}
OpenPOWER on IntegriCloud