|
6 | 6 | //
|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 |
|
| 9 | +#include "llvm/Analysis/MemoryLocation.h" |
9 | 10 | #include "llvm/Analysis/OptimizationRemarkEmitter.h"
|
10 | 11 | #include "llvm/AsmParser/Parser.h"
|
11 | 12 | #include "llvm/CodeGen/MachineModuleInfo.h"
|
12 | 13 | #include "llvm/CodeGen/SelectionDAG.h"
|
13 | 14 | #include "llvm/CodeGen/TargetLowering.h"
|
| 15 | +#include "llvm/IR/MDBuilder.h" |
14 | 16 | #include "llvm/MC/TargetRegistry.h"
|
15 | 17 | #include "llvm/Support/KnownBits.h"
|
16 | 18 | #include "llvm/Support/SourceMgr.h"
|
@@ -728,4 +730,70 @@ TEST_F(AArch64SelectionDAGTest, ReplaceAllUsesWith) {
|
728 | 730 | EXPECT_EQ(DAG->getPCSections(New.getNode()), MD);
|
729 | 731 | }
|
730 | 732 |
|
| 733 | +TEST_F(AArch64SelectionDAGTest, computeKnownBits_extload_known01) { |
| 734 | + SDLoc Loc; |
| 735 | + auto Int8VT = EVT::getIntegerVT(Context, 8); |
| 736 | + auto Int32VT = EVT::getIntegerVT(Context, 32); |
| 737 | + auto Int64VT = EVT::getIntegerVT(Context, 64); |
| 738 | + auto Ptr = DAG->getConstant(0, Loc, Int64VT); |
| 739 | + auto PtrInfo = |
| 740 | + MachinePointerInfo::getFixedStack(DAG->getMachineFunction(), 0); |
| 741 | + AAMDNodes AA; |
| 742 | + MDBuilder MDHelper(*DAG->getContext()); |
| 743 | + MDNode *Range = MDHelper.createRange(APInt(8, 0), APInt(8, 2)); |
| 744 | + MachineMemOperand *MMO = DAG->getMachineFunction().getMachineMemOperand( |
| 745 | + PtrInfo, MachineMemOperand::MOLoad, 8, Align(8), AA, Range); |
| 746 | + |
| 747 | + auto ALoad = DAG->getExtLoad(ISD::EXTLOAD, Loc, Int32VT, DAG->getEntryNode(), |
| 748 | + Ptr, Int8VT, MMO); |
| 749 | + KnownBits Known = DAG->computeKnownBits(ALoad); |
| 750 | + EXPECT_EQ(Known.Zero, APInt(32, 0xfe)); |
| 751 | + EXPECT_EQ(Known.One, APInt(32, 0)); |
| 752 | + |
| 753 | + auto ZLoad = DAG->getExtLoad(ISD::ZEXTLOAD, Loc, Int32VT, DAG->getEntryNode(), |
| 754 | + Ptr, Int8VT, MMO); |
| 755 | + Known = DAG->computeKnownBits(ZLoad); |
| 756 | + EXPECT_EQ(Known.Zero, APInt(32, 0xfffffffe)); |
| 757 | + EXPECT_EQ(Known.One, APInt(32, 0)); |
| 758 | + |
| 759 | + auto SLoad = DAG->getExtLoad(ISD::SEXTLOAD, Loc, Int32VT, DAG->getEntryNode(), |
| 760 | + Ptr, Int8VT, MMO); |
| 761 | + Known = DAG->computeKnownBits(SLoad); |
| 762 | + EXPECT_EQ(Known.Zero, APInt(32, 0xfffffffe)); |
| 763 | + EXPECT_EQ(Known.One, APInt(32, 0)); |
| 764 | +} |
| 765 | + |
| 766 | +TEST_F(AArch64SelectionDAGTest, computeKnownBits_extload_knownnegative) { |
| 767 | + SDLoc Loc; |
| 768 | + auto Int8VT = EVT::getIntegerVT(Context, 8); |
| 769 | + auto Int32VT = EVT::getIntegerVT(Context, 32); |
| 770 | + auto Int64VT = EVT::getIntegerVT(Context, 64); |
| 771 | + auto Ptr = DAG->getConstant(0, Loc, Int64VT); |
| 772 | + auto PtrInfo = |
| 773 | + MachinePointerInfo::getFixedStack(DAG->getMachineFunction(), 0); |
| 774 | + AAMDNodes AA; |
| 775 | + MDBuilder MDHelper(*DAG->getContext()); |
| 776 | + MDNode *Range = MDHelper.createRange(APInt(8, 0xf0), APInt(8, 0xff)); |
| 777 | + MachineMemOperand *MMO = DAG->getMachineFunction().getMachineMemOperand( |
| 778 | + PtrInfo, MachineMemOperand::MOLoad, 8, Align(8), AA, Range); |
| 779 | + |
| 780 | + auto ALoad = DAG->getExtLoad(ISD::EXTLOAD, Loc, Int32VT, DAG->getEntryNode(), |
| 781 | + Ptr, Int8VT, MMO); |
| 782 | + KnownBits Known = DAG->computeKnownBits(ALoad); |
| 783 | + EXPECT_EQ(Known.Zero, APInt(32, 0)); |
| 784 | + EXPECT_EQ(Known.One, APInt(32, 0xf0)); |
| 785 | + |
| 786 | + auto ZLoad = DAG->getExtLoad(ISD::ZEXTLOAD, Loc, Int32VT, DAG->getEntryNode(), |
| 787 | + Ptr, Int8VT, MMO); |
| 788 | + Known = DAG->computeKnownBits(ZLoad); |
| 789 | + EXPECT_EQ(Known.Zero, APInt(32, 0xffffff00)); |
| 790 | + EXPECT_EQ(Known.One, APInt(32, 0x000000f0)); |
| 791 | + |
| 792 | + auto SLoad = DAG->getExtLoad(ISD::SEXTLOAD, Loc, Int32VT, DAG->getEntryNode(), |
| 793 | + Ptr, Int8VT, MMO); |
| 794 | + Known = DAG->computeKnownBits(SLoad); |
| 795 | + EXPECT_EQ(Known.Zero, APInt(32, 0)); |
| 796 | + EXPECT_EQ(Known.One, APInt(32, 0xfffffff0)); |
| 797 | +} |
| 798 | + |
731 | 799 | } // end namespace llvm
|
0 commit comments