@@ -54,9 +54,12 @@ enum class RecurKind {
54
54
FMulAdd, // /< Sum of float products with llvm.fmuladd(a * b + sum).
55
55
AnyOf, // /< AnyOf reduction with select(cmp(),x,y) where one of (x,y) is
56
56
// /< loop invariant, and both x and y are integer type.
57
- FindLastIV, // /< FindLast reduction with select(cmp(),x,y) where one of
58
- // /< (x,y) is increasing loop induction, and both x and y are
59
- // /< integer type.
57
+ FindLastIVSMin, // /< FindLast reduction with select(cmp(),x,y) where one of
58
+ // /< (x,y) is increasing loop induction, and both x and y
59
+ // /< are integer type, producing a SMin reduction.
60
+ FindLastIVUMin, // /< FindLast reduction with select(cmp(),x,y) where one of
61
+ // /< (x,y) is increasing loop induction, and both x and y
62
+ // /< are integer type, producting a UMin reduction.
60
63
// clang-format on
61
64
// TODO: Any_of and FindLast reduction need not be restricted to integer type
62
65
// only.
@@ -80,13 +83,12 @@ class RecurrenceDescriptor {
80
83
81
84
RecurrenceDescriptor (Value *Start, Instruction *Exit, StoreInst *Store,
82
85
RecurKind K, FastMathFlags FMF, Instruction *ExactFP,
83
- Type *RT, bool IsResultSigned , bool IsReduxSigned ,
84
- bool Ordered, SmallPtrSetImpl<Instruction *> &CI,
86
+ Type *RT, bool Signed , bool Ordered ,
87
+ SmallPtrSetImpl<Instruction *> &CI,
85
88
unsigned MinWidthCastToRecurTy)
86
89
: IntermediateStore(Store), StartValue(Start), LoopExitInstr(Exit),
87
90
Kind (K), FMF(FMF), ExactFPMathInst(ExactFP), RecurrenceType(RT),
88
- IsResultSigned(IsResultSigned), IsReduxSigned(IsReduxSigned),
89
- IsOrdered(Ordered),
91
+ IsSigned(Signed), IsOrdered(Ordered),
90
92
MinWidthCastToRecurrenceType(MinWidthCastToRecurTy) {
91
93
CastInsts.insert_range (CI);
92
94
}
@@ -98,14 +100,12 @@ class RecurrenceDescriptor {
98
100
: IsRecurrence(IsRecur), PatternLastInst(I),
99
101
RecKind (RecurKind::None), ExactFPMathInst(ExactFP) {}
100
102
101
- InstDesc (Instruction *I, RecurKind K, bool IsSigned = false )
102
- : IsRecurrence(true ), IsSigned(IsSigned ), PatternLastInst(I ),
103
- RecKind(K ) {}
103
+ InstDesc (Instruction *I, RecurKind K, Instruction *ExactFP = nullptr )
104
+ : IsRecurrence(true ), PatternLastInst(I ), RecKind(K ),
105
+ ExactFPMathInst(ExactFP ) {}
104
106
105
107
bool isRecurrence () const { return IsRecurrence; }
106
108
107
- bool isSigned () const { return IsSigned; }
108
-
109
109
bool needsExactFPMath () const { return ExactFPMathInst != nullptr ; }
110
110
111
111
Instruction *getExactFPMathInst () const { return ExactFPMathInst; }
@@ -117,15 +117,13 @@ class RecurrenceDescriptor {
117
117
private:
118
118
// Is this instruction a recurrence candidate.
119
119
bool IsRecurrence;
120
- // Is this recurrence a signed variant.
121
- bool IsSigned = false ;
122
120
// The last instruction in a min/max pattern (select of the select(icmp())
123
121
// pattern), or the current recurrence instruction otherwise.
124
122
Instruction *PatternLastInst;
125
123
// If this is a min/max pattern.
126
124
RecurKind RecKind;
127
125
// Recurrence does not allow floating-point reassociation.
128
- Instruction *ExactFPMathInst = nullptr ;
126
+ Instruction *ExactFPMathInst;
129
127
};
130
128
131
129
// / Returns a struct describing if the instruction 'I' can be a recurrence
@@ -265,7 +263,14 @@ class RecurrenceDescriptor {
265
263
// / Returns true if the recurrence kind is of the form
266
264
// / select(cmp(),x,y) where one of (x,y) is increasing loop induction.
267
265
static bool isFindLastIVRecurrenceKind (RecurKind Kind) {
268
- return Kind == RecurKind::FindLastIV;
266
+ return Kind == RecurKind::FindLastIVSMin ||
267
+ Kind == RecurKind::FindLastIVUMin;
268
+ }
269
+
270
+ // / Returns true if recurrece kind is a signed redux kind.
271
+ static bool isSignedRecurrenceKind (RecurKind Kind) {
272
+ return Kind == RecurKind::SMax || Kind == RecurKind::SMin ||
273
+ Kind == RecurKind::FindLastIVSMin;
269
274
}
270
275
271
276
// / Returns the type of the recurrence. This type can be narrower than the
@@ -278,8 +283,9 @@ class RecurrenceDescriptor {
278
283
assert (isFindLastIVRecurrenceKind (Kind) && " Unexpected recurrence kind" );
279
284
Type *Ty = StartValue->getType ();
280
285
unsigned BW = Ty->getIntegerBitWidth ();
281
- return ConstantInt::get (Ty, isReduxSigned () ? APInt::getSignedMinValue (BW)
282
- : APInt::getMinValue (BW));
286
+ return ConstantInt::get (Ty, isSignedRecurrenceKind (Kind)
287
+ ? APInt::getSignedMinValue (BW)
288
+ : APInt::getMinValue (BW));
283
289
}
284
290
285
291
// / Returns a reference to the instructions used for type-promoting the
@@ -291,11 +297,8 @@ class RecurrenceDescriptor {
291
297
return MinWidthCastToRecurrenceType;
292
298
}
293
299
294
- // / Returns true if the reduction result is signed.
295
- bool isResultSigned () const { return IsResultSigned; }
296
-
297
- // / Returns true if the reduction redux is signed.
298
- bool isReduxSigned () const { return IsReduxSigned; }
300
+ // / Returns true if all source operands of the recurrence are SExtInsts.
301
+ bool isSigned () const { return IsSigned; }
299
302
300
303
// / Expose an ordered FP reduction to the instance users.
301
304
bool isOrdered () const { return IsOrdered; }
@@ -331,10 +334,8 @@ class RecurrenceDescriptor {
331
334
Instruction *ExactFPMathInst = nullptr ;
332
335
// The type of the recurrence.
333
336
Type *RecurrenceType = nullptr ;
334
- // True if reduction result is signed.
335
- bool IsResultSigned = false ;
336
- // True if reduction redux is signed.
337
- bool IsReduxSigned = false ;
337
+ // True if all source operands of the recurrence are SExtInsts.
338
+ bool IsSigned = false ;
338
339
// True if this recurrence can be treated as an in-order reduction.
339
340
// Currently only a non-reassociative FAdd can be considered in-order,
340
341
// if it is also the only FAdd in the PHI's use chain.
0 commit comments