summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2019-12-27 17:38:18 +0000
committerFlorian Hahn <flo@fhahn.com>2019-12-27 17:38:34 +0000
commitb35c585a9a8185ca7de378a0d45ebb68e385e7a0 (patch)
tree5ca3f0545a4af182a9c86514babc7836a59663c4
parent752220ea2664c814eb1eb046d755fe63ade9c32e (diff)
downloadbcm5719-llvm-b35c585a9a8185ca7de378a0d45ebb68e385e7a0.tar.gz
bcm5719-llvm-b35c585a9a8185ca7de378a0d45ebb68e385e7a0.zip
[ConstantRange] Respect destination bitwidth for cast results.
We returning a full set, we should use ResultBitWidth. Otherwise we might it assertions when the resulting constant ranges are used later on. Reviewers: nikic, spatel, reames Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D71937
-rw-r--r--llvm/lib/IR/ConstantRange.cpp4
-rw-r--r--llvm/unittests/IR/ConstantRangeTest.cpp22
2 files changed, 24 insertions, 2 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index 2a8ea0657db..3d25cb5bfbd 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -641,7 +641,7 @@ ConstantRange ConstantRange::castOp(Instruction::CastOps CastOp,
if (getBitWidth() == ResultBitWidth)
return *this;
else
- return getFull();
+ return getFull(ResultBitWidth);
case Instruction::UIToFP: {
// TODO: use input range if available
auto BW = getBitWidth();
@@ -662,7 +662,7 @@ ConstantRange ConstantRange::castOp(Instruction::CastOps CastOp,
case Instruction::PtrToInt:
case Instruction::AddrSpaceCast:
// Conservatively return getFull set.
- return getFull();
+ return getFull(ResultBitWidth);
};
}
diff --git a/llvm/unittests/IR/ConstantRangeTest.cpp b/llvm/unittests/IR/ConstantRangeTest.cpp
index d8befa88c84..2e5ab82f256 100644
--- a/llvm/unittests/IR/ConstantRangeTest.cpp
+++ b/llvm/unittests/IR/ConstantRangeTest.cpp
@@ -2295,4 +2295,26 @@ TEST_F(ConstantRangeTest, Abs) {
});
}
+TEST_F(ConstantRangeTest, castOps) {
+ ConstantRange A(APInt(16, 66), APInt(16, 128));
+ ConstantRange FpToI8 = A.castOp(Instruction::FPToSI, 8);
+ EXPECT_EQ(8u, FpToI8.getBitWidth());
+ EXPECT_TRUE(FpToI8.isFullSet());
+
+ ConstantRange FpToI16 = A.castOp(Instruction::FPToSI, 16);
+ EXPECT_EQ(16u, FpToI16.getBitWidth());
+ EXPECT_EQ(A, FpToI16);
+
+ ConstantRange FPExtToDouble = A.castOp(Instruction::FPExt, 64);
+ EXPECT_EQ(64u, FPExtToDouble.getBitWidth());
+ EXPECT_TRUE(FPExtToDouble.isFullSet());
+
+ ConstantRange PtrToInt = A.castOp(Instruction::PtrToInt, 64);
+ EXPECT_EQ(64u, PtrToInt.getBitWidth());
+ EXPECT_TRUE(PtrToInt.isFullSet());
+
+ ConstantRange IntToPtr = A.castOp(Instruction::IntToPtr, 64);
+ EXPECT_EQ(64u, IntToPtr.getBitWidth());
+ EXPECT_TRUE(IntToPtr.isFullSet());
+}
} // anonymous namespace
OpenPOWER on IntegriCloud