Skip to content

Commit 7bd097f

Browse files
committed
[CostModel][TTI] Fix ops used for generic smulo/umulo cost expansion
Fix copy+pasta that was checking for smul_fix instead of smul_with_overflow to detected signed values. The LShr is performed on the extended type as we use it to truncate+extract the upper/hi bits of the extended multiply. More closely matches the default expansion from TargetLowering::expandMULO
1 parent 81b5da8 commit 7bd097f

File tree

4 files changed

+306
-306
lines changed

4 files changed

+306
-306
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1826,9 +1826,9 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
18261826
Type *OverflowTy = RetTy->getContainedType(1);
18271827
unsigned ExtSize = MulTy->getScalarSizeInBits() * 2;
18281828
Type *ExtTy = MulTy->getWithNewBitWidth(ExtSize);
1829+
bool IsSigned = IID == Intrinsic::smul_with_overflow;
18291830

1830-
unsigned ExtOp =
1831-
IID == Intrinsic::smul_fix ? Instruction::SExt : Instruction::ZExt;
1831+
unsigned ExtOp = IsSigned ? Instruction::SExt : Instruction::ZExt;
18321832
TTI::CastContextHint CCH = TTI::CastContextHint::None;
18331833

18341834
InstructionCost Cost = 0;
@@ -1837,11 +1837,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
18371837
thisT()->getArithmeticInstrCost(Instruction::Mul, ExtTy, CostKind);
18381838
Cost += 2 * thisT()->getCastInstrCost(Instruction::Trunc, MulTy, ExtTy,
18391839
CCH, CostKind);
1840-
Cost += thisT()->getArithmeticInstrCost(Instruction::LShr, MulTy,
1840+
Cost += thisT()->getArithmeticInstrCost(Instruction::LShr, ExtTy,
18411841
CostKind, TTI::OK_AnyValue,
18421842
TTI::OK_UniformConstantValue);
18431843

1844-
if (IID == Intrinsic::smul_with_overflow)
1844+
if (IsSigned)
18451845
Cost += thisT()->getArithmeticInstrCost(Instruction::AShr, MulTy,
18461846
CostKind, TTI::OK_AnyValue,
18471847
TTI::OK_UniformConstantValue);

0 commit comments

Comments
 (0)