Skip to content

Commit b3a3355

Browse files
committed
[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.
1 parent 91c9dee commit b3a3355

File tree

4 files changed

+29
-30
lines changed

4 files changed

+29
-30
lines changed

llvm/include/llvm/Analysis/IVDescriptors.h

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,29 @@ class RecurrenceDescriptor {
6868
RecurrenceDescriptor() = default;
6969

7070
RecurrenceDescriptor(Value *Start, Instruction *Exit, RecurKind K,
71-
FastMathFlags FMF, Instruction *UAI, Type *RT,
71+
FastMathFlags FMF, Instruction *ExactFP, Type *RT,
7272
bool Signed, SmallPtrSetImpl<Instruction *> &CI)
7373
: StartValue(Start), LoopExitInstr(Exit), Kind(K), FMF(FMF),
74-
UnsafeAlgebraInst(UAI), RecurrenceType(RT), IsSigned(Signed) {
74+
ExactFPMathInst(ExactFP), RecurrenceType(RT), IsSigned(Signed) {
7575
CastInsts.insert(CI.begin(), CI.end());
7676
}
7777

7878
/// This POD struct holds information about a potential recurrence operation.
7979
class InstDesc {
8080
public:
81-
InstDesc(bool IsRecur, Instruction *I, Instruction *UAI = nullptr)
81+
InstDesc(bool IsRecur, Instruction *I, Instruction *ExactFP = nullptr)
8282
: IsRecurrence(IsRecur), PatternLastInst(I),
83-
RecKind(RecurKind::None), UnsafeAlgebraInst(UAI) {}
83+
RecKind(RecurKind::None), ExactFPMathInst(ExactFP) {}
8484

85-
InstDesc(Instruction *I, RecurKind K, Instruction *UAI = nullptr)
85+
InstDesc(Instruction *I, RecurKind K, Instruction *ExactFP = nullptr)
8686
: IsRecurrence(true), PatternLastInst(I), RecKind(K),
87-
UnsafeAlgebraInst(UAI) {}
87+
ExactFPMathInst(ExactFP) {}
8888

8989
bool isRecurrence() const { return IsRecurrence; }
9090

91-
bool hasUnsafeAlgebra() const { return UnsafeAlgebraInst != nullptr; }
91+
bool needsExactFPMath() const { return ExactFPMathInst != nullptr; }
9292

93-
Instruction *getUnsafeAlgebraInst() const { return UnsafeAlgebraInst; }
93+
Instruction *getExactFPMathInst() const { return ExactFPMathInst; }
9494

9595
RecurKind getRecKind() const { return RecKind; }
9696

@@ -104,8 +104,8 @@ class RecurrenceDescriptor {
104104
Instruction *PatternLastInst;
105105
// If this is a min/max pattern.
106106
RecurKind RecKind;
107-
// Recurrence has unsafe algebra.
108-
Instruction *UnsafeAlgebraInst;
107+
// Recurrence does not allow floating-point reassociation.
108+
Instruction *ExactFPMathInst;
109109
};
110110

111111
/// Returns a struct describing if the instruction 'I' can be a recurrence
@@ -184,12 +184,12 @@ class RecurrenceDescriptor {
184184

185185
Instruction *getLoopExitInstr() const { return LoopExitInstr; }
186186

187-
/// Returns true if the recurrence has unsafe algebra which requires a relaxed
188-
/// floating-point model.
189-
bool hasUnsafeAlgebra() const { return UnsafeAlgebraInst != nullptr; }
187+
/// Returns true if the recurrence has floating-point math that requires
188+
/// precise (ordered) operations.
189+
bool hasExactFPMath() const { return ExactFPMathInst != nullptr; }
190190

191-
/// Returns first unsafe algebra instruction in the PHI node's use-chain.
192-
Instruction *getUnsafeAlgebraInst() const { return UnsafeAlgebraInst; }
191+
/// Returns 1st non-reassociative FP instruction in the PHI node's use-chain.
192+
Instruction *getExactFPMathInst() const { return ExactFPMathInst; }
193193

194194
/// Returns true if the recurrence kind is an integer kind.
195195
static bool isIntegerRecurrenceKind(RecurKind Kind);
@@ -243,8 +243,8 @@ class RecurrenceDescriptor {
243243
// The fast-math flags on the recurrent instructions. We propagate these
244244
// fast-math flags into the vectorized FP instructions we generate.
245245
FastMathFlags FMF;
246-
// First occurrence of unasfe algebra in the PHI's use-chain.
247-
Instruction *UnsafeAlgebraInst = nullptr;
246+
// First instance of non-reassociative floating-point in the PHI's use-chain.
247+
Instruction *ExactFPMathInst = nullptr;
248248
// The type of the recurrence.
249249
Type *RecurrenceType = nullptr;
250250
// True if all source operands of the recurrence are SExtInsts.

llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ class LoopVectorizationRequirements {
179179
public:
180180
LoopVectorizationRequirements(OptimizationRemarkEmitter &ORE) : ORE(ORE) {}
181181

182-
void addUnsafeAlgebraInst(Instruction *I) {
183-
// First unsafe algebra instruction.
184-
if (!UnsafeAlgebraInst)
185-
UnsafeAlgebraInst = I;
182+
/// Track the 1st floating-point instruction that can not be reassociated.
183+
void addExactFPMathInst(Instruction *I) {
184+
if (I && !ExactFPMathInst)
185+
ExactFPMathInst = I;
186186
}
187187

188188
void addRuntimePointerChecks(unsigned Num) { NumRuntimePointerChecks = Num; }
@@ -191,7 +191,7 @@ class LoopVectorizationRequirements {
191191

192192
private:
193193
unsigned NumRuntimePointerChecks = 0;
194-
Instruction *UnsafeAlgebraInst = nullptr;
194+
Instruction *ExactFPMathInst = nullptr;
195195

196196
/// Interface to emit optimization remarks.
197197
OptimizationRemarkEmitter &ORE;

llvm/lib/Analysis/IVDescriptors.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ bool RecurrenceDescriptor::AddReductionVar(PHINode *Phi, RecurKind Kind,
469469

470470
// Save the description of this reduction variable.
471471
RecurrenceDescriptor RD(RdxStart, ExitInstruction, Kind, FMF,
472-
ReduxDesc.getUnsafeAlgebraInst(), RecurrenceType,
472+
ReduxDesc.getExactFPMathInst(), RecurrenceType,
473473
IsSigned, CastInsts);
474474
RedDes = RD;
475475

@@ -569,7 +569,7 @@ RecurrenceDescriptor::isRecurrenceInstr(Instruction *I, RecurKind Kind,
569569
default:
570570
return InstDesc(false, I);
571571
case Instruction::PHI:
572-
return InstDesc(I, Prev.getRecKind(), Prev.getUnsafeAlgebraInst());
572+
return InstDesc(I, Prev.getRecKind(), Prev.getExactFPMathInst());
573573
case Instruction::Sub:
574574
case Instruction::Add:
575575
return InstDesc(Kind == RecurKind::Add, I);

llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ bool LoopVectorizationRequirements::doesNotMeet(
250250
Function *F, Loop *L, const LoopVectorizeHints &Hints) {
251251
const char *PassName = Hints.vectorizeAnalysisPassName();
252252
bool Failed = false;
253-
if (UnsafeAlgebraInst && !Hints.allowReordering()) {
253+
if (ExactFPMathInst && !Hints.allowReordering()) {
254254
ORE.emit([&]() {
255255
return OptimizationRemarkAnalysisFPCommute(
256-
PassName, "CantReorderFPOps", UnsafeAlgebraInst->getDebugLoc(),
257-
UnsafeAlgebraInst->getParent())
256+
PassName, "CantReorderFPOps", ExactFPMathInst->getDebugLoc(),
257+
ExactFPMathInst->getParent())
258258
<< "loop not vectorized: cannot prove it is safe to reorder "
259259
"floating-point operations";
260260
});
@@ -651,8 +651,7 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
651651
RecurrenceDescriptor RedDes;
652652
if (RecurrenceDescriptor::isReductionPHI(Phi, TheLoop, RedDes, DB, AC,
653653
DT)) {
654-
if (RedDes.hasUnsafeAlgebra())
655-
Requirements->addUnsafeAlgebraInst(RedDes.getUnsafeAlgebraInst());
654+
Requirements->addExactFPMathInst(RedDes.getExactFPMathInst());
656655
AllowedExit.insert(RedDes.getLoopExitInstr());
657656
Reductions[Phi] = RedDes;
658657
continue;
@@ -676,7 +675,7 @@ bool LoopVectorizationLegality::canVectorizeInstrs() {
676675
if (InductionDescriptor::isInductionPHI(Phi, TheLoop, PSE, ID)) {
677676
addInductionPhi(Phi, ID, AllowedExit);
678677
if (ID.hasUnsafeAlgebra())
679-
Requirements->addUnsafeAlgebraInst(ID.getUnsafeAlgebraInst());
678+
Requirements->addExactFPMathInst(ID.getUnsafeAlgebraInst());
680679
continue;
681680
}
682681

0 commit comments

Comments
 (0)