llvm.org GIT mirror llvm / bd19ebc
GlobalISel: Add another overload of buildUnmerge It's annoying to have to create an array of the result type, particularly when you don't care about the size of the value. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357763 91177308-0d34-0410-b5e6-96231b3b80d8 Matt Arsenault 7 months ago
3 changed file(s) with 32 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
730730 MachineInstrBuilder buildUnmerge(ArrayRef Res, const SrcOp &Op);
731731 MachineInstrBuilder buildUnmerge(ArrayRef Res, const SrcOp &Op);
732732
733 /// Build and insert an unmerge of \p Res sized pieces to cover \p Op
734 MachineInstrBuilder buildUnmerge(LLT Res, const SrcOp &Op);
735
733736 /// Build and insert \p Res = G_BUILD_VECTOR \p Op0, ...
734737 ///
735738 /// G_BUILD_VECTOR creates a vector value from multiple scalar registers.
544544 // sufficiently large SmallVector to not go through the heap.
545545 SmallVector TmpVec(Res.begin(), Res.end());
546546 return buildInstr(TargetOpcode::G_UNMERGE_VALUES, TmpVec, Op);
547 }
548
549 MachineInstrBuilder MachineIRBuilder::buildUnmerge(LLT Res,
550 const SrcOp &Op) {
551 unsigned NumReg = Op.getLLTTy(*getMRI()).getSizeInBits() / Res.getSizeInBits();
552 SmallVector TmpVec;
553 for (unsigned I = 0; I != NumReg; ++I)
554 TmpVec.push_back(getMRI()->createGenericVirtualRegister(Res));
555 return buildUnmerge(TmpVec, Op);
547556 }
548557
549558 MachineInstrBuilder MachineIRBuilder::buildUnmerge(ArrayRef Res,
8989
9090 EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
9191 }
92
93 TEST_F(GISelMITest, BuildUnmerge) {
94 if (!TM)
95 return;
96
97 SmallVector Copies;
98 collectCopies(Copies, MF);
99 B.buildUnmerge(LLT::scalar(32), Copies[0]);
100 B.buildUnmerge(LLT::scalar(16), Copies[1]);
101
102 auto CheckStr = R"(
103 ; CHECK: [[COPY0:%[0-9]+]]:_(s64) = COPY $x0
104 ; CHECK: [[COPY1:%[0-9]+]]:_(s64) = COPY $x1
105 ; CHECK: [[UNMERGE32_0:%[0-9]+]]:_(s32), [[UNMERGE32_1:%[0-9]+]]:_(s32) = G_UNMERGE_VALUES [[COPY0]]
106 ; CHECK: [[UNMERGE16_0:%[0-9]+]]:_(s16), [[UNMERGE16_1:%[0-9]+]]:_(s16), [[UNMERGE16_2:%[0-9]+]]:_(s16), [[UNMERGE16_3:%[0-9]+]]:_(s16) = G_UNMERGE_VALUES [[COPY1]]
107
108 )";
109
110 EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
111 }