@@ -110,9 +110,6 @@ STATISTIC(NumAddSubHoisted, "Number of add/subtract expressions reassociated "
110
110
" and hoisted out of the loop" );
111
111
STATISTIC (NumFPAssociationsHoisted, " Number of invariant FP expressions "
112
112
" reassociated and hoisted out of the loop" );
113
- STATISTIC (NumIntAssociationsHoisted,
114
- " Number of invariant int expressions "
115
- " reassociated and hoisted out of the loop" );
116
113
117
114
// / Memory promotion is enabled by default.
118
115
static cl::opt<bool >
@@ -138,12 +135,6 @@ static cl::opt<unsigned> FPAssociationUpperLimit(
138
135
" Set upper limit for the number of transformations performed "
139
136
" during a single round of hoisting the reassociated expressions." ));
140
137
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
-
147
138
// Experimental option to allow imprecision in LICM in pathological cases, in
148
139
// exchange for faster compile. This is to be removed if MemorySSA starts to
149
140
// address the same issue. LICM calls MemorySSAWalker's
@@ -2670,31 +2661,21 @@ static bool hoistAddSub(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo,
2670
2661
return false ;
2671
2662
}
2672
2663
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
-
2683
2664
// / Try to reassociate expressions like ((A1 * B1) + (A2 * B2) + ...) * C where
2684
2665
// / A1, A2, ... and C are loop invariants into expressions like
2685
2666
// / ((A1 * C * B1) + (A2 * C * B2) + ...) and hoist the (A1 * C), (A2 * C), ...
2686
2667
// / invariant expressions. This functions returns true only if any hoisting has
2687
2668
// / 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) {
2692
2673
using namespace PatternMatch ;
2674
+ Value *VariantOp = nullptr , *InvariantOp = nullptr ;
2693
2675
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 ())
2695
2678
return false ;
2696
- Value *VariantOp = I.getOperand (0 );
2697
- Value *InvariantOp = I.getOperand (1 );
2698
2679
if (L.isLoopInvariant (VariantOp))
2699
2680
std::swap (VariantOp, InvariantOp);
2700
2681
if (L.isLoopInvariant (VariantOp) || !L.isLoopInvariant (InvariantOp))
@@ -2708,17 +2689,15 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L,
2708
2689
Worklist.push_back (VariantBinOp);
2709
2690
while (!Worklist.empty ()) {
2710
2691
BinaryOperator *BO = Worklist.pop_back_val ();
2711
- if (!BO->hasOneUse ())
2692
+ if (!BO->hasOneUse () || !BO-> hasAllowReassoc () || !BO-> hasNoSignedZeros () )
2712
2693
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);
2718
2698
continue ;
2719
2699
}
2720
- if (!isReassociableOp (BO, Instruction::Mul, Instruction::FMul) ||
2721
- L.isLoopInvariant (BO))
2700
+ if (BO->getOpcode () != Instruction::FMul || L.isLoopInvariant (BO))
2722
2701
return false ;
2723
2702
Use &U0 = BO->getOperandUse (0 );
2724
2703
Use &U1 = BO->getOperandUse (1 );
@@ -2728,10 +2707,7 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L,
2728
2707
Changes.push_back (&U1);
2729
2708
else
2730
2709
return false ;
2731
- unsigned Limit = I.getType ()->isIntOrIntVectorTy ()
2732
- ? IntAssociationUpperLimit
2733
- : FPAssociationUpperLimit;
2734
- if (Changes.size () > Limit)
2710
+ if (Changes.size () > FPAssociationUpperLimit)
2735
2711
return false ;
2736
2712
}
2737
2713
if (Changes.empty ())
@@ -2744,12 +2720,7 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L,
2744
2720
for (auto *U : Changes) {
2745
2721
assert (L.isLoopInvariant (U->get ()));
2746
2722
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" ));
2753
2724
}
2754
2725
I.replaceAllUsesWith (VariantOp);
2755
2726
eraseInstruction (I, SafetyInfo, MSSAU);
@@ -2783,12 +2754,9 @@ static bool hoistArithmetics(Instruction &I, Loop &L,
2783
2754
return true ;
2784
2755
}
2785
2756
2786
- if (hoistMulAddAssociation (I, L, SafetyInfo, MSSAU, AC, DT)) {
2757
+ if (hoistFPAssociation (I, L, SafetyInfo, MSSAU, AC, DT)) {
2787
2758
++NumHoisted;
2788
- if (I.getType ()->isIntOrIntVectorTy ())
2789
- ++NumIntAssociationsHoisted;
2790
- else
2791
- ++NumFPAssociationsHoisted;
2759
+ ++NumFPAssociationsHoisted;
2792
2760
return true ;
2793
2761
}
2794
2762
0 commit comments