Skip to content

Commit

Permalink
[NFC] Save 60% of the time spent creating integer types
Browse files Browse the repository at this point in the history
  • Loading branch information
darthscsi committed Mar 10, 2024
1 parent 99968ff commit c8ad1d6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/Dialect/FIRRTL/FIRRTLOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4898,8 +4898,15 @@ FIRRTLType impl::inferBitwiseResult(FIRRTLType lhs, FIRRTLType rhs,
if (!isSameIntTypeKind(lhs, rhs, lhsWidth, rhsWidth, isConstResult, loc))
return {};

if (lhsWidth != -1 && rhsWidth != -1)
if (lhsWidth != -1 && rhsWidth != -1) {
resultWidth = std::max(lhsWidth, rhsWidth);
if (lhsWidth == resultWidth && lhs.isConst() == isConstResult &&
isa<UIntType>(lhs))
return lhs;
if (rhsWidth == resultWidth && rhs.isConst() == isConstResult &&
isa<UIntType>(rhs))
return rhs;
}
return UIntType::get(lhs.getContext(), resultWidth, isConstResult);
}

Expand Down Expand Up @@ -5083,6 +5090,8 @@ FIRRTLType NotPrimOp::inferUnaryReturnType(FIRRTLType input,
auto inputi = type_dyn_cast<IntType>(input);
if (!inputi)
return emitInferRetTypeError(loc, "operand must have integer type");
if (isa<UIntType>(inputi))
return inputi;
return UIntType::get(input.getContext(), inputi.getWidthOrSentinel(),
inputi.isConst());
}
Expand Down

0 comments on commit c8ad1d6

Please sign in to comment.