From 0a031f5c880690e794aad48487dafbb010342ea1 Mon Sep 17 00:00:00 2001 From: Jay Foad Date: Tue, 5 Oct 2021 10:47:54 +0100 Subject: [PATCH] [GlobalISel] Simplify narrowScalarMul. NFC. Remove some redundancy because the source and result types of any multiply are always the same. --- llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp index 17a6a7c..0ecb2d1 100644 --- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -5337,26 +5337,23 @@ LegalizerHelper::narrowScalarMul(MachineInstr &MI, LLT NarrowTy) { if (Ty.isVector()) return UnableToLegalize; - unsigned SrcSize = MRI.getType(Src1).getSizeInBits(); - unsigned DstSize = Ty.getSizeInBits(); + unsigned Size = Ty.getSizeInBits(); unsigned NarrowSize = NarrowTy.getSizeInBits(); - if (DstSize % NarrowSize != 0 || SrcSize % NarrowSize != 0) + if (Size % NarrowSize != 0) return UnableToLegalize; - unsigned NumDstParts = DstSize / NarrowSize; - unsigned NumSrcParts = SrcSize / NarrowSize; + unsigned NumParts = Size / NarrowSize; bool IsMulHigh = MI.getOpcode() == TargetOpcode::G_UMULH; - unsigned DstTmpParts = NumDstParts * (IsMulHigh ? 2 : 1); + unsigned DstTmpParts = NumParts * (IsMulHigh ? 2 : 1); SmallVector Src1Parts, Src2Parts; SmallVector DstTmpRegs(DstTmpParts); - extractParts(Src1, NarrowTy, NumSrcParts, Src1Parts); - extractParts(Src2, NarrowTy, NumSrcParts, Src2Parts); + extractParts(Src1, NarrowTy, NumParts, Src1Parts); + extractParts(Src2, NarrowTy, NumParts, Src2Parts); multiplyRegisters(DstTmpRegs, Src1Parts, Src2Parts, NarrowTy); // Take only high half of registers if this is high mul. - ArrayRef DstRegs( - IsMulHigh ? &DstTmpRegs[DstTmpParts / 2] : &DstTmpRegs[0], NumDstParts); + ArrayRef DstRegs(&DstTmpRegs[DstTmpParts - NumParts], NumParts); MIRBuilder.buildMerge(DstReg, DstRegs); MI.eraseFromParent(); return Legalized; -- 2.7.4