[Analysis][LoopVectorize] rename "Unsafe" variables/methods; NFC

We are tracking an FP instruction that does *not* have FMF (reassoc)
properties, so calling that "Unsafe" seems opposite of the common
reading.

I also removed one getter method by rolling the null check into
the access. Further simplification seems possible.

The motivation is to clean up the interactions between FMF and
function-level attributes in these classes and their callers.
This commit is contained in:
Sanjay Patel 2021-03-04 08:47:46 -05:00
parent 91c9dee3fb
commit b3a33553ae
4 changed files with 29 additions and 30 deletions

View File

@ -68,29 +68,29 @@ public:
RecurrenceDescriptor() = default;
RecurrenceDescriptor(Value *Start, Instruction *Exit, RecurKind K,
FastMathFlags FMF, Instruction *UAI, Type *RT,
FastMathFlags FMF, Instruction *ExactFP, Type *RT,
bool Signed, SmallPtrSetImpl<Instruction *> &CI)
: StartValue(Start), LoopExitInstr(Exit), Kind(K), FMF(FMF),
UnsafeAlgebraInst(UAI), RecurrenceType(RT), IsSigned(Signed) {
ExactFPMathInst(ExactFP), RecurrenceType(RT), IsSigned(Signed) {
CastInsts.insert(CI.begin(), CI.end());
}
/// This POD struct holds information about a potential recurrence operation.
class InstDesc {
public:
InstDesc(bool IsRecur, Instruction *I, Instruction *UAI = nullptr)
InstDesc(bool IsRecur, Instruction *I, Instruction *ExactFP = nullptr)
: IsRecurrence(IsRecur), PatternLastInst(I),
RecKind(RecurKind::None), UnsafeAlgebraInst(UAI) {}
RecKind(RecurKind::None), ExactFPMathInst(ExactFP) {}
InstDesc(Instruction *I, RecurKind K, Instruction *UAI = nullptr)
InstDesc(Instruction *I, RecurKind K, Instruction *ExactFP = nullptr)
: IsRecurrence(true), PatternLastInst(I), RecKind(K),
UnsafeAlgebraInst(UAI) {}
ExactFPMathInst(ExactFP) {}
bool isRecurrence() const { return IsRecurrence; }
bool hasUnsafeAlgebra() const { return UnsafeAlgebraInst != nullptr; }
bool needsExactFPMath() const { return ExactFPMathInst != nullptr; }
Instruction *getUnsafeAlgebraInst() const { return UnsafeAlgebraInst; }
Instruction *getExactFPMathInst() const { return ExactFPMathInst; }
RecurKind getRecKind() const { return RecKind; }
@ -104,8 +104,8 @@ public:
Instruction *PatternLastInst;
// If this is a min/max pattern.
RecurKind RecKind;
// Recurrence has unsafe algebra.
Instruction *UnsafeAlgebraInst;
// Recurrence does not allow floating-point reassociation.
Instruction *ExactFPMathInst;
};
/// Returns a struct describing if the instruction 'I' can be a recurrence
@ -184,12 +184,12 @@ public:
Instruction *getLoopExitInstr() const { return LoopExitInstr; }
/// Returns true if the recurrence has unsafe algebra which requires a relaxed
/// floating-point model.
bool hasUnsafeAlgebra() const { return UnsafeAlgebraInst != nullptr; }
/// Returns true if the recurrence has floating-point math that requires
/// precise (ordered) operations.
bool hasExactFPMath() const { return ExactFPMathInst != nullptr; }
/// Returns first unsafe algebra instruction in the PHI node's use-chain.
Instruction *getUnsafeAlgebraInst() const { return UnsafeAlgebraInst; }
/// Returns 1st non-reassociative FP instruction in the PHI node's use-chain.
Instruction *getExactFPMathInst() const { return ExactFPMathInst; }
/// Returns true if the recurrence kind is an integer kind.
static bool isIntegerRecurrenceKind(RecurKind Kind);
@ -243,8 +243,8 @@ private:
// The fast-math flags on the recurrent instructions. We propagate these
// fast-math flags into the vectorized FP instructions we generate.
FastMathFlags FMF;
// First occurrence of unasfe algebra in the PHI's use-chain.
Instruction *UnsafeAlgebraInst = nullptr;
// First instance of non-reassociative floating-point in the PHI's use-chain.
Instruction *ExactFPMathInst = nullptr;
// The type of the recurrence.
Type *RecurrenceType = nullptr;
// True if all source operands of the recurrence are SExtInsts.

View File

@ -179,10 +179,10 @@ class LoopVectorizationRequirements {
public:
LoopVectorizationRequirements(OptimizationRemarkEmitter &ORE) : ORE(ORE) {}
void addUnsafeAlgebraInst(Instruction *I) {
// First unsafe algebra instruction.
if (!UnsafeAlgebraInst)
UnsafeAlgebraInst = I;
/// Track the 1st floating-point instruction that can not be reassociated.
void addExactFPMathInst(Instruction *I) {
if (I && !ExactFPMathInst)
ExactFPMathInst = I;
}
void addRuntimePointerChecks(unsigned Num) { NumRuntimePointerChecks = Num; }
@ -191,7 +191,7 @@ public:
private:
unsigned NumRuntimePointerChecks = 0;
Instruction *UnsafeAlgebraInst = nullptr;
Instruction *ExactFPMathInst = nullptr;
/// Interface to emit optimization remarks.
OptimizationRemarkEmitter &ORE;

View File

@ -469,7 +469,7 @@ bool RecurrenceDescriptor::AddReductionVar(PHINode *Phi, RecurKind Kind,
// Save the description of this reduction variable.
RecurrenceDescriptor RD(RdxStart, ExitInstruction, Kind, FMF,
ReduxDesc.getUnsafeAlgebraInst(), RecurrenceType,
ReduxDesc.getExactFPMathInst(), RecurrenceType,
IsSigned, CastInsts);
RedDes = RD;
@ -569,7 +569,7 @@ RecurrenceDescriptor::isRecurrenceInstr(Instruction *I, RecurKind Kind,
default:
return InstDesc(false, I);
case Instruction::PHI:
return InstDesc(I, Prev.getRecKind(), Prev.getUnsafeAlgebraInst());
return InstDesc(I, Prev.getRecKind(), Prev.getExactFPMathInst());
case Instruction::Sub:
case Instruction::Add:
return InstDesc(Kind == RecurKind::Add, I);

View File

@ -250,11 +250,11 @@ bool LoopVectorizationRequirements::doesNotMeet(
Function *F, Loop *L, const LoopVectorizeHints &Hints) {
const char *PassName = Hints.vectorizeAnalysisPassName();
bool Failed = false;
if (UnsafeAlgebraInst && !Hints.allowReordering()) {
if (ExactFPMathInst && !Hints.allowReordering()) {
ORE.emit([&]() {
return OptimizationRemarkAnalysisFPCommute(
PassName, "CantReorderFPOps", UnsafeAlgebraInst->getDebugLoc(),
UnsafeAlgebraInst->getParent())
PassName, "CantReorderFPOps", ExactFPMathInst->getDebugLoc(),
ExactFPMathInst->getParent())
<< "loop not vectorized: cannot prove it is safe to reorder "
"floating-point operations";
});
@ -651,8 +651,7 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
RecurrenceDescriptor RedDes;
if (RecurrenceDescriptor::isReductionPHI(Phi, TheLoop, RedDes, DB, AC,
DT)) {
if (RedDes.hasUnsafeAlgebra())
Requirements->addUnsafeAlgebraInst(RedDes.getUnsafeAlgebraInst());
Requirements->addExactFPMathInst(RedDes.getExactFPMathInst());
AllowedExit.insert(RedDes.getLoopExitInstr());
Reductions[Phi] = RedDes;
continue;
@ -676,7 +675,7 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
if (InductionDescriptor::isInductionPHI(Phi, TheLoop, PSE, ID)) {
addInductionPhi(Phi, ID, AllowedExit);
if (ID.hasUnsafeAlgebra())
Requirements->addUnsafeAlgebraInst(ID.getUnsafeAlgebraInst());
Requirements->addExactFPMathInst(ID.getUnsafeAlgebraInst());
continue;
}