diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index ad51e163062012..2fff10df55038d 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -6161,7 +6161,8 @@ static Value *simplifyLdexp(Value *Op0, Value *Op1, const SimplifyQuery &Q, } static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0, - const SimplifyQuery &Q) { + const SimplifyQuery &Q, + const CallBase *Call) { // Idempotent functions return the same result when called repeatedly. Intrinsic::ID IID = F->getIntrinsicID(); if (isIdempotent(IID)) @@ -6212,31 +6213,31 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0, } case Intrinsic::exp: // exp(log(x)) -> x - if (Q.CxtI->hasAllowReassoc() && + if (Call->hasAllowReassoc() && match(Op0, m_Intrinsic(m_Value(X)))) return X; break; case Intrinsic::exp2: // exp2(log2(x)) -> x - if (Q.CxtI->hasAllowReassoc() && + if (Call->hasAllowReassoc() && match(Op0, m_Intrinsic(m_Value(X)))) return X; break; case Intrinsic::exp10: // exp10(log10(x)) -> x - if (Q.CxtI->hasAllowReassoc() && + if (Call->hasAllowReassoc() && match(Op0, m_Intrinsic(m_Value(X)))) return X; break; case Intrinsic::log: // log(exp(x)) -> x - if (Q.CxtI->hasAllowReassoc() && + if (Call->hasAllowReassoc() && match(Op0, m_Intrinsic(m_Value(X)))) return X; break; case Intrinsic::log2: // log2(exp2(x)) -> x - if (Q.CxtI->hasAllowReassoc() && + if (Call->hasAllowReassoc() && (match(Op0, m_Intrinsic(m_Value(X))) || match(Op0, m_Intrinsic(m_SpecificFP(2.0), m_Value(X))))) @@ -6245,7 +6246,7 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0, case Intrinsic::log10: // log10(pow(10.0, x)) -> x // log10(exp10(x)) -> x - if (Q.CxtI->hasAllowReassoc() && + if (Call->hasAllowReassoc() && (match(Op0, m_Intrinsic(m_Value(X))) || match(Op0, m_Intrinsic(m_SpecificFP(10.0), m_Value(X))))) @@ -6346,7 +6347,8 @@ static Value *foldMinimumMaximumSharedOp(Intrinsic::ID IID, Value *Op0, } static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1, - const SimplifyQuery &Q) { + const SimplifyQuery &Q, + const CallBase *Call) { Intrinsic::ID IID = F->getIntrinsicID(); Type *ReturnType = F->getReturnType(); unsigned BitWidth = ReturnType->getScalarSizeInBits(); @@ -6606,20 +6608,19 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1, // float, if the ninf flag is set. const APFloat *C; if (match(Op1, m_APFloat(C)) && - (C->isInfinity() || (isa(Q.CxtI) && - Q.CxtI->hasNoInfs() && C->isLargest()))) { + (C->isInfinity() || (Call->hasNoInfs() && C->isLargest()))) { // minnum(X, -inf) -> -inf // maxnum(X, +inf) -> +inf // minimum(X, -inf) -> -inf if nnan // maximum(X, +inf) -> +inf if nnan - if (C->isNegative() == IsMin && (!PropagateNaN || Q.CxtI->hasNoNaNs())) + if (C->isNegative() == IsMin && (!PropagateNaN || Call->hasNoNaNs())) return ConstantFP::get(ReturnType, *C); // minnum(X, +inf) -> X if nnan // maxnum(X, -inf) -> X if nnan // minimum(X, +inf) -> X // maximum(X, -inf) -> X - if (C->isNegative() != IsMin && (PropagateNaN || Q.CxtI->hasNoNaNs())) + if (C->isNegative() != IsMin && (PropagateNaN || Call->hasNoNaNs())) return Op0; } @@ -6678,10 +6679,10 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee, } if (NumOperands == 1) - return simplifyUnaryIntrinsic(F, Args[0], Q); + return simplifyUnaryIntrinsic(F, Args[0], Q, Call); if (NumOperands == 2) - return simplifyBinaryIntrinsic(F, Args[0], Args[1], Q); + return simplifyBinaryIntrinsic(F, Args[0], Args[1], Q, Call); // Handle intrinsics with 3 or more arguments. switch (IID) {