From aead0cfbc4ff0a9a40bab2836d39bb8645d49351 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 13 Apr 2021 14:46:21 -0400 Subject: [PATCH] [ValueTracking] add unit test for isKnownNonZero(); NFC We call various value tracking APIs from within -instsimplify, so I don't think this is visible in a larger test. --- unittests/Analysis/ValueTrackingTest.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/unittests/Analysis/ValueTrackingTest.cpp b/unittests/Analysis/ValueTrackingTest.cpp index 93bb2635b24..85678bb6653 100644 --- a/unittests/Analysis/ValueTrackingTest.cpp +++ b/unittests/Analysis/ValueTrackingTest.cpp @@ -1173,6 +1173,27 @@ TEST_F(ComputeKnownBitsTest, ComputeKnownMulBits) { expectKnownBits(/*zero*/ 95u, /*one*/ 32u); } +TEST_F(ValueTrackingTest, isNonZeroRecurrence) { + parseAssembly(R"( + define i1 @test(i8 %n, i8 %r) { + entry: + br label %loop + loop: + %p = phi i8 [ -1, %entry ], [ %next, %loop ] + %next = add nsw i8 %p, -1 + %cmp1 = icmp eq i8 %p, %n + br i1 %cmp1, label %exit, label %loop + exit: + %A = or i8 %p, %r + %CxtI = icmp eq i8 %A, 0 + ret i1 %CxtI + } + )"); + DataLayout DL = M->getDataLayout(); + AssumptionCache AC(*F); + EXPECT_FALSE(isKnownNonZero(A, DL, 0, &AC, CxtI)); +} + TEST_F(ValueTrackingTest, KnownNonZeroFromDomCond) { parseAssembly(R"( declare i8* @f_i8()