[llvm] a56803b - [Analysis] fix cast in ValueTracking to allow constant expression
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 20 14:22:57 PST 2021
Author: Sanjay Patel
Date: 2021-12-20T17:16:47-05:00
New Revision: a56803b8f8df4f8d866f91d354b82ee9b62e9a60
URL: https://github.com/llvm/llvm-project/commit/a56803b8f8df4f8d866f91d354b82ee9b62e9a60
DIFF: https://github.com/llvm/llvm-project/commit/a56803b8f8df4f8d866f91d354b82ee9b62e9a60.diff
LOG: [Analysis] fix cast in ValueTracking to allow constant expression
The test would crash because a non-instruction negate op made it in here.
Fixes #51506
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/unittests/Analysis/ValueTrackingTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 2585961977964..fc378f97de0b1 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -1154,7 +1154,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
// If the negate has an NSW flag we can assume the sign bit of the result
// will be 0 because that makes abs(INT_MIN) undefined.
if (match(RHS, m_Neg(m_Specific(LHS))) &&
- Q.IIQ.hasNoSignedWrap(cast<Instruction>(RHS)))
+ Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(RHS)))
Known.Zero.setSignBit();
}
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 593100cbcd434..0104d321f2c94 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -1711,6 +1711,20 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownBitsGEPWithRangeNoOverlap) {
EXPECT_EQ(Known.getMaxValue(), 575);
}
+TEST_F(ComputeKnownBitsTest, ComputeKnownBitsCrash) {
+ parseAssembly(
+ "@g.a = external global i16, align 1\n"
+ "define i16 @test(i16 %i) {\n"
+ "entry:\n"
+ " %0 = icmp slt i16 sub (i16 0, i16 trunc (i32 udiv (i32 ptrtoint (i16* @g.a to i32), i32 -1) to i16)), 0\n"
+ " %A = select i1 %0, i16 trunc (i32 udiv (i32 ptrtoint (i16* @g.a to i32), i32 -1) to i16), i16 sub (i16 0, i16 trunc (i32 udiv (i32 ptrtoint (i16* @g.a to i32), i32 -1) to i16))\n"
+ " ret i16 %A\n"
+ "}\n");
+ AssumptionCache AC(*F);
+ KnownBits Known = computeKnownBits(
+ A, M->getDataLayout(), /* Depth */ 0, &AC, F->front().getTerminator());
+}
+
class IsBytewiseValueTest : public ValueTrackingTest,
public ::testing::WithParamInterface<
std::pair<const char *, const char *>> {
More information about the llvm-commits
mailing list