@@ -993,7 +993,6 @@ static void addToWorklist(Instruction &I,
993993static bool runImpl (Function &F, const TargetLowering &TLI,
994994 AssumptionCache *AC) {
995995 SmallVector<Instruction *, 4 > Worklist;
996- bool Modified = false ;
997996
998997 unsigned MaxLegalFpConvertBitWidth =
999998 TLI.getMaxLargeFPConvertBitWidthSupported ();
@@ -1003,50 +1002,49 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
10031002 if (MaxLegalFpConvertBitWidth >= llvm::IntegerType::MAX_INT_BITS)
10041003 return false ;
10051004
1006- for (auto It = inst_begin (&F), End = inst_end (F); It != End;) {
1007- Instruction &I = *It++;
1005+ auto ShouldHandleInst = [&](Instruction &I) {
10081006 Type *Ty = I.getType ();
10091007 // TODO: This pass doesn't handle scalable vectors.
10101008 if (Ty->isScalableTy ())
1011- continue ;
1009+ return false ;
10121010
10131011 switch (I.getOpcode ()) {
10141012 case Instruction::FRem:
1015- if (!targetSupportsFrem (TLI, Ty) &&
1016- FRemExpander::canExpandType (Ty->getScalarType ())) {
1017- addToWorklist (I, Worklist);
1018- Modified = true ;
1019- }
1020- break ;
1013+ return !targetSupportsFrem (TLI, Ty) &&
1014+ FRemExpander::canExpandType (Ty->getScalarType ());
1015+
10211016 case Instruction::FPToUI:
10221017 case Instruction::FPToSI: {
10231018 auto *IntTy = cast<IntegerType>(Ty->getScalarType ());
1024- if (IntTy->getIntegerBitWidth () <= MaxLegalFpConvertBitWidth)
1025- continue ;
1026-
1027- addToWorklist (I, Worklist);
1028- Modified = true ;
1029- break ;
1019+ return IntTy->getIntegerBitWidth () > MaxLegalFpConvertBitWidth;
10301020 }
1021+
10311022 case Instruction::UIToFP:
10321023 case Instruction::SIToFP: {
10331024 auto *IntTy =
10341025 cast<IntegerType>(I.getOperand (0 )->getType ()->getScalarType ());
1035- if (IntTy->getIntegerBitWidth () <= MaxLegalFpConvertBitWidth)
1036- continue ;
1037-
1038- addToWorklist (I, Worklist);
1039- Modified = true ;
1040- break ;
1026+ return IntTy->getIntegerBitWidth () > MaxLegalFpConvertBitWidth;
10411027 }
1042- default :
1043- break ;
10441028 }
1029+
1030+ return false ;
1031+ };
1032+
1033+ bool Modified = false ;
1034+ for (auto It = inst_begin (&F), End = inst_end (F); It != End;) {
1035+ Instruction &I = *It++;
1036+ if (!ShouldHandleInst (I))
1037+ continue ;
1038+
1039+ addToWorklist (I, Worklist);
1040+ Modified = true ;
10451041 }
10461042
10471043 while (!Worklist.empty ()) {
10481044 Instruction *I = Worklist.pop_back_val ();
1049- if (I->getOpcode () == Instruction::FRem) {
1045+
1046+ switch (I->getOpcode ()) {
1047+ case Instruction::FRem: {
10501048 auto SQ = [&]() -> std::optional<SimplifyQuery> {
10511049 if (AC) {
10521050 auto Res = std::make_optional<SimplifyQuery>(
@@ -1058,11 +1056,18 @@ static bool runImpl(Function &F, const TargetLowering &TLI,
10581056 }();
10591057
10601058 expandFRem (cast<BinaryOperator>(*I), SQ);
1061- } else if (I->getOpcode () == Instruction::FPToUI ||
1062- I->getOpcode () == Instruction::FPToSI) {
1059+ break ;
1060+ }
1061+
1062+ case Instruction::FPToUI:
1063+ case Instruction::FPToSI:
10631064 expandFPToI (I);
1064- } else {
1065+ break ;
1066+
1067+ case Instruction::UIToFP:
1068+ case Instruction::SIToFP:
10651069 expandIToFP (I);
1070+ break ;
10661071 }
10671072 }
10681073
0 commit comments