Skip to content

Commit ecd63af

Browse files
committed
Revert "[LICM] Support integer mul/add in hoistFPAssociation. (#67736)"
This reverts commit 7ff5dfb. Causing crashes on Mac build bots.
1 parent 3a080a0 commit ecd63af

File tree

2 files changed

+17
-413
lines changed

2 files changed

+17
-413
lines changed

llvm/lib/Transforms/Scalar/LICM.cpp

Lines changed: 17 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ STATISTIC(NumAddSubHoisted, "Number of add/subtract expressions reassociated "
110110
"and hoisted out of the loop");
111111
STATISTIC(NumFPAssociationsHoisted, "Number of invariant FP expressions "
112112
"reassociated and hoisted out of the loop");
113-
STATISTIC(NumIntAssociationsHoisted,
114-
"Number of invariant int expressions "
115-
"reassociated and hoisted out of the loop");
116113

117114
/// Memory promotion is enabled by default.
118115
static cl::opt<bool>
@@ -138,12 +135,6 @@ static cl::opt<unsigned> FPAssociationUpperLimit(
138135
"Set upper limit for the number of transformations performed "
139136
"during a single round of hoisting the reassociated expressions."));
140137

141-
cl::opt<unsigned> IntAssociationUpperLimit(
142-
"licm-max-num-int-reassociations", cl::init(5U), cl::Hidden,
143-
cl::desc(
144-
"Set upper limit for the number of transformations performed "
145-
"during a single round of hoisting the reassociated expressions."));
146-
147138
// Experimental option to allow imprecision in LICM in pathological cases, in
148139
// exchange for faster compile. This is to be removed if MemorySSA starts to
149140
// address the same issue. LICM calls MemorySSAWalker's
@@ -2670,31 +2661,21 @@ static bool hoistAddSub(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
26702661
return false;
26712662
}
26722663

2673-
static bool isReassociableOp(Instruction *I, unsigned IntOpcode,
2674-
unsigned FPOpcode) {
2675-
if (I->getOpcode() == IntOpcode)
2676-
return true;
2677-
if (I->getOpcode() == FPOpcode && I->hasAllowReassoc() &&
2678-
I->hasNoSignedZeros())
2679-
return true;
2680-
return false;
2681-
}
2682-
26832664
/// Try to reassociate expressions like ((A1 * B1) + (A2 * B2) + ...) * C where
26842665
/// A1, A2, ... and C are loop invariants into expressions like
26852666
/// ((A1 * C * B1) + (A2 * C * B2) + ...) and hoist the (A1 * C), (A2 * C), ...
26862667
/// invariant expressions. This functions returns true only if any hoisting has
26872668
/// actually occured.
2688-
static bool hoistMulAddAssociation(Instruction &I, Loop &L,
2689-
ICFLoopSafetyInfo &SafetyInfo,
2690-
MemorySSAUpdater &MSSAU, AssumptionCache *AC,
2691-
DominatorTree *DT) {
2669+
static bool hoistFPAssociation(Instruction &I, Loop &L,
2670+
ICFLoopSafetyInfo &SafetyInfo,
2671+
MemorySSAUpdater &MSSAU, AssumptionCache *AC,
2672+
DominatorTree *DT) {
26922673
using namespace PatternMatch;
2674+
Value *VariantOp = nullptr, *InvariantOp = nullptr;
26932675

2694-
if (!isReassociableOp(&I, Instruction::Mul, Instruction::FMul))
2676+
if (!match(&I, m_FMul(m_Value(VariantOp), m_Value(InvariantOp))) ||
2677+
!I.hasAllowReassoc() || !I.hasNoSignedZeros())
26952678
return false;
2696-
Value *VariantOp = I.getOperand(0);
2697-
Value *InvariantOp = I.getOperand(1);
26982679
if (L.isLoopInvariant(VariantOp))
26992680
std::swap(VariantOp, InvariantOp);
27002681
if (L.isLoopInvariant(VariantOp) || !L.isLoopInvariant(InvariantOp))
@@ -2708,17 +2689,15 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L,
27082689
Worklist.push_back(VariantBinOp);
27092690
while (!Worklist.empty()) {
27102691
BinaryOperator *BO = Worklist.pop_back_val();
2711-
if (!BO->hasOneUse())
2692+
if (!BO->hasOneUse() || !BO->hasAllowReassoc() || !BO->hasNoSignedZeros())
27122693
return false;
2713-
if (isReassociableOp(BO, Instruction::Add, Instruction::FAdd) &&
2714-
isa<BinaryOperator>(BO->getOperand(0)) &&
2715-
isa<BinaryOperator>(BO->getOperand(1))) {
2716-
Worklist.push_back(cast<BinaryOperator>(BO->getOperand(0)));
2717-
Worklist.push_back(cast<BinaryOperator>(BO->getOperand(1)));
2694+
BinaryOperator *Op0, *Op1;
2695+
if (match(BO, m_FAdd(m_BinOp(Op0), m_BinOp(Op1)))) {
2696+
Worklist.push_back(Op0);
2697+
Worklist.push_back(Op1);
27182698
continue;
27192699
}
2720-
if (!isReassociableOp(BO, Instruction::Mul, Instruction::FMul) ||
2721-
L.isLoopInvariant(BO))
2700+
if (BO->getOpcode() != Instruction::FMul || L.isLoopInvariant(BO))
27222701
return false;
27232702
Use &U0 = BO->getOperandUse(0);
27242703
Use &U1 = BO->getOperandUse(1);
@@ -2728,10 +2707,7 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L,
27282707
Changes.push_back(&U1);
27292708
else
27302709
return false;
2731-
unsigned Limit = I.getType()->isIntOrIntVectorTy()
2732-
? IntAssociationUpperLimit
2733-
: FPAssociationUpperLimit;
2734-
if (Changes.size() > Limit)
2710+
if (Changes.size() > FPAssociationUpperLimit)
27352711
return false;
27362712
}
27372713
if (Changes.empty())
@@ -2744,12 +2720,7 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L,
27442720
for (auto *U : Changes) {
27452721
assert(L.isLoopInvariant(U->get()));
27462722
Instruction *Ins = cast<Instruction>(U->getUser());
2747-
Value *Mul;
2748-
if (I.getType()->isIntOrIntVectorTy())
2749-
Mul = Builder.CreateMul(U->get(), Factor, "factor.op.mul");
2750-
else
2751-
Mul = Builder.CreateFMulFMF(U->get(), Factor, Ins, "factor.op.fmul");
2752-
U->set(Mul);
2723+
U->set(Builder.CreateFMulFMF(U->get(), Factor, Ins, "factor.op.fmul"));
27532724
}
27542725
I.replaceAllUsesWith(VariantOp);
27552726
eraseInstruction(I, SafetyInfo, MSSAU);
@@ -2783,12 +2754,9 @@ static bool hoistArithmetics(Instruction &I, Loop &L,
27832754
return true;
27842755
}
27852756

2786-
if (hoistMulAddAssociation(I, L, SafetyInfo, MSSAU, AC, DT)) {
2757+
if (hoistFPAssociation(I, L, SafetyInfo, MSSAU, AC, DT)) {
27872758
++NumHoisted;
2788-
if (I.getType()->isIntOrIntVectorTy())
2789-
++NumIntAssociationsHoisted;
2790-
else
2791-
++NumFPAssociationsHoisted;
2759+
++NumFPAssociationsHoisted;
27922760
return true;
27932761
}
27942762

0 commit comments

Comments
 (0)