Skip to content

Commit 0a031f5

Browse files
committed
[GlobalISel] Simplify narrowScalarMul. NFC.
Remove some redundancy because the source and result types of any multiply are always the same.
1 parent ffaaa9b commit 0a031f5

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

+7-10
Original file line numberDiff line numberDiff line change
@@ -5337,26 +5337,23 @@ LegalizerHelper::narrowScalarMul(MachineInstr &MI, LLT NarrowTy) {
53375337
if (Ty.isVector())
53385338
return UnableToLegalize;
53395339

5340-
unsigned SrcSize = MRI.getType(Src1).getSizeInBits();
5341-
unsigned DstSize = Ty.getSizeInBits();
5340+
unsigned Size = Ty.getSizeInBits();
53425341
unsigned NarrowSize = NarrowTy.getSizeInBits();
5343-
if (DstSize % NarrowSize != 0 || SrcSize % NarrowSize != 0)
5342+
if (Size % NarrowSize != 0)
53445343
return UnableToLegalize;
53455344

5346-
unsigned NumDstParts = DstSize / NarrowSize;
5347-
unsigned NumSrcParts = SrcSize / NarrowSize;
5345+
unsigned NumParts = Size / NarrowSize;
53485346
bool IsMulHigh = MI.getOpcode() == TargetOpcode::G_UMULH;
5349-
unsigned DstTmpParts = NumDstParts * (IsMulHigh ? 2 : 1);
5347+
unsigned DstTmpParts = NumParts * (IsMulHigh ? 2 : 1);
53505348

53515349
SmallVector<Register, 2> Src1Parts, Src2Parts;
53525350
SmallVector<Register, 2> DstTmpRegs(DstTmpParts);
5353-
extractParts(Src1, NarrowTy, NumSrcParts, Src1Parts);
5354-
extractParts(Src2, NarrowTy, NumSrcParts, Src2Parts);
5351+
extractParts(Src1, NarrowTy, NumParts, Src1Parts);
5352+
extractParts(Src2, NarrowTy, NumParts, Src2Parts);
53555353
multiplyRegisters(DstTmpRegs, Src1Parts, Src2Parts, NarrowTy);
53565354

53575355
// Take only high half of registers if this is high mul.
5358-
ArrayRef<Register> DstRegs(
5359-
IsMulHigh ? &DstTmpRegs[DstTmpParts / 2] : &DstTmpRegs[0], NumDstParts);
5356+
ArrayRef<Register> DstRegs(&DstTmpRegs[DstTmpParts - NumParts], NumParts);
53605357
MIRBuilder.buildMerge(DstReg, DstRegs);
53615358
MI.eraseFromParent();
53625359
return Legalized;

0 commit comments

Comments
 (0)