@@ -3682,39 +3682,27 @@ static Value *foldSelectIntoAddConstant(SelectInst &SI,
36823682
36833683 // Note: OneUse check for `Cmp` is necessary because it makes sure that other
36843684 // InstCombine folds don't undo this transformation and cause an infinite
3685- // loop.
3685+ // loop. Furthermore, it could also increase the operation count.
36863686 if (match (&SI, m_Select (m_OneUse (m_FCmp (Pred, m_Value (X), m_Value (Z))),
36873687 m_OneUse (m_Instruction (FAdd)), m_Constant (C))) ||
36883688 match (&SI, m_Select (m_OneUse (m_FCmp (Pred, m_Value (X), m_Value (Z))),
36893689 m_Constant (C), m_OneUse (m_Instruction (FAdd))))) {
36903690 if (!match (Z, m_AnyZeroFP ()))
36913691 return nullptr ;
36923692
3693- // Only these Predicates can be transformed into fmaxnum/fminnum intrinsic.
3694- switch (Pred) {
3695- default :
3693+ // Only these relational predicates can be transformed into maxnum/minnum
3694+ // intrinsic.
3695+ if (! CmpInst::isRelational (Pred))
36963696 return nullptr ;
3697- case FCmpInst::FCMP_OGT:
3698- case FCmpInst::FCMP_OGE:
3699- case FCmpInst::FCMP_OLT:
3700- case FCmpInst::FCMP_OLE:
3701- case FCmpInst::FCMP_UGT:
3702- case FCmpInst::FCMP_UGE:
3703- case FCmpInst::FCMP_ULT:
3704- case FCmpInst::FCMP_ULE:
3705- break ;
3706- }
37073697
37083698 if (!match (FAdd, m_FAdd (m_Specific (X), m_Specific (C))))
37093699 return nullptr ;
37103700
3711- Value *NewSelect = Builder. CreateSelect (SI. getCondition (), X, Z,
3712- SI.getName () + " .new " , &SI);
3701+ Value *NewSelect =
3702+ Builder. CreateSelect (SI. getCondition (), X, Z, SI.getName (), &SI);
37133703 cast<Instruction>(NewSelect)->setFastMathFlags (SI.getFastMathFlags ());
37143704
3715- Value *NewFAdd =
3716- Builder.CreateFAddFMF (NewSelect, C, FAdd, FAdd->getName () + " .new" );
3717- return NewFAdd;
3705+ return Builder.CreateFAddFMF (NewSelect, C, FAdd, FAdd->getName ());
37183706 }
37193707
37203708 return nullptr ;
0 commit comments