From b3f0c2653b61377413c02ce6f6cdeb452c9a8e79 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Wed, 3 Mar 2021 16:53:49 -0500 Subject: [PATCH] [Analysis] simplify propagation of FMF in recurrences; NFC This is a mess, but this is hopefully no-functional-change. The 'Prev' descriptor is only used for min/max recurrences or when starting a match from a phi, so it should not be a factor when propagating FMF for fmul/fadd. The API is confusing (and should be reduced in subsequent steps) because the "UnsafeAlgebraInst" appears to actually be a placeholder for a recurrence that does NOT have FMF, but we still want to treat it as reassociative. --- llvm/lib/Analysis/IVDescriptors.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp index ca8cd095d510..7cd9a8d4e10e 100644 --- a/llvm/lib/Analysis/IVDescriptors.cpp +++ b/llvm/lib/Analysis/IVDescriptors.cpp @@ -565,10 +565,6 @@ RecurrenceDescriptor::isConditionalRdxPattern(RecurKind Kind, Instruction *I) { RecurrenceDescriptor::InstDesc RecurrenceDescriptor::isRecurrenceInstr(Instruction *I, RecurKind Kind, InstDesc &Prev, FastMathFlags FMF) { - Instruction *UAI = Prev.getUnsafeAlgebraInst(); - if (!UAI && isa(I) && !I->hasAllowReassoc()) - UAI = I; // Found an unsafe (unvectorizable) algebra instruction. - switch (I->getOpcode()) { default: return InstDesc(false, I); @@ -587,10 +583,12 @@ RecurrenceDescriptor::isRecurrenceInstr(Instruction *I, RecurKind Kind, return InstDesc(Kind == RecurKind::Xor, I); case Instruction::FDiv: case Instruction::FMul: - return InstDesc(Kind == RecurKind::FMul, I, UAI); + return InstDesc(Kind == RecurKind::FMul, I, + I->hasAllowReassoc() ? nullptr : I); case Instruction::FSub: case Instruction::FAdd: - return InstDesc(Kind == RecurKind::FAdd, I, UAI); + return InstDesc(Kind == RecurKind::FAdd, I, + I->hasAllowReassoc() ? nullptr : I); case Instruction::Select: if (Kind == RecurKind::FAdd || Kind == RecurKind::FMul) return isConditionalRdxPattern(Kind, I); @@ -598,8 +596,7 @@ RecurrenceDescriptor::isRecurrenceInstr(Instruction *I, RecurKind Kind, case Instruction::FCmp: case Instruction::ICmp: if (isIntMinMaxRecurrenceKind(Kind) || - (FMF.noNaNs() && FMF.noSignedZeros() && - isFPMinMaxRecurrenceKind(Kind))) + (FMF.noNaNs() && FMF.noSignedZeros() && isFPMinMaxRecurrenceKind(Kind))) return isMinMaxSelectCmpPattern(I, Prev); return InstDesc(false, I); }