Skip to content

Commit 92f7c1e

Browse files
committed
TTI: Check legalization cost of mul overflow ISD nodes
1 parent d52cc9d commit 92f7c1e

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

llvm/include/llvm/CodeGen/BasicTTIImpl.h

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,37 +2196,11 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
21962196
ISD = ISD::USUBO;
21972197
break;
21982198
case Intrinsic::smul_with_overflow:
2199-
case Intrinsic::umul_with_overflow: {
2200-
Type *MulTy = RetTy->getContainedType(0);
2201-
Type *OverflowTy = RetTy->getContainedType(1);
2202-
unsigned ExtSize = MulTy->getScalarSizeInBits() * 2;
2203-
Type *ExtTy = MulTy->getWithNewBitWidth(ExtSize);
2204-
bool IsSigned = IID == Intrinsic::smul_with_overflow;
2205-
2206-
unsigned ExtOp = IsSigned ? Instruction::SExt : Instruction::ZExt;
2207-
TTI::CastContextHint CCH = TTI::CastContextHint::None;
2208-
2209-
InstructionCost Cost = 0;
2210-
Cost += 2 * thisT()->getCastInstrCost(ExtOp, ExtTy, MulTy, CCH, CostKind);
2211-
Cost +=
2212-
thisT()->getArithmeticInstrCost(Instruction::Mul, ExtTy, CostKind);
2213-
Cost += 2 * thisT()->getCastInstrCost(Instruction::Trunc, MulTy, ExtTy,
2214-
CCH, CostKind);
2215-
Cost += thisT()->getArithmeticInstrCost(Instruction::LShr, ExtTy,
2216-
CostKind,
2217-
{TTI::OK_AnyValue, TTI::OP_None},
2218-
{TTI::OK_UniformConstantValue, TTI::OP_None});
2219-
2220-
if (IsSigned)
2221-
Cost += thisT()->getArithmeticInstrCost(Instruction::AShr, MulTy,
2222-
CostKind,
2223-
{TTI::OK_AnyValue, TTI::OP_None},
2224-
{TTI::OK_UniformConstantValue, TTI::OP_None});
2225-
2226-
Cost += thisT()->getCmpSelInstrCost(
2227-
BinaryOperator::ICmp, MulTy, OverflowTy, CmpInst::ICMP_NE, CostKind);
2228-
return Cost;
2229-
}
2199+
ISD = ISD::SMULO;
2200+
break;
2201+
case Intrinsic::umul_with_overflow:
2202+
ISD = ISD::UMULO;
2203+
break;
22302204
case Intrinsic::fptosi_sat:
22312205
case Intrinsic::fptoui_sat: {
22322206
if (Tys.empty())
@@ -2371,6 +2345,37 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
23712345
OverflowTy, Pred, CostKind);
23722346
return Cost;
23732347
}
2348+
case Intrinsic::smul_with_overflow:
2349+
case Intrinsic::umul_with_overflow: {
2350+
Type *MulTy = RetTy->getContainedType(0);
2351+
Type *OverflowTy = RetTy->getContainedType(1);
2352+
unsigned ExtSize = MulTy->getScalarSizeInBits() * 2;
2353+
Type *ExtTy = MulTy->getWithNewBitWidth(ExtSize);
2354+
bool IsSigned = IID == Intrinsic::smul_with_overflow;
2355+
2356+
unsigned ExtOp = IsSigned ? Instruction::SExt : Instruction::ZExt;
2357+
TTI::CastContextHint CCH = TTI::CastContextHint::None;
2358+
2359+
InstructionCost Cost = 0;
2360+
Cost += 2 * thisT()->getCastInstrCost(ExtOp, ExtTy, MulTy, CCH, CostKind);
2361+
Cost +=
2362+
thisT()->getArithmeticInstrCost(Instruction::Mul, ExtTy, CostKind);
2363+
Cost += 2 * thisT()->getCastInstrCost(Instruction::Trunc, MulTy, ExtTy,
2364+
CCH, CostKind);
2365+
Cost += thisT()->getArithmeticInstrCost(
2366+
Instruction::LShr, ExtTy, CostKind, {TTI::OK_AnyValue, TTI::OP_None},
2367+
{TTI::OK_UniformConstantValue, TTI::OP_None});
2368+
2369+
if (IsSigned)
2370+
Cost += thisT()->getArithmeticInstrCost(
2371+
Instruction::AShr, MulTy, CostKind,
2372+
{TTI::OK_AnyValue, TTI::OP_None},
2373+
{TTI::OK_UniformConstantValue, TTI::OP_None});
2374+
2375+
Cost += thisT()->getCmpSelInstrCost(
2376+
BinaryOperator::ICmp, MulTy, OverflowTy, CmpInst::ICMP_NE, CostKind);
2377+
return Cost;
2378+
}
23742379
case Intrinsic::sadd_sat:
23752380
case Intrinsic::ssub_sat: {
23762381
// Assume a default expansion.

0 commit comments

Comments
 (0)