aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Analysis/ValueTrackingTest.cpp
diff options
context:
space:
mode:
authorDavid Sherwood <david.sherwood@arm.com>2021-09-21 12:11:04 +0100
committerDavid Sherwood <david.sherwood@arm.com>2021-09-24 09:58:10 +0100
commitc2634fc6abe73acf0d9c4421071948e43d96d7eb (patch)
tree2d78cfa450b294803f69fd19dc919e3426c54246 /llvm/unittests/Analysis/ValueTrackingTest.cpp
parent3bad9616aa52aa467e4f1fb5c00abac6acba8471 (diff)
downloadllvm-c2634fc6abe73acf0d9c4421071948e43d96d7eb.zip
llvm-c2634fc6abe73acf0d9c4421071948e43d96d7eb.tar.gz
llvm-c2634fc6abe73acf0d9c4421071948e43d96d7eb.tar.bz2
[Analysis] Fix issues when querying vscale attributes on functions
There are several places in the code that are currently broken as they assume an Instruction always has a parent Function when attempting to get the vscale_range attribute. This patch adds checks that an Instruction has a parent. I've added a test for a parentless @llvm.vscale intrinsic call here: unittests/Analysis/ValueTrackingTest.cpp Differential Revision: https://reviews.llvm.org/D110158
Diffstat (limited to 'llvm/unittests/Analysis/ValueTrackingTest.cpp')
-rw-r--r--llvm/unittests/Analysis/ValueTrackingTest.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index a1dedd8..8d9df97 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -12,6 +12,7 @@
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/Function.h"
+#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/LLVMContext.h"
@@ -1597,6 +1598,22 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAddWithRange) {
EXPECT_EQ(Known.getMaxValue(), 131071);
}
+TEST_F(ComputeKnownBitsTest, ComputeKnownBitsUnknownVScale) {
+ Module M("", Context);
+ IRBuilder<> Builder(Context);
+ Function *TheFn =
+ Intrinsic::getDeclaration(&M, Intrinsic::vscale, {Builder.getInt32Ty()});
+ CallInst *CI = Builder.CreateCall(TheFn, {}, {}, "");
+
+ KnownBits Known = computeKnownBits(CI, M.getDataLayout(), /* Depth */ 0);
+ delete CI;
+
+ // There is no parent function so we cannot look up the vscale_range
+ // attribute to determine the number of bits.
+ EXPECT_EQ(Known.One.getZExtValue(), 0u);
+ EXPECT_EQ(Known.Zero.getZExtValue(), 0u);
+}
+
// 512 + [32, 64) doesn't produce overlapping bits.
// Make sure we get all the individual bits properly.
TEST_F(ComputeKnownBitsTest, ComputeKnownBitsAddWithRangeNoOverlap) {