Skip to content

Commit d2173d8

Browse files
committed
[InstCombine] foldFCmpIntToFPConst - simplify repeated calls to getBitWidth/getScalarSizeInBits. NFC.
Noticed on #82241 - we don't need to use the IntegerType just for the scalar width, and we were calling it 3 times in different forms - we can just call Type::getScalarSizeInBits once and reuse.
1 parent 7f3980a commit d2173d8

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7294,14 +7294,14 @@ Instruction *InstCombinerImpl::foldFCmpIntToFPConst(FCmpInst &I,
72947294
int MantissaWidth = LHSI->getType()->getFPMantissaWidth();
72957295
if (MantissaWidth == -1) return nullptr; // Unknown.
72967296

7297-
IntegerType *IntTy = cast<IntegerType>(LHSI->getOperand(0)->getType());
7298-
7297+
Type *IntTy = LHSI->getOperand(0)->getType();
7298+
unsigned IntWidth = IntTy->getScalarSizeInBits();
72997299
bool LHSUnsigned = isa<UIToFPInst>(LHSI);
73007300

73017301
if (I.isEquality()) {
73027302
FCmpInst::Predicate P = I.getPredicate();
73037303
bool IsExact = false;
7304-
APSInt RHSCvt(IntTy->getBitWidth(), LHSUnsigned);
7304+
APSInt RHSCvt(IntWidth, LHSUnsigned);
73057305
RHS.convertToInteger(RHSCvt, APFloat::rmNearestTiesToEven, &IsExact);
73067306

73077307
// If the floating point constant isn't an integer value, we know if we will
@@ -7326,23 +7326,22 @@ Instruction *InstCombinerImpl::foldFCmpIntToFPConst(FCmpInst &I,
73267326
// Check to see that the input is converted from an integer type that is small
73277327
// enough that preserves all bits. TODO: check here for "known" sign bits.
73287328
// This would allow us to handle (fptosi (x >>s 62) to float) if x is i64 f.e.
7329-
unsigned InputSize = IntTy->getScalarSizeInBits();
73307329

7331-
// Following test does NOT adjust InputSize downwards for signed inputs,
7330+
// Following test does NOT adjust IntWidth downwards for signed inputs,
73327331
// because the most negative value still requires all the mantissa bits
73337332
// to distinguish it from one less than that value.
7334-
if ((int)InputSize > MantissaWidth) {
7333+
if ((int)IntWidth > MantissaWidth) {
73357334
// Conversion would lose accuracy. Check if loss can impact comparison.
73367335
int Exp = ilogb(RHS);
73377336
if (Exp == APFloat::IEK_Inf) {
73387337
int MaxExponent = ilogb(APFloat::getLargest(RHS.getSemantics()));
7339-
if (MaxExponent < (int)InputSize - !LHSUnsigned)
7338+
if (MaxExponent < (int)IntWidth - !LHSUnsigned)
73407339
// Conversion could create infinity.
73417340
return nullptr;
73427341
} else {
73437342
// Note that if RHS is zero or NaN, then Exp is negative
73447343
// and first condition is trivially false.
7345-
if (MantissaWidth <= Exp && Exp <= (int)InputSize - !LHSUnsigned)
7344+
if (MantissaWidth <= Exp && Exp <= (int)IntWidth - !LHSUnsigned)
73467345
// Conversion could affect comparison.
73477346
return nullptr;
73487347
}
@@ -7390,8 +7389,6 @@ Instruction *InstCombinerImpl::foldFCmpIntToFPConst(FCmpInst &I,
73907389

73917390
// See if the FP constant is too large for the integer. For example,
73927391
// comparing an i8 to 300.0.
7393-
unsigned IntWidth = IntTy->getScalarSizeInBits();
7394-
73957392
if (!LHSUnsigned) {
73967393
// If the RHS value is > SignedMax, fold the comparison. This handles +INF
73977394
// and large values.

0 commit comments

Comments
 (0)