Skip to content

Commit 98d8b68

Browse files
authored
[InstSimplify] Check call for FMF instead of CtxI (llvm#71585)
This code was incorrectly checking that the CtxI has required FMF, but the context instruction need not always be the instrinsic call. Check that the intrinsic call has the required FMF. Fixes PR71548.
1 parent ea82853 commit 98d8b68

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

llvm/lib/Analysis/InstructionSimplify.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6161,7 +6161,8 @@ static Value *simplifyLdexp(Value *Op0, Value *Op1, const SimplifyQuery &Q,
61616161
}
61626162

61636163
static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
6164-
const SimplifyQuery &Q) {
6164+
const SimplifyQuery &Q,
6165+
const CallBase *Call) {
61656166
// Idempotent functions return the same result when called repeatedly.
61666167
Intrinsic::ID IID = F->getIntrinsicID();
61676168
if (isIdempotent(IID))
@@ -6212,31 +6213,31 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
62126213
}
62136214
case Intrinsic::exp:
62146215
// exp(log(x)) -> x
6215-
if (Q.CxtI->hasAllowReassoc() &&
6216+
if (Call->hasAllowReassoc() &&
62166217
match(Op0, m_Intrinsic<Intrinsic::log>(m_Value(X))))
62176218
return X;
62186219
break;
62196220
case Intrinsic::exp2:
62206221
// exp2(log2(x)) -> x
6221-
if (Q.CxtI->hasAllowReassoc() &&
6222+
if (Call->hasAllowReassoc() &&
62226223
match(Op0, m_Intrinsic<Intrinsic::log2>(m_Value(X))))
62236224
return X;
62246225
break;
62256226
case Intrinsic::exp10:
62266227
// exp10(log10(x)) -> x
6227-
if (Q.CxtI->hasAllowReassoc() &&
6228+
if (Call->hasAllowReassoc() &&
62286229
match(Op0, m_Intrinsic<Intrinsic::log10>(m_Value(X))))
62296230
return X;
62306231
break;
62316232
case Intrinsic::log:
62326233
// log(exp(x)) -> x
6233-
if (Q.CxtI->hasAllowReassoc() &&
6234+
if (Call->hasAllowReassoc() &&
62346235
match(Op0, m_Intrinsic<Intrinsic::exp>(m_Value(X))))
62356236
return X;
62366237
break;
62376238
case Intrinsic::log2:
62386239
// log2(exp2(x)) -> x
6239-
if (Q.CxtI->hasAllowReassoc() &&
6240+
if (Call->hasAllowReassoc() &&
62406241
(match(Op0, m_Intrinsic<Intrinsic::exp2>(m_Value(X))) ||
62416242
match(Op0,
62426243
m_Intrinsic<Intrinsic::pow>(m_SpecificFP(2.0), m_Value(X)))))
@@ -6245,7 +6246,7 @@ static Value *simplifyUnaryIntrinsic(Function *F, Value *Op0,
62456246
case Intrinsic::log10:
62466247
// log10(pow(10.0, x)) -> x
62476248
// log10(exp10(x)) -> x
6248-
if (Q.CxtI->hasAllowReassoc() &&
6249+
if (Call->hasAllowReassoc() &&
62496250
(match(Op0, m_Intrinsic<Intrinsic::exp10>(m_Value(X))) ||
62506251
match(Op0,
62516252
m_Intrinsic<Intrinsic::pow>(m_SpecificFP(10.0), m_Value(X)))))
@@ -6346,7 +6347,8 @@ static Value *foldMinimumMaximumSharedOp(Intrinsic::ID IID, Value *Op0,
63466347
}
63476348

63486349
static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
6349-
const SimplifyQuery &Q) {
6350+
const SimplifyQuery &Q,
6351+
const CallBase *Call) {
63506352
Intrinsic::ID IID = F->getIntrinsicID();
63516353
Type *ReturnType = F->getReturnType();
63526354
unsigned BitWidth = ReturnType->getScalarSizeInBits();
@@ -6606,20 +6608,19 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1,
66066608
// float, if the ninf flag is set.
66076609
const APFloat *C;
66086610
if (match(Op1, m_APFloat(C)) &&
6609-
(C->isInfinity() || (isa<FPMathOperator>(Q.CxtI) &&
6610-
Q.CxtI->hasNoInfs() && C->isLargest()))) {
6611+
(C->isInfinity() || (Call->hasNoInfs() && C->isLargest()))) {
66116612
// minnum(X, -inf) -> -inf
66126613
// maxnum(X, +inf) -> +inf
66136614
// minimum(X, -inf) -> -inf if nnan
66146615
// maximum(X, +inf) -> +inf if nnan
6615-
if (C->isNegative() == IsMin && (!PropagateNaN || Q.CxtI->hasNoNaNs()))
6616+
if (C->isNegative() == IsMin && (!PropagateNaN || Call->hasNoNaNs()))
66166617
return ConstantFP::get(ReturnType, *C);
66176618

66186619
// minnum(X, +inf) -> X if nnan
66196620
// maxnum(X, -inf) -> X if nnan
66206621
// minimum(X, +inf) -> X
66216622
// maximum(X, -inf) -> X
6622-
if (C->isNegative() != IsMin && (PropagateNaN || Q.CxtI->hasNoNaNs()))
6623+
if (C->isNegative() != IsMin && (PropagateNaN || Call->hasNoNaNs()))
66236624
return Op0;
66246625
}
66256626

@@ -6678,10 +6679,10 @@ static Value *simplifyIntrinsic(CallBase *Call, Value *Callee,
66786679
}
66796680

66806681
if (NumOperands == 1)
6681-
return simplifyUnaryIntrinsic(F, Args[0], Q);
6682+
return simplifyUnaryIntrinsic(F, Args[0], Q, Call);
66826683

66836684
if (NumOperands == 2)
6684-
return simplifyBinaryIntrinsic(F, Args[0], Args[1], Q);
6685+
return simplifyBinaryIntrinsic(F, Args[0], Args[1], Q, Call);
66856686

66866687
// Handle intrinsics with 3 or more arguments.
66876688
switch (IID) {

0 commit comments

Comments
 (0)