diff options
author | Chang-Sun Lin, Jr <chang-sun.lin.jr@intel.com> | 2021-08-02 22:18:13 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-08-02 22:20:17 +0200 |
commit | b58eda39eb1fcb7df942c8569d031a342fa1308d (patch) | |
tree | 43527c1ea42f217403ec9b1a30a4c436bd1a64d6 /llvm/unittests/Analysis/ValueTrackingTest.cpp | |
parent | 739efad3f6e36282b7d3a4c76802424473249b41 (diff) | |
download | llvm-b58eda39eb1fcb7df942c8569d031a342fa1308d.zip llvm-b58eda39eb1fcb7df942c8569d031a342fa1308d.tar.gz llvm-b58eda39eb1fcb7df942c8569d031a342fa1308d.tar.bz2 |
[ValueTracking] Fix computeConstantRange to use "may" instead of "always" semantics for llvm.assume
ValueTracking should allow for value ranges that may satisfy
llvm.assume, instead of restricting the ranges only to values that
will always satisfy the condition.
Differential Revision: https://reviews.llvm.org/D107298
Diffstat (limited to 'llvm/unittests/Analysis/ValueTrackingTest.cpp')
-rw-r--r-- | llvm/unittests/Analysis/ValueTrackingTest.cpp | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp index e8b1a18..c07c76c 100644 --- a/llvm/unittests/Analysis/ValueTrackingTest.cpp +++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp @@ -2073,7 +2073,7 @@ TEST_F(ValueTrackingTest, ComputeConstantRange) { // * x.1 >= 5 // * x.2 < x.1 // - // stride = [0, 5) + // stride = [0, -1) auto M = parseModule(R"( declare void @llvm.assume(i1) @@ -2088,17 +2088,45 @@ TEST_F(ValueTrackingTest, ComputeConstantRange) { Function *F = M->getFunction("test"); AssumptionCache AC(*F); + Value *X1 = &*(F->arg_begin()); Value *X2 = &*std::next(F->arg_begin()); Instruction *I = &findInstructionByName(F, "stride.plus.one"); - ConstantRange CR1 = computeConstantRange(X2, true, &AC, I); - EXPECT_EQ(0, CR1.getLower()); - EXPECT_EQ(5, CR1.getUpper()); + ConstantRange CR1 = computeConstantRange(X1, true, &AC, I); + ConstantRange CR2 = computeConstantRange(X2, true, &AC, I); + + EXPECT_EQ(5, CR1.getLower()); + EXPECT_EQ(0, CR1.getUpper()); + + EXPECT_EQ(0, CR2.getLower()); + EXPECT_EQ(0xffffffff, CR2.getUpper()); // Check the depth cutoff results in a conservative result (full set) by // passing Depth == MaxDepth == 6. - ConstantRange CR2 = computeConstantRange(X2, true, &AC, I, 6); - EXPECT_TRUE(CR2.isFullSet()); + ConstantRange CR3 = computeConstantRange(X2, true, &AC, I, 6); + EXPECT_TRUE(CR3.isFullSet()); + } + { + // Assumptions: + // * x.2 <= x.1 + auto M = parseModule(R"( + declare void @llvm.assume(i1) + + define i32 @test(i32 %x.1, i32 %x.2) { + %lt = icmp ule i32 %x.2, %x.1 + call void @llvm.assume(i1 %lt) + %stride.plus.one = add nsw nuw i32 %x.1, 1 + ret i32 %stride.plus.one + })"); + Function *F = M->getFunction("test"); + + AssumptionCache AC(*F); + Value *X2 = &*std::next(F->arg_begin()); + + Instruction *I = &findInstructionByName(F, "stride.plus.one"); + ConstantRange CR1 = computeConstantRange(X2, true, &AC, I); + // If we don't know the value of x.2, we don't know the value of x.1. + EXPECT_TRUE(CR1.isFullSet()); } } |