@@ -7909,7 +7909,8 @@ static Instruction *foldFCmpFNegCommonOp(FCmpInst &I) {
7909
7909
static Instruction *foldFCmpFSubIntoFCmp (FCmpInst &I, Instruction *LHSI,
7910
7910
Constant *RHSC, InstCombinerImpl &CI) {
7911
7911
const CmpInst::Predicate Pred = I.getPredicate ();
7912
- Value *X, *Y;
7912
+ Value *X = LHSI->getOperand (0 );
7913
+ Value *Y = LHSI->getOperand (1 );
7913
7914
switch (Pred) {
7914
7915
default :
7915
7916
break ;
@@ -7919,8 +7920,10 @@ static Instruction *foldFCmpFSubIntoFCmp(FCmpInst &I, Instruction *LHSI,
7919
7920
case FCmpInst::FCMP_OEQ:
7920
7921
case FCmpInst::FCMP_OGE:
7921
7922
case FCmpInst::FCMP_OLE:
7922
- // Skip optimization: fsub x, y unless guaranteed !isinf(x) ||
7923
- // !isinf(y).
7923
+ // The optimization is not valid if X and Y are infinities of the same
7924
+ // sign, i.e. the inf - inf = nan case. If the fsub has the ninf or nnan
7925
+ // flag then we can assume we do not have that case. Otherwise we might be
7926
+ // able to prove that either X or Y is not infinity.
7924
7927
if (!LHSI->hasNoNaNs () && !LHSI->hasNoInfs () &&
7925
7928
!isKnownNeverInfinity (LHSI->getOperand (1 ), /* Depth=*/ 0 ,
7926
7929
CI.getSimplifyQuery ().getWithInstruction (&I)) &&
@@ -7937,7 +7940,6 @@ static Instruction *foldFCmpFSubIntoFCmp(FCmpInst &I, Instruction *LHSI,
7937
7940
case FCmpInst::FCMP_ULE:
7938
7941
// fcmp pred (x - y), 0 --> fcmp pred x, y
7939
7942
if (match (RHSC, m_AnyZeroFP ()) &&
7940
- match (LHSI, m_FSub (m_Value (X), m_Value (Y))) &&
7941
7943
I.getFunction ()->getDenormalMode (
7942
7944
LHSI->getType ()->getScalarType ()->getFltSemantics ()) ==
7943
7945
DenormalMode::getIEEE ()) {
0 commit comments