Skip to content

Commit 1dd1559

Browse files
committedJul 28, 2015
fix TLI's combineRepeatedFPDivisors interface to return the minimum user threshold
This fix was suggested as part of D11345 and is part of fixing PR24141. With this change, we can avoid walking the uses of a divisor node if the target doesn't want the combineRepeatedFPDivisors transform in the first place. There is no NFC-intended other than that. Differential Revision: http://reviews.llvm.org/D11531 llvm-svn: 243498
1 parent ef5c196 commit 1dd1559

File tree

8 files changed

+26
-18
lines changed

8 files changed

+26
-18
lines changed
 

‎llvm/include/llvm/Target/TargetLowering.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -2732,10 +2732,12 @@ class TargetLowering : public TargetLoweringBase {
27322732
return SDValue();
27332733
}
27342734

2735-
/// Indicate whether this target prefers to combine the given number of FDIVs
2736-
/// with the same divisor.
2737-
virtual bool combineRepeatedFPDivisors(unsigned NumUsers) const {
2738-
return false;
2735+
/// Indicate whether this target prefers to combine FDIVs with the same
2736+
/// divisor. If the transform should never be done, return zero. If the
2737+
/// transform should be done, return the minimum number of divisor uses
2738+
/// that must exist.
2739+
virtual unsigned combineRepeatedFPDivisors() const {
2740+
return 0;
27392741
}
27402742

27412743
/// Hooks for building estimates in place of slower divisions and square

‎llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -8247,23 +8247,29 @@ SDValue DAGCombiner::combineRepeatedFPDivisors(SDNode *N) {
82478247
if (!DAG.getTarget().Options.UnsafeFPMath)
82488248
return SDValue();
82498249

8250+
// Skip if current node is a reciprocal.
82508251
SDValue N0 = N->getOperand(0);
82518252
ConstantFPSDNode *N0CFP = dyn_cast<ConstantFPSDNode>(N0);
8252-
8253-
// Skip if current node is a reciprocal.
82548253
if (N0CFP && N0CFP->isExactlyValue(1.0))
82558254
return SDValue();
82568255

8256+
// Exit early if the target does not want this transform or if there can't
8257+
// possibly be enough uses of the divisor to make the transform worthwhile.
82578258
SDValue N1 = N->getOperand(1);
8258-
SmallVector<SDNode *, 4> Users;
8259+
unsigned MinUses = TLI.combineRepeatedFPDivisors();
8260+
if (!MinUses || N1->use_size() < MinUses)
8261+
return SDValue();
82598262

82608263
// Find all FDIV users of the same divisor.
8264+
SmallVector<SDNode *, 4> Users;
82618265
for (auto *U : N1->uses()) {
82628266
if (U->getOpcode() == ISD::FDIV && U->getOperand(1) == N1)
82638267
Users.push_back(U);
82648268
}
82658269

8266-
if (!TLI.combineRepeatedFPDivisors(Users.size()))
8270+
// Now that we have the actual number of divisor uses, make sure it meets
8271+
// the minimum threshold specified by the target.
8272+
if (Users.size() < MinUses)
82678273
return SDValue();
82688274

82698275
EVT VT = N->getValueType(0);

‎llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -9427,10 +9427,10 @@ bool AArch64TargetLowering::useLoadStackGuardNode() const {
94279427
return true;
94289428
}
94299429

9430-
bool AArch64TargetLowering::combineRepeatedFPDivisors(unsigned NumUsers) const {
9430+
unsigned AArch64TargetLowering::combineRepeatedFPDivisors() const {
94319431
// Combine multiple FDIVs with the same divisor into multiple FMULs by the
94329432
// reciprocal if there are three or more FDIVs.
9433-
return NumUsers > 2;
9433+
return 3;
94349434
}
94359435

94369436
TargetLoweringBase::LegalizeTypeAction

‎llvm/lib/Target/AArch64/AArch64ISelLowering.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ class AArch64TargetLowering : public TargetLowering {
477477

478478
SDValue BuildSDIVPow2(SDNode *N, const APInt &Divisor, SelectionDAG &DAG,
479479
std::vector<SDNode *> *Created) const override;
480-
bool combineRepeatedFPDivisors(unsigned NumUsers) const override;
480+
unsigned combineRepeatedFPDivisors() const override;
481481

482482
ConstraintType getConstraintType(StringRef Constraint) const override;
483483
unsigned getRegisterByName(const char* RegName, EVT VT,

‎llvm/lib/Target/PowerPC/PPCISelLowering.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -9131,7 +9131,7 @@ SDValue PPCTargetLowering::getRecipEstimate(SDValue Operand,
91319131
return SDValue();
91329132
}
91339133

9134-
bool PPCTargetLowering::combineRepeatedFPDivisors(unsigned NumUsers) const {
9134+
unsigned PPCTargetLowering::combineRepeatedFPDivisors() const {
91359135
// Note: This functionality is used only when unsafe-fp-math is enabled, and
91369136
// on cores with reciprocal estimates (which are used when unsafe-fp-math is
91379137
// enabled for division), this functionality is redundant with the default
@@ -9144,12 +9144,12 @@ bool PPCTargetLowering::combineRepeatedFPDivisors(unsigned NumUsers) const {
91449144
// one FP pipeline) for three or more FDIVs (for generic OOO cores).
91459145
switch (Subtarget.getDarwinDirective()) {
91469146
default:
9147-
return NumUsers > 2;
9147+
return 3;
91489148
case PPC::DIR_440:
91499149
case PPC::DIR_A2:
91509150
case PPC::DIR_E500mc:
91519151
case PPC::DIR_E5500:
9152-
return NumUsers > 1;
9152+
return 2;
91539153
}
91549154
}
91559155

‎llvm/lib/Target/PowerPC/PPCISelLowering.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ namespace llvm {
853853
bool &UseOneConstNR) const override;
854854
SDValue getRecipEstimate(SDValue Operand, DAGCombinerInfo &DCI,
855855
unsigned &RefinementSteps) const override;
856-
bool combineRepeatedFPDivisors(unsigned NumUsers) const override;
856+
unsigned combineRepeatedFPDivisors() const override;
857857

858858
CCAssignFn *useFastISelCCs(unsigned Flag) const;
859859
};

‎llvm/lib/Target/X86/X86ISelLowering.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -13308,8 +13308,8 @@ SDValue X86TargetLowering::getRecipEstimate(SDValue Op,
1330813308
/// This is because we still need one division to calculate the reciprocal and
1330913309
/// then we need two multiplies by that reciprocal as replacements for the
1331013310
/// original divisions.
13311-
bool X86TargetLowering::combineRepeatedFPDivisors(unsigned NumUsers) const {
13312-
return NumUsers > 1;
13311+
unsigned X86TargetLowering::combineRepeatedFPDivisors() const {
13312+
return 2;
1331313313
}
1331413314

1331513315
static bool isAllOnes(SDValue V) {

‎llvm/lib/Target/X86/X86ISelLowering.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ namespace llvm {
11241124
unsigned &RefinementSteps) const override;
11251125

11261126
/// Reassociate floating point divisions into multiply by reciprocal.
1127-
bool combineRepeatedFPDivisors(unsigned NumUsers) const override;
1127+
unsigned combineRepeatedFPDivisors() const override;
11281128
};
11291129

11301130
namespace X86 {

0 commit comments

Comments
 (0)