diff options
| author | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2019-04-15 07:19:11 +0000 |
|---|---|---|
| committer | Bjorn Pettersson <bjorn.a.pettersson@ericsson.com> | 2019-04-15 07:19:11 +0000 |
| commit | 60569363a5895561dd23dfb57b821261f8de35d6 (patch) | |
| tree | 1d869a7d530f3409fa9143bcbd96ccbe2403f694 /llvm/unittests/CodeGen | |
| parent | abd87ff48b9e0f18970cb9b1e7258536cc3004fd (diff) | |
| download | bcm5719-llvm-60569363a5895561dd23dfb57b821261f8de35d6.tar.gz bcm5719-llvm-60569363a5895561dd23dfb57b821261f8de35d6.zip | |
[SelectionDAG] Use KnownBits::computeForAddSub/computeForAddCarry
Summary:
Use KnownBits::computeForAddSub/computeForAddCarry
in SelectionDAG::computeKnownBits when doing value
tracking for addition/subtraction.
This should improve the precision of the known bits,
as we only used to make a simple estimate of known
zeroes. The KnownBits support functions are also
able to deduce bits that are known to be one in the
result.
Reviewers: spatel, RKSimon, nikic, lebedev.ri
Reviewed By: nikic
Subscribers: nikic, javed.absar, lebedev.ri, hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60460
llvm-svn: 358372
Diffstat (limited to 'llvm/unittests/CodeGen')
| -rw-r--r-- | llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp b/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp index ae4c76ecf15..3ac32aebeac 100644 --- a/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp +++ b/llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp @@ -157,4 +157,46 @@ TEST_F(AArch64SelectionDAGTest, SimplifyDemandedVectorElts_EXTRACT_SUBVECTOR) { false); } +// Piggy-backing on the AArch64 tests to verify SelectionDAG::computeKnownBits. +TEST_F(AArch64SelectionDAGTest, ComputeKnownBits_ADD) { + if (!TM) + return; + SDLoc Loc; + auto IntVT = EVT::getIntegerVT(Context, 8); + auto UnknownOp = DAG->getRegister(0, IntVT); + auto Mask = DAG->getConstant(0x8A, Loc, IntVT); + auto N0 = DAG->getNode(ISD::AND, Loc, IntVT, Mask, UnknownOp); + auto N1 = DAG->getConstant(0x55, Loc, IntVT); + auto Op = DAG->getNode(ISD::ADD, Loc, IntVT, N0, N1); + // N0 = ?000?0?0 + // N1 = 01010101 + // => + // Known.One = 01010101 (0x55) + // Known.Zero = 00100000 (0x20) + KnownBits Known = DAG->computeKnownBits(Op); + EXPECT_EQ(Known.Zero, APInt(8, 0x20)); + EXPECT_EQ(Known.One, APInt(8, 0x55)); +} + +// Piggy-backing on the AArch64 tests to verify SelectionDAG::computeKnownBits. +TEST_F(AArch64SelectionDAGTest, ComputeKnownBits_SUB) { + if (!TM) + return; + SDLoc Loc; + auto IntVT = EVT::getIntegerVT(Context, 8); + auto N0 = DAG->getConstant(0x55, Loc, IntVT); + auto UnknownOp = DAG->getRegister(0, IntVT); + auto Mask = DAG->getConstant(0x2e, Loc, IntVT); + auto N1 = DAG->getNode(ISD::AND, Loc, IntVT, Mask, UnknownOp); + auto Op = DAG->getNode(ISD::SUB, Loc, IntVT, N0, N1); + // N0 = 01010101 + // N1 = 00?0???0 + // => + // Known.One = 00000001 (0x1) + // Known.Zero = 10000000 (0x80) + KnownBits Known = DAG->computeKnownBits(Op); + EXPECT_EQ(Known.Zero, APInt(8, 0x80)); + EXPECT_EQ(Known.One, APInt(8, 0x1)); +} + } // end anonymous namespace |

