diff --git a/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h b/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h --- a/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h @@ -300,7 +300,7 @@ for (unsigned i = 0; i < NumSrcs; ++i) SrcRegs[i] = SrcMerge->getSourceReg(i); - Builder.buildMerge(DstReg, SrcRegs); + Builder.buildMergeLikeOp(DstReg, SrcRegs); UpdatedDefs.push_back(DstReg); } else { // Unable to combine @@ -932,7 +932,7 @@ } MIB.setInstrAndDebugLoc(MI); - MIB.buildMerge(Dst, ConcatSources); + MIB.buildMergeLikeOp(Dst, ConcatSources); DeadInsts.push_back(&MI); return true; } @@ -1099,7 +1099,7 @@ Regs.push_back(MergeI->getOperand(Idx).getReg()); Register DefReg = MI.getReg(DefIdx); - Builder.buildMerge(DefReg, Regs); + Builder.buildMergeLikeOp(DefReg, Regs); UpdatedDefs.push_back(DefReg); } diff --git a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h --- a/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h @@ -984,9 +984,10 @@ /// \return a MachineInstrBuilder for the newly created instruction. The /// opcode of the new instruction will depend on the types of both /// the destination and the sources. - MachineInstrBuilder buildMerge(const DstOp &Res, ArrayRef Ops); - MachineInstrBuilder buildMerge(const DstOp &Res, - std::initializer_list Ops); + MachineInstrBuilder buildMergeLikeOp(const DstOp &Res, + ArrayRef Ops); + MachineInstrBuilder buildMergeLikeOp(const DstOp &Res, + std::initializer_list Ops); /// Build and insert \p Res0, ... = G_UNMERGE_VALUES \p Op /// diff --git a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp --- a/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CallLowering.cpp @@ -306,8 +306,8 @@ Register UnmergeSrcReg; if (LCMTy != PartLLT) { assert(DstRegs.size() == 1); - return B.buildDeleteTrailingVectorElements(DstRegs[0], - B.buildMerge(LCMTy, SrcRegs)); + return B.buildDeleteTrailingVectorElements( + DstRegs[0], B.buildMergeLikeOp(LCMTy, SrcRegs)); } else { // We don't need to widen anything if we're extracting a scalar which was // promoted to a vector e.g. s8 -> v4s8 -> s8 @@ -388,9 +388,9 @@ unsigned SrcSize = PartLLT.getSizeInBits().getFixedSize() * Regs.size(); if (SrcSize == OrigTy.getSizeInBits()) - B.buildMerge(OrigRegs[0], Regs); + B.buildMergeLikeOp(OrigRegs[0], Regs); else { - auto Widened = B.buildMerge(LLT::scalar(SrcSize), Regs); + auto Widened = B.buildMergeLikeOp(LLT::scalar(SrcSize), Regs); B.buildTrunc(OrigRegs[0], Widened); } @@ -458,7 +458,8 @@ assert(DstEltTy.getSizeInBits() % PartLLT.getSizeInBits() == 0); for (int I = 0, NumElts = LLTy.getNumElements(); I != NumElts; ++I) { - auto Merge = B.buildMerge(RealDstEltTy, Regs.take_front(PartsPerElt)); + auto Merge = + B.buildMergeLikeOp(RealDstEltTy, Regs.take_front(PartsPerElt)); // Fix the type in case this is really a vector of pointers. MRI.setType(Merge.getReg(0), RealDstEltTy); EltMerges.push_back(Merge.getReg(0)); @@ -549,7 +550,7 @@ SmallVector MergeParts(1, SrcReg); for (unsigned Size = SrcSize; Size != CoveringSize; Size += SrcSize) MergeParts.push_back(Undef); - UnmergeSrc = B.buildMerge(LCMTy, MergeParts).getReg(0); + UnmergeSrc = B.buildMergeLikeOp(LCMTy, MergeParts).getReg(0); } } diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -389,7 +389,7 @@ if (Ops.size() == 1) Builder.buildCopy(NewDstReg, Ops[0]); else - Builder.buildMerge(NewDstReg, Ops); + Builder.buildMergeLikeOp(NewDstReg, Ops); MI.eraseFromParent(); replaceRegWith(MRI, DstReg, NewDstReg); @@ -1972,7 +1972,7 @@ } auto Zero = Builder.buildConstant(HalfTy, 0); - Builder.buildMerge(DstReg, { Narrowed, Zero }); + Builder.buildMergeLikeOp(DstReg, {Narrowed, Zero}); } else if (MI.getOpcode() == TargetOpcode::G_SHL) { Register Narrowed = Unmerge.getReg(0); // dst = G_SHL s64:x, C for C >= 32 @@ -1985,7 +1985,7 @@ } auto Zero = Builder.buildConstant(HalfTy, 0); - Builder.buildMerge(DstReg, { Zero, Narrowed }); + Builder.buildMergeLikeOp(DstReg, {Zero, Narrowed}); } else { assert(MI.getOpcode() == TargetOpcode::G_ASHR); auto Hi = Builder.buildAShr( @@ -1995,13 +1995,13 @@ if (ShiftVal == HalfSize) { // (G_ASHR i64:x, 32) -> // G_MERGE_VALUES hi_32(x), (G_ASHR hi_32(x), 31) - Builder.buildMerge(DstReg, { Unmerge.getReg(1), Hi }); + Builder.buildMergeLikeOp(DstReg, {Unmerge.getReg(1), Hi}); } else if (ShiftVal == Size - 1) { // Don't need a second shift. // (G_ASHR i64:x, 63) -> // %narrowed = (G_ASHR hi_32(x), 31) // G_MERGE_VALUES %narrowed, %narrowed - Builder.buildMerge(DstReg, { Hi, Hi }); + Builder.buildMergeLikeOp(DstReg, {Hi, Hi}); } else { auto Lo = Builder.buildAShr( HalfTy, Unmerge.getReg(1), @@ -2009,7 +2009,7 @@ // (G_ASHR i64:x, C) ->, for C >= 32 // G_MERGE_VALUES (G_ASHR hi_32(x), C - 32), (G_ASHR hi_32(x), 31) - Builder.buildMerge(DstReg, { Lo, Hi }); + Builder.buildMergeLikeOp(DstReg, {Lo, Hi}); } } diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp --- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -235,7 +235,7 @@ // Requested sub-vectors of NarrowTy. for (unsigned i = 0; i < NumNarrowTyPieces; ++i, Offset += NumElts) { ArrayRef Pieces(&Elts[Offset], NumElts); - VRegs.push_back(MIRBuilder.buildMerge(NarrowTy, Pieces).getReg(0)); + VRegs.push_back(MIRBuilder.buildMergeLikeOp(NarrowTy, Pieces).getReg(0)); } // Leftover element(s). @@ -244,7 +244,7 @@ } else { LLT LeftoverTy = LLT::fixed_vector(LeftoverNumElts, EltTy); ArrayRef Pieces(&Elts[Offset], LeftoverNumElts); - VRegs.push_back(MIRBuilder.buildMerge(LeftoverTy, Pieces).getReg(0)); + VRegs.push_back(MIRBuilder.buildMergeLikeOp(LeftoverTy, Pieces).getReg(0)); } } @@ -257,7 +257,7 @@ assert(LeftoverRegs.empty()); if (!ResultTy.isVector()) { - MIRBuilder.buildMerge(DstReg, PartRegs); + MIRBuilder.buildMergeLikeOp(DstReg, PartRegs); return; } @@ -306,7 +306,7 @@ else appendVectorElts(AllElts, Leftover); - MIRBuilder.buildMerge(DstReg, AllElts); + MIRBuilder.buildMergeLikeOp(DstReg, AllElts); } /// Append the result registers of G_UNMERGE_VALUES \p MI to \p Regs. @@ -423,7 +423,7 @@ if (NumSubParts == 1) Remerge[I] = SubMerge[0]; else - Remerge[I] = MIRBuilder.buildMerge(NarrowTy, SubMerge).getReg(0); + Remerge[I] = MIRBuilder.buildMergeLikeOp(NarrowTy, SubMerge).getReg(0); // In the sign extend padding case, re-use the first all-signbit merge. if (AllMergePartsArePadding && !AllPadReg) @@ -442,11 +442,11 @@ // the result. if (DstTy == LCMTy) { - MIRBuilder.buildMerge(DstReg, RemergeRegs); + MIRBuilder.buildMergeLikeOp(DstReg, RemergeRegs); return; } - auto Remerge = MIRBuilder.buildMerge(LCMTy, RemergeRegs); + auto Remerge = MIRBuilder.buildMergeLikeOp(LCMTy, RemergeRegs); if (DstTy.isScalar() && LCMTy.isScalar()) { MIRBuilder.buildTrunc(DstReg, Remerge); return; @@ -460,7 +460,7 @@ UnmergeDefs[I] = MRI.createGenericVirtualRegister(DstTy); MIRBuilder.buildUnmerge(UnmergeDefs, - MIRBuilder.buildMerge(LCMTy, RemergeRegs)); + MIRBuilder.buildMergeLikeOp(LCMTy, RemergeRegs)); return; } @@ -941,7 +941,7 @@ if (DstTy.isVector()) MIRBuilder.buildBuildVector(DstReg, DstRegs); else - MIRBuilder.buildMerge(DstReg, DstRegs); + MIRBuilder.buildMergeLikeOp(DstReg, DstRegs); MI.eraseFromParent(); return Legalized; } @@ -1013,7 +1013,7 @@ MIRBuilder.buildFreeze(NarrowTy, Unmerge.getReg(i)).getReg(0)); } - MIRBuilder.buildMerge(MI.getOperand(0).getReg(), Parts); + MIRBuilder.buildMergeLikeOp(MI.getOperand(0).getReg(), Parts); MI.eraseFromParent(); return Legalized; } @@ -1188,7 +1188,7 @@ MIB.addUse(SrcRegs[j / 2][i]).add(MI.getOperand(j + 1)); } MIRBuilder.setInsertPt(MBB, MBB.getFirstNonPHI()); - MIRBuilder.buildMerge(MI.getOperand(0), DstRegs); + MIRBuilder.buildMergeLikeOp(MI.getOperand(0), DstRegs); Observer.changedInstr(MI); MI.eraseFromParent(); return Legalized; @@ -1365,7 +1365,7 @@ // Gather the destination registers into the final destination. Register DstReg = MI.getOperand(0).getReg(); - MIRBuilder.buildMerge(DstReg, DstRegs); + MIRBuilder.buildMergeLikeOp(DstReg, DstRegs); MI.eraseFromParent(); return Legalized; } @@ -1385,7 +1385,7 @@ DstRegs.push_back(DstPart.getReg(0)); } - MIRBuilder.buildMerge(MI.getOperand(0), DstRegs); + MIRBuilder.buildMergeLikeOp(MI.getOperand(0), DstRegs); Observer.changedInstr(MI); MI.eraseFromParent(); @@ -1602,16 +1602,17 @@ // Build merges of each piece. ArrayRef Slicer(Unmerges); for (int I = 0; I != NumMerge; ++I, Slicer = Slicer.drop_front(PartsPerGCD)) { - auto Merge = MIRBuilder.buildMerge(WideTy, Slicer.take_front(PartsPerGCD)); + auto Merge = + MIRBuilder.buildMergeLikeOp(WideTy, Slicer.take_front(PartsPerGCD)); NewMergeRegs.push_back(Merge.getReg(0)); } // A truncate may be necessary if the requested type doesn't evenly divide the // original result type. if (DstTy.getSizeInBits() == WideDstTy.getSizeInBits()) { - MIRBuilder.buildMerge(DstReg, NewMergeRegs); + MIRBuilder.buildMergeLikeOp(DstReg, NewMergeRegs); } else { - auto FinalMerge = MIRBuilder.buildMerge(WideDstTy, NewMergeRegs); + auto FinalMerge = MIRBuilder.buildMergeLikeOp(WideDstTy, NewMergeRegs); MIRBuilder.buildTrunc(DstReg, FinalMerge.getReg(0)); } @@ -1739,7 +1740,7 @@ RemergeParts.emplace_back(Parts[Idx]); } - MIRBuilder.buildMerge(MI.getOperand(I).getReg(), RemergeParts); + MIRBuilder.buildMergeLikeOp(MI.getOperand(I).getReg(), RemergeParts); RemergeParts.clear(); } } @@ -2680,7 +2681,7 @@ } else getUnmergePieces(SrcRegs, MIRBuilder, Src, SrcEltTy); - MIRBuilder.buildMerge(Dst, SrcRegs); + MIRBuilder.buildMergeLikeOp(Dst, SrcRegs); MI.eraseFromParent(); return Legalized; } @@ -2688,7 +2689,7 @@ if (DstTy.isVector()) { SmallVector SrcRegs; getUnmergePieces(SrcRegs, MIRBuilder, Src, DstTy.getElementType()); - MIRBuilder.buildMerge(Dst, SrcRegs); + MIRBuilder.buildMergeLikeOp(Dst, SrcRegs); MI.eraseFromParent(); return Legalized; } @@ -3760,7 +3761,7 @@ mergeMixedSubvectors(MI.getReg(i), OutputRegs[i]); } else { for (unsigned i = 0; i < NumDefs; ++i) - MIRBuilder.buildMerge(MI.getReg(i), OutputRegs[i]); + MIRBuilder.buildMergeLikeOp(MI.getReg(i), OutputRegs[i]); } MI.eraseFromParent(); @@ -3808,7 +3809,7 @@ if (NumLeftovers) { mergeMixedSubvectors(MI.getReg(0), OutputRegs); } else { - MIRBuilder.buildMerge(MI.getReg(0), OutputRegs); + MIRBuilder.buildMergeLikeOp(MI.getReg(0), OutputRegs); } MI.eraseFromParent(); @@ -3911,10 +3912,11 @@ for (unsigned i = 0, Offset = 0; i < NumNarrowTyPieces; ++i, Offset += NumNarrowTyElts) { ArrayRef Pieces(&Elts[Offset], NumNarrowTyElts); - NarrowTyElts.push_back(MIRBuilder.buildMerge(NarrowTy, Pieces).getReg(0)); + NarrowTyElts.push_back( + MIRBuilder.buildMergeLikeOp(NarrowTy, Pieces).getReg(0)); } - MIRBuilder.buildMerge(DstReg, NarrowTyElts); + MIRBuilder.buildMergeLikeOp(DstReg, NarrowTyElts); MI.eraseFromParent(); return Legalized; } @@ -3942,10 +3944,11 @@ SmallVector Sources; for (unsigned j = 0; j < NumElts; ++j) Sources.push_back(MI.getOperand(1 + i * NumElts + j).getReg()); - NarrowTyElts.push_back(MIRBuilder.buildMerge(NarrowTy, Sources).getReg(0)); + NarrowTyElts.push_back( + MIRBuilder.buildMergeLikeOp(NarrowTy, Sources).getReg(0)); } - MIRBuilder.buildMerge(DstReg, NarrowTyElts); + MIRBuilder.buildMergeLikeOp(DstReg, NarrowTyElts); MI.eraseFromParent(); return Legalized; } @@ -4588,7 +4591,7 @@ MIRBuilder.buildUnmerge({InL, InH}, MI.getOperand(1)); if (Amt.isZero()) { - MIRBuilder.buildMerge(MI.getOperand(0), {InL, InH}); + MIRBuilder.buildMergeLikeOp(MI.getOperand(0), {InL, InH}); MI.eraseFromParent(); return Legalized; } @@ -4661,7 +4664,7 @@ } } - MIRBuilder.buildMerge(MI.getOperand(0), {Lo, Hi}); + MIRBuilder.buildMergeLikeOp(MI.getOperand(0), {Lo, Hi}); MI.eraseFromParent(); return Legalized; @@ -4772,7 +4775,7 @@ llvm_unreachable("not a shift"); } - MIRBuilder.buildMerge(DstReg, ResultRegs); + MIRBuilder.buildMergeLikeOp(DstReg, ResultRegs); MI.eraseFromParent(); return Legalized; } @@ -5239,7 +5242,7 @@ // Take only high half of registers if this is high mul. ArrayRef DstRegs(&DstTmpRegs[DstTmpParts - NumParts], NumParts); - MIRBuilder.buildMerge(DstReg, DstRegs); + MIRBuilder.buildMergeLikeOp(DstReg, DstRegs); MI.eraseFromParent(); return Legalized; } @@ -5329,7 +5332,7 @@ if (MRI.getType(DstReg).isVector()) MIRBuilder.buildBuildVector(DstReg, DstRegs); else if (DstRegs.size() > 1) - MIRBuilder.buildMerge(DstReg, DstRegs); + MIRBuilder.buildMergeLikeOp(DstReg, DstRegs); else MIRBuilder.buildCopy(DstReg, DstRegs[0]); MI.eraseFromParent(); @@ -5411,10 +5414,10 @@ Register DstReg = MI.getOperand(0).getReg(); if (WideSize > RegTy.getSizeInBits()) { Register MergeReg = MRI.createGenericVirtualRegister(LLT::scalar(WideSize)); - MIRBuilder.buildMerge(MergeReg, DstRegs); + MIRBuilder.buildMergeLikeOp(MergeReg, DstRegs); MIRBuilder.buildTrunc(DstReg, MergeReg); } else - MIRBuilder.buildMerge(DstReg, DstRegs); + MIRBuilder.buildMergeLikeOp(DstReg, DstRegs); MI.eraseFromParent(); return Legalized; @@ -6672,7 +6675,7 @@ if (InsertVal) { SrcRegs[IdxVal] = MI.getOperand(2).getReg(); - MIRBuilder.buildMerge(DstReg, SrcRegs); + MIRBuilder.buildMergeLikeOp(DstReg, SrcRegs); } else { MIRBuilder.buildCopy(DstReg, SrcRegs[IdxVal]); } @@ -6844,7 +6847,7 @@ if (SubVectorElts.size() == 1) MIRBuilder.buildCopy(Dst, SubVectorElts[0]); else - MIRBuilder.buildMerge(Dst, SubVectorElts); + MIRBuilder.buildMergeLikeOp(Dst, SubVectorElts); MI.eraseFromParent(); return Legalized; @@ -6917,7 +6920,7 @@ DstElts.push_back(UnmergeSrc.getReg(Idx)); } - MIRBuilder.buildMerge(Dst, DstElts); + MIRBuilder.buildMergeLikeOp(Dst, DstElts); MI.eraseFromParent(); return Legalized; } diff --git a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp --- a/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp +++ b/llvm/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp @@ -243,7 +243,7 @@ unsigned NumberOfPadElts = ResTy.getNumElements() - Regs.size(); for (unsigned i = 0; i < NumberOfPadElts; ++i) Regs.push_back(Undef); - return buildMerge(Res, Regs); + return buildMergeLikeOp(Res, Regs); } MachineInstrBuilder @@ -262,7 +262,7 @@ auto Unmerge = buildUnmerge(Op0Ty.getElementType(), Op0); for (unsigned i = 0; i < ResTy.getNumElements(); ++i) Regs.push_back(Unmerge.getReg(i)); - return buildMerge(Res, Regs); + return buildMergeLikeOp(Res, Regs); } MachineInstrBuilder MachineIRBuilder::buildBr(MachineBasicBlock &Dest) { @@ -597,8 +597,8 @@ return buildInstr(TargetOpcode::G_IMPLICIT_DEF, {Res}, {}); } -MachineInstrBuilder MachineIRBuilder::buildMerge(const DstOp &Res, - ArrayRef Ops) { +MachineInstrBuilder MachineIRBuilder::buildMergeLikeOp(const DstOp &Res, + ArrayRef Ops) { // Unfortunately to convert from ArrayRef to ArrayRef, // we need some temporary storage for the DstOp objects. Here we use a // sufficiently large SmallVector to not go through the heap. @@ -608,8 +608,8 @@ } MachineInstrBuilder -MachineIRBuilder::buildMerge(const DstOp &Res, - std::initializer_list Ops) { +MachineIRBuilder::buildMergeLikeOp(const DstOp &Res, + std::initializer_list Ops) { assert(Ops.size() > 1); return buildInstr(getOpcodeForMerge(Res, Ops), Res, Ops); } diff --git a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp b/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp --- a/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64CallLowering.cpp @@ -414,7 +414,8 @@ } auto Undef = MIRBuilder.buildUndef({OldLLT}); CurVReg = - MIRBuilder.buildMerge({NewLLT}, {CurVReg, Undef}).getReg(0); + MIRBuilder.buildMergeLikeOp({NewLLT}, {CurVReg, Undef}) + .getReg(0); } else { // Just do a vector extend. CurVReg = MIRBuilder.buildInstr(ExtendOp, {NewLLT}, {CurVReg}) diff --git a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp --- a/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp +++ b/llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp @@ -1197,7 +1197,8 @@ MachineInstrBuilder NewI; if (MI.getOpcode() == TargetOpcode::G_LOAD) { NewI = MIRBuilder.buildInstr(AArch64::LDPXi, {s64, s64}, {}); - MIRBuilder.buildMerge(ValReg, {NewI->getOperand(0), NewI->getOperand(1)}); + MIRBuilder.buildMergeLikeOp(ValReg, + {NewI->getOperand(0), NewI->getOperand(1)}); } else { auto Split = MIRBuilder.buildUnmerge(s64, MI.getOperand(0)); NewI = MIRBuilder.buildInstr( @@ -1499,7 +1500,7 @@ *MRI.getTargetRegisterInfo(), *ST->getRegBankInfo()); - MIRBuilder.buildMerge(MI.getOperand(0), {DstLo, DstHi}); + MIRBuilder.buildMergeLikeOp(MI.getOperand(0), {DstLo, DstHi}); MI.eraseFromParent(); return true; } diff --git a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp @@ -1989,7 +1989,7 @@ // TODO: Should we allow mismatched types but matching sizes in merges to // avoid the ptrtoint? - auto BuildPtr = B.buildMerge(DstTy, {SrcAsInt, ApertureReg}); + auto BuildPtr = B.buildMergeLikeOp(DstTy, {SrcAsInt, ApertureReg}); if (isKnownNonNull(Src, MRI, TM, SrcAS)) { B.buildCopy(Dst, BuildPtr); @@ -2023,7 +2023,7 @@ uint32_t AddrHiVal = Info->get32BitAddressHighBits(); auto PtrLo = B.buildPtrToInt(S32, Src); auto HighAddr = B.buildConstant(S32, AddrHiVal); - B.buildMerge(Dst, {PtrLo, HighAddr}); + B.buildMergeLikeOp(Dst, {PtrLo, HighAddr}); MI.eraseFromParent(); return true; } @@ -2156,7 +2156,7 @@ const auto Zero32 = B.buildConstant(S32, 0); // Extend back to 64-bits. - auto SignBit64 = B.buildMerge(S64, {Zero32, SignBit}); + auto SignBit64 = B.buildMergeLikeOp(S64, {Zero32, SignBit}); auto Shr = B.buildAShr(S64, FractMask, Exp); auto Not = B.buildNot(S64, Shr); @@ -2292,11 +2292,12 @@ if (Signed && SrcLT == S32) { // Flip the result based on the signedness, which is either all 0s or 1s. - Sign = B.buildMerge(S64, {Sign, Sign}); + Sign = B.buildMergeLikeOp(S64, {Sign, Sign}); // r := xor({lo, hi}, sign) - sign; - B.buildSub(Dst, B.buildXor(S64, B.buildMerge(S64, {Lo, Hi}), Sign), Sign); + B.buildSub(Dst, B.buildXor(S64, B.buildMergeLikeOp(S64, {Lo, Hi}), Sign), + Sign); } else - B.buildMerge(Dst, {Lo, Hi}); + B.buildMergeLikeOp(Dst, {Lo, Hi}); MI.eraseFromParent(); return true; @@ -2388,7 +2389,7 @@ B.buildUnmerge(SrcRegs, Vec); SrcRegs[IdxVal] = MI.getOperand(2).getReg(); - B.buildMerge(Dst, SrcRegs); + B.buildMergeLikeOp(Dst, SrcRegs); } else { B.buildUndef(Dst); } @@ -2873,7 +2874,7 @@ Src1 = B.buildTrunc(S16, MI.getOperand(2).getReg()).getReg(0); } - auto Merge = B.buildMerge(S32, {Src0, Src1}); + auto Merge = B.buildMergeLikeOp(S32, {Src0, Src1}); B.buildBitcast(Dst, Merge); MI.eraseFromParent(); @@ -3007,7 +3008,7 @@ Tmp = B.buildAnyExt(S64, LocalAccum[0]).getReg(0); HaveSmallAccum = true; } else if (LocalAccum[1]) { - Tmp = B.buildMerge(S64, LocalAccum).getReg(0); + Tmp = B.buildMergeLikeOp(S64, LocalAccum).getReg(0); HaveSmallAccum = false; } else { Tmp = B.buildZExt(S64, LocalAccum[0]).getReg(0); @@ -3166,7 +3167,7 @@ buildMultiply(Helper, AccumRegs, Src0Parts, Src1Parts, UsePartialMad64_32, SeparateOddAlignedProducts); - B.buildMerge(DstReg, AccumRegs); + B.buildMergeLikeOp(DstReg, AccumRegs); MI.eraseFromParent(); return true; @@ -3515,7 +3516,7 @@ std::tie(RcpLo, RcpHi) = emitReciprocalU64(B, Denom); - auto Rcp = B.buildMerge(S64, {RcpLo, RcpHi}); + auto Rcp = B.buildMergeLikeOp(S64, {RcpLo, RcpHi}); auto Zero64 = B.buildConstant(S64, 0); auto NegDenom = B.buildSub(S64, Zero64, Denom); @@ -3529,7 +3530,7 @@ auto Add1_Lo = B.buildUAddo(S32, S1, RcpLo, MulHi1_Lo); auto Add1_Hi = B.buildUAdde(S32, S1, RcpHi, MulHi1_Hi, Add1_Lo.getReg(1)); - auto Add1 = B.buildMerge(S64, {Add1_Lo, Add1_Hi}); + auto Add1 = B.buildMergeLikeOp(S64, {Add1_Lo, Add1_Hi}); auto MulLo2 = B.buildMul(S64, NegDenom, Add1); auto MulHi2 = B.buildUMulH(S64, Add1, MulLo2); @@ -3540,7 +3541,7 @@ auto Zero32 = B.buildConstant(S32, 0); auto Add2_Lo = B.buildUAddo(S32, S1, Add1_Lo, MulHi2_Lo); auto Add2_Hi = B.buildUAdde(S32, S1, Add1_Hi, MulHi2_Hi, Add2_Lo.getReg(1)); - auto Add2 = B.buildMerge(S64, {Add2_Lo, Add2_Hi}); + auto Add2 = B.buildMergeLikeOp(S64, {Add2_Lo, Add2_Hi}); auto UnmergeNumer = B.buildUnmerge(S32, Numer); Register NumerLo = UnmergeNumer.getReg(0); @@ -3554,7 +3555,7 @@ auto Sub1_Lo = B.buildUSubo(S32, S1, NumerLo, Mul3_Lo); auto Sub1_Hi = B.buildUSube(S32, S1, NumerHi, Mul3_Hi, Sub1_Lo.getReg(1)); auto Sub1_Mi = B.buildSub(S32, NumerHi, Mul3_Hi); - auto Sub1 = B.buildMerge(S64, {Sub1_Lo, Sub1_Hi}); + auto Sub1 = B.buildMergeLikeOp(S64, {Sub1_Lo, Sub1_Hi}); auto UnmergeDenom = B.buildUnmerge(S32, Denom); Register DenomLo = UnmergeDenom.getReg(0); @@ -3577,7 +3578,7 @@ auto Sub2_Lo = B.buildUSubo(S32, S1, Sub1_Lo, DenomLo); auto Sub2_Mi = B.buildUSube(S32, S1, Sub1_Mi, DenomHi, Sub1_Lo.getReg(1)); auto Sub2_Hi = B.buildUSube(S32, S1, Sub2_Mi, Zero32, Sub2_Lo.getReg(1)); - auto Sub2 = B.buildMerge(S64, {Sub2_Lo, Sub2_Hi}); + auto Sub2 = B.buildMergeLikeOp(S64, {Sub2_Lo, Sub2_Hi}); auto One64 = B.buildConstant(S64, 1); auto Add3 = B.buildAdd(S64, MulHi3, One64); @@ -3595,7 +3596,7 @@ auto Sub3_Mi = B.buildUSube(S32, S1, Sub2_Mi, DenomHi, Sub2_Lo.getReg(1)); auto Sub3_Hi = B.buildUSube(S32, S1, Sub3_Mi, Zero32, Sub3_Lo.getReg(1)); - auto Sub3 = B.buildMerge(S64, {Sub3_Lo, Sub3_Hi}); + auto Sub3 = B.buildMergeLikeOp(S64, {Sub3_Lo, Sub3_Hi}); // endif C6 // endif C3 @@ -4593,7 +4594,7 @@ LoadElts.push_back(StatusDst); B.buildUnmerge(LoadElts, LoadDstReg); LoadElts.truncate(NumValueDWords); - B.buildMerge(Dst, LoadElts); + B.buildMergeLikeOp(Dst, LoadElts); } } else if ((!IsD16 && MemTy.getSizeInBits() < 32) || (IsD16 && !Ty.isVector())) { @@ -4613,7 +4614,7 @@ SmallVector Repack; for (unsigned I = 0, N = Unmerge->getNumOperands() - 1; I != N; ++I) Repack.push_back(B.buildTrunc(EltTy, Unmerge.getReg(I)).getReg(0)); - B.buildMerge(Dst, Repack); + B.buildMergeLikeOp(Dst, Repack); } else { buildBufferLoad(Opc, Dst, RSrc, VIndex, VOffset, SOffset, ImmOffset, Format, AuxiliaryData, MMO, IsTyped, HasVIndex, B); @@ -5446,7 +5447,7 @@ if (UseNSA && IsGFX11Plus) { auto packLanes = [&Ops, &S32, &V3S32, &B](Register Src) { auto Unmerge = B.buildUnmerge({S32, S32, S32}, Src); - auto Merged = B.buildMerge( + auto Merged = B.buildMergeLikeOp( V3S32, {Unmerge.getReg(0), Unmerge.getReg(1), Unmerge.getReg(2)}); Ops.push_back(Merged.getReg(0)); }; @@ -5458,16 +5459,19 @@ if (IsA16) { auto UnmergeRayDir = B.buildUnmerge({S16, S16, S16}, RayDir); auto UnmergeRayInvDir = B.buildUnmerge({S16, S16, S16}, RayInvDir); - auto MergedDir = B.buildMerge( + auto MergedDir = B.buildMergeLikeOp( V3S32, - {B.buildBitcast(S32, B.buildMerge(V2S16, {UnmergeRayInvDir.getReg(0), - UnmergeRayDir.getReg(0)})) + {B.buildBitcast(S32, + B.buildMergeLikeOp(V2S16, {UnmergeRayInvDir.getReg(0), + UnmergeRayDir.getReg(0)})) .getReg(0), - B.buildBitcast(S32, B.buildMerge(V2S16, {UnmergeRayInvDir.getReg(1), - UnmergeRayDir.getReg(1)})) + B.buildBitcast(S32, + B.buildMergeLikeOp(V2S16, {UnmergeRayInvDir.getReg(1), + UnmergeRayDir.getReg(1)})) .getReg(0), - B.buildBitcast(S32, B.buildMerge(V2S16, {UnmergeRayInvDir.getReg(2), - UnmergeRayDir.getReg(2)})) + B.buildBitcast(S32, + B.buildMergeLikeOp(V2S16, {UnmergeRayInvDir.getReg(2), + UnmergeRayDir.getReg(2)})) .getReg(0)}); Ops.push_back(MergedDir.getReg(0)); } else { @@ -5498,10 +5502,12 @@ Register R1 = MRI.createGenericVirtualRegister(S32); Register R2 = MRI.createGenericVirtualRegister(S32); Register R3 = MRI.createGenericVirtualRegister(S32); - B.buildMerge(R1, {UnmergeRayDir.getReg(0), UnmergeRayDir.getReg(1)}); - B.buildMerge(R2, {UnmergeRayDir.getReg(2), UnmergeRayInvDir.getReg(0)}); - B.buildMerge(R3, - {UnmergeRayInvDir.getReg(1), UnmergeRayInvDir.getReg(2)}); + B.buildMergeLikeOp(R1, + {UnmergeRayDir.getReg(0), UnmergeRayDir.getReg(1)}); + B.buildMergeLikeOp(R2, + {UnmergeRayDir.getReg(2), UnmergeRayInvDir.getReg(0)}); + B.buildMergeLikeOp( + R3, {UnmergeRayInvDir.getReg(1), UnmergeRayInvDir.getReg(2)}); Ops.push_back(R1); Ops.push_back(R2); Ops.push_back(R3); @@ -5514,7 +5520,7 @@ if (!UseNSA) { // Build a single vector containing all the operands so far prepared. LLT OpTy = LLT::fixed_vector(Ops.size(), 32); - Register MergedOps = B.buildMerge(OpTy, Ops).getReg(0); + Register MergedOps = B.buildMergeLikeOp(OpTy, Ops).getReg(0); Ops.clear(); Ops.push_back(MergedOps); } diff --git a/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp @@ -729,7 +729,7 @@ if (Bits == 32) return DstParts[0]; - Register Dst = B.buildMerge(Ty, DstParts).getReg(0); + Register Dst = B.buildMergeLikeOp(Ty, DstParts).getReg(0); MRI.setRegBank(Dst, AMDGPU::SGPRRegBank); return Dst; } @@ -1439,7 +1439,7 @@ if (Ty.isVector()) B.buildConcatVectors(Dst, LoadParts); else - B.buildMerge(Dst, LoadParts); + B.buildMergeLikeOp(Dst, LoadParts); } // We removed the instruction earlier with a waterfall loop. @@ -1499,7 +1499,7 @@ : B.buildUbfx(S32, UnmergeSOffset.getReg(0), Zero, WidthReg); auto Extend = Signed ? B.buildAShr(S32, Extract, B.buildConstant(S32, 31)) : Zero; - B.buildMerge(DstReg, {Extract, Extend}); + B.buildMergeLikeOp(DstReg, {Extract, Extend}); } else { // Use bitfield extract on upper 32-bit source, and combine with lower // 32-bit source. @@ -1508,7 +1508,7 @@ Signed ? B.buildSbfx(S32, UnmergeSOffset.getReg(1), Zero, UpperWidth) : B.buildUbfx(S32, UnmergeSOffset.getReg(1), Zero, UpperWidth); - B.buildMerge(DstReg, {UnmergeSOffset.getReg(0), Extract}); + B.buildMergeLikeOp(DstReg, {UnmergeSOffset.getReg(0), Extract}); } MI.eraseFromParent(); return true; @@ -1695,7 +1695,7 @@ } } - B.buildMerge(Dst0, {DstLo, DstHi}); + B.buildMergeLikeOp(Dst0, {DstLo, DstHi}); if (DstOnValu) { B.buildCopy(Dst1, Carry); @@ -1782,7 +1782,8 @@ const LLT S32 = LLT::scalar(32); int NumElts = StoreVT.getNumElements(); - return B.buildMerge(LLT::fixed_vector(NumElts, S32), WideRegs).getReg(0); + return B.buildMergeLikeOp(LLT::fixed_vector(NumElts, S32), WideRegs) + .getReg(0); } static std::pair diff --git a/llvm/lib/Target/ARM/ARMCallLowering.cpp b/llvm/lib/Target/ARM/ARMCallLowering.cpp --- a/llvm/lib/Target/ARM/ARMCallLowering.cpp +++ b/llvm/lib/Target/ARM/ARMCallLowering.cpp @@ -337,7 +337,7 @@ if (!IsLittle) std::swap(NewRegs[0], NewRegs[1]); - MIRBuilder.buildMerge(Arg.Regs[0], NewRegs); + MIRBuilder.buildMergeLikeOp(Arg.Regs[0], NewRegs); return 1; } diff --git a/llvm/lib/Target/Mips/MipsCallLowering.cpp b/llvm/lib/Target/Mips/MipsCallLowering.cpp --- a/llvm/lib/Target/Mips/MipsCallLowering.cpp +++ b/llvm/lib/Target/Mips/MipsCallLowering.cpp @@ -181,7 +181,7 @@ Arg.OrigRegs.assign(Arg.Regs.begin(), Arg.Regs.end()); Arg.Regs = { CopyLo.getReg(0), CopyHi.getReg(0) }; - MIRBuilder.buildMerge(Arg.OrigRegs[0], {CopyLo, CopyHi}); + MIRBuilder.buildMergeLikeOp(Arg.OrigRegs[0], {CopyLo, CopyHi}); markPhysRegUsed(VALo.getLocReg()); markPhysRegUsed(VAHi.getLocReg()); diff --git a/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp b/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp --- a/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp +++ b/llvm/lib/Target/Mips/MipsLegalizerInfo.cpp @@ -411,9 +411,10 @@ auto Load_Rem = MIRBuilder.buildLoad(s32, Addr, *RemMemOp); if (Size == 64) - MIRBuilder.buildMerge(Val, {Load_P2Half, Load_Rem}); + MIRBuilder.buildMergeLikeOp(Val, {Load_P2Half, Load_Rem}); else { - auto Merge = MIRBuilder.buildMerge(s64, {Load_P2Half, Load_Rem}); + auto Merge = + MIRBuilder.buildMergeLikeOp(s64, {Load_P2Half, Load_Rem}); MIRBuilder.buildTrunc(Val, Merge); } } @@ -440,7 +441,7 @@ // Done. Trunc double to float if needed. auto C_HiMask = MIRBuilder.buildConstant(s32, UINT32_C(0x43300000)); - auto Bitcast = MIRBuilder.buildMerge(s64, {Src, C_HiMask.getReg(0)}); + auto Bitcast = MIRBuilder.buildMergeLikeOp(s64, {Src, C_HiMask.getReg(0)}); MachineInstrBuilder TwoP52FP = MIRBuilder.buildFConstant( s64, BitsToDouble(UINT64_C(0x4330000000000000))); diff --git a/llvm/lib/Target/X86/X86CallLowering.cpp b/llvm/lib/Target/X86/X86CallLowering.cpp --- a/llvm/lib/Target/X86/X86CallLowering.cpp +++ b/llvm/lib/Target/X86/X86CallLowering.cpp @@ -398,7 +398,7 @@ return false; if (!NewRegs.empty()) - MIRBuilder.buildMerge(Info.OrigRet.Regs[0], NewRegs); + MIRBuilder.buildMergeLikeOp(Info.OrigRet.Regs[0], NewRegs); } CallSeqStart.addImm(Assigner.getStackSize()) diff --git a/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp b/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp --- a/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/LegalizerHelperTest.cpp @@ -1784,7 +1784,7 @@ for (int I = 0; I != 8; ++I) Merge0Ops.push_back(B.buildConstant(S3, I).getReg(0)); - auto Merge0 = B.buildMerge(S24, Merge0Ops); + auto Merge0 = B.buildMergeLikeOp(S24, Merge0Ops); // 21 = 3 3 3 3 3 3 3 // => 9, 2 extra implicit_def needed @@ -1793,13 +1793,13 @@ for (int I = 0; I != 7; ++I) Merge1Ops.push_back(B.buildConstant(S3, I).getReg(0)); - auto Merge1 = B.buildMerge(S21, Merge1Ops); + auto Merge1 = B.buildMergeLikeOp(S21, Merge1Ops); SmallVector Merge2Ops; for (int I = 0; I != 2; ++I) Merge2Ops.push_back(B.buildConstant(S8, I).getReg(0)); - auto Merge2 = B.buildMerge(S16, Merge2Ops); + auto Merge2 = B.buildMergeLikeOp(S16, Merge2Ops); B.setInstr(*Merge0); EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized, @@ -1877,7 +1877,7 @@ auto Lo = B.buildTrunc(S32, Copies[0]); auto Hi = B.buildTrunc(S32, Copies[1]); - auto Merge = B.buildMerge(P0, {Lo, Hi}); + auto Merge = B.buildMergeLikeOp(P0, {Lo, Hi}); B.setInstr(*Merge); EXPECT_EQ(LegalizerHelper::LegalizeResult::Legalized, @@ -2087,7 +2087,7 @@ auto MIBFPTrunc1 = B.buildInstr(TargetOpcode::G_FPTRUNC, {S16}, {MIBTrunc}); - auto MIBMerge = B.buildMerge(S128, {Copies[1], Copies[2]}); + auto MIBMerge = B.buildMergeLikeOp(S128, {Copies[1], Copies[2]}); auto MIBFPTrunc2 = B.buildInstr(TargetOpcode::G_FPTRUNC, {S64}, {MIBMerge}); diff --git a/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp b/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp --- a/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp +++ b/llvm/unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp @@ -197,7 +197,7 @@ B.buildNot(S64, Copies[0]); // Make sure this works with > 64-bit types - auto Merge = B.buildMerge(S128, {Copies[0], Copies[1]}); + auto Merge = B.buildMergeLikeOp(S128, {Copies[0], Copies[1]}); B.buildNot(S128, Merge); auto CheckStr = R"( ; CHECK: [[COPY0:%[0-9]+]]:_(s64) = COPY $x0 @@ -324,7 +324,7 @@ EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF; } -TEST_F(AArch64GISelMITest, BuildMerge) { +TEST_F(AArch64GISelMITest, BuildMergeLikeOp) { setUp(); if (!TM) return; @@ -337,15 +337,13 @@ // Merging plain constants as one big blob of bit should produce a // G_MERGE_VALUES. - B.buildMerge(LLT::scalar(128), {RegC0, RegC1, RegC2, RegC3}); + B.buildMergeLikeOp(LLT::scalar(128), {RegC0, RegC1, RegC2, RegC3}); // Merging plain constants to a vector should produce a G_BUILD_VECTOR. LLT V2x32 = LLT::fixed_vector(2, 32); - Register RegC0C1 = - B.buildMerge(V2x32, {RegC0, RegC1}).getReg(0); - Register RegC2C3 = - B.buildMerge(V2x32, {RegC2, RegC3}).getReg(0); + Register RegC0C1 = B.buildMergeLikeOp(V2x32, {RegC0, RegC1}).getReg(0); + Register RegC2C3 = B.buildMergeLikeOp(V2x32, {RegC2, RegC3}).getReg(0); // Merging vector constants to a vector should produce a G_CONCAT_VECTORS. - B.buildMerge(LLT::fixed_vector(4, 32), {RegC0C1, RegC2C3}); + B.buildMergeLikeOp(LLT::fixed_vector(4, 32), {RegC0C1, RegC2C3}); // Merging vector constants to a plain type is not allowed. // Nothing else to test.