Skip to content

Commit dad0c54

Browse files
committed
!fixup adjust code, thanks
1 parent ec12921 commit dad0c54

File tree

1 file changed

+34
-24
lines changed

1 file changed

+34
-24
lines changed

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,32 @@ static FastMathFlags collectMinMaxFMF(Value *V) {
231231
static std::optional<FastMathFlags>
232232
hasRequiredFastMathFlags(FPMathOperator *FPOp, RecurKind &RK,
233233
FastMathFlags FuncFMF) {
234-
bool HasRequiredFMF =
235-
(FuncFMF.noNaNs() && FuncFMF.noSignedZeros()) ||
236-
(FPOp && FPOp->hasNoNaNs() && FPOp->hasNoSignedZeros()) ||
237-
RK == RecurKind::FMinimum || RK == RecurKind::FMaximum ||
238-
RK == RecurKind::FMinimumNum || RK == RecurKind::FMaximumNum;
239-
if (!HasRequiredFMF) {
240-
if (RK == RecurKind::FMax &&
241-
match(FPOp, m_Intrinsic<Intrinsic::maxnum>(m_Value(), m_Value())))
242-
RK = RecurKind::FMaxNum;
243-
else if (RK == RecurKind::FMin &&
244-
match(FPOp, m_Intrinsic<Intrinsic::minnum>(m_Value(), m_Value())))
245-
RK = RecurKind::FMinNum;
246-
else
234+
bool HasRequiredFMF = (FuncFMF.noNaNs() && FuncFMF.noSignedZeros()) ||
235+
(FPOp && FPOp->hasNoNaNs() && FPOp->hasNoSignedZeros());
236+
if (HasRequiredFMF)
237+
return collectMinMaxFMF(FPOp);
238+
239+
switch (RK) {
240+
case RecurKind::FMinimum:
241+
case RecurKind::FMaximum:
242+
case RecurKind::FMinimumNum:
243+
case RecurKind::FMaximumNum:
244+
break;
245+
246+
case RecurKind::FMax:
247+
if (!match(FPOp, m_Intrinsic<Intrinsic::maxnum>(m_Value(), m_Value())))
248+
return std::nullopt;
249+
RK = RecurKind::FMaxNum;
250+
break;
251+
case RecurKind::FMin:
252+
if (!match(FPOp, m_Intrinsic<Intrinsic::minnum>(m_Value(), m_Value())))
247253
return std::nullopt;
254+
RK = RecurKind::FMinNum;
255+
break;
256+
default:
257+
return std::nullopt;
248258
}
249-
return {collectMinMaxFMF(FPOp)};
259+
return collectMinMaxFMF(FPOp);
250260
}
251261

252262
static RecurrenceDescriptor getMinMaxRecurrence(PHINode *Phi, Loop *TheLoop,
@@ -261,7 +271,7 @@ static RecurrenceDescriptor getMinMaxRecurrence(PHINode *Phi, Loop *TheLoop,
261271
if ((!Ty->isIntegerTy() && !Ty->isFloatingPointTy()) || !Latch)
262272
return {};
263273

264-
auto Matches = [](Value *V, Value *&A, Value *&B) -> RecurKind {
274+
auto GetMinMaxRK = [](Value *V, Value *&A, Value *&B) -> RecurKind {
265275
if (match(V, m_UMin(m_Value(A), m_Value(B))))
266276
return RecurKind::UMin;
267277
if (match(V, m_UMax(m_Value(A), m_Value(B))))
@@ -292,8 +302,8 @@ static RecurrenceDescriptor getMinMaxRecurrence(PHINode *Phi, Loop *TheLoop,
292302
RecurKind RK = RecurKind::None;
293303
// Identify min/max recurrences by walking the def-use chains upwards,
294304
// starting at RdxNext.
295-
SmallVector<Value *> WorkList = {RdxNext};
296-
SmallPtrSet<Value *, 8> Chain = {Phi};
305+
SmallVector<Value *> WorkList({RdxNext});
306+
SmallPtrSet<Value *, 8> Chain({Phi});
297307
while (!WorkList.empty()) {
298308
Value *Cur = WorkList.pop_back_val();
299309
if (!Chain.insert(Cur).second)
@@ -307,19 +317,19 @@ static RecurrenceDescriptor getMinMaxRecurrence(PHINode *Phi, Loop *TheLoop,
307317
continue;
308318
}
309319
Value *A, *B;
310-
RecurKind CurRK = Matches(Cur, A, B);
320+
RecurKind CurRK = GetMinMaxRK(Cur, A, B);
311321
if (CurRK == RecurKind::None || (RK != RecurKind::None && CurRK != RK))
312322
return {};
313323

314324
RK = CurRK;
315325
// For floating point recurrences, check we have the required fast-math
316326
// flags.
317327
if (RecurrenceDescriptor::isFPMinMaxRecurrenceKind(CurRK)) {
318-
if (auto CurFMF =
319-
hasRequiredFastMathFlags(cast<FPMathOperator>(Cur), RK, FuncFMF))
320-
FMF &= *CurFMF;
321-
else
328+
auto CurFMF =
329+
hasRequiredFastMathFlags(cast<FPMathOperator>(Cur), RK, FuncFMF);
330+
if (!CurFMF)
322331
return {};
332+
FMF &= *CurFMF;
323333
}
324334

325335
Chain.insert(I);
@@ -334,8 +344,8 @@ static RecurrenceDescriptor getMinMaxRecurrence(PHINode *Phi, Loop *TheLoop,
334344
Value *X, *Y;
335345
auto *IA = dyn_cast<Instruction>(A);
336346
auto *IB = dyn_cast<Instruction>(B);
337-
bool AMatches = IA && TheLoop->contains(IA) && Matches(A, X, Y) == RK;
338-
bool BMatches = IB && TheLoop->contains(IB) && Matches(B, X, Y) == RK;
347+
bool AMatches = IA && TheLoop->contains(IA) && GetMinMaxRK(A, X, Y) == RK;
348+
bool BMatches = IB && TheLoop->contains(IB) && GetMinMaxRK(B, X, Y) == RK;
339349
if (AMatches == BMatches) // Both or neither match
340350
return {};
341351
WorkList.push_back(AMatches ? A : B);

0 commit comments

Comments
 (0)