diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2024-07-30 14:27:43 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2024-10-23 18:26:26 +0000 |
| commit | 36b606ae6aa4b24061096ba18582e0a08ccd5dba (patch) | |
| tree | cf4fe3cf493461d93efbefc53852f456ce574608 /contrib/llvm-project/llvm/lib/Transforms | |
| parent | 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583 (diff) | |
| parent | c76260f306a7e51ef52dc75c6031e51e1e0862d7 (diff) | |
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Transforms')
3 files changed, 5 insertions, 65 deletions
diff --git a/contrib/llvm-project/llvm/lib/Transforms/Scalar/LICM.cpp b/contrib/llvm-project/llvm/lib/Transforms/Scalar/LICM.cpp index fe264503dee9..91ef2b4b7c18 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Scalar/LICM.cpp @@ -113,8 +113,6 @@ STATISTIC(NumFPAssociationsHoisted, "Number of invariant FP expressions " STATISTIC(NumIntAssociationsHoisted, "Number of invariant int expressions " "reassociated and hoisted out of the loop"); -STATISTIC(NumBOAssociationsHoisted, "Number of invariant BinaryOp expressions " - "reassociated and hoisted out of the loop"); /// Memory promotion is enabled by default. static cl::opt<bool> @@ -2781,60 +2779,6 @@ static bool hoistMulAddAssociation(Instruction &I, Loop &L, return true; } -/// Reassociate general associative binary expressions of the form -/// -/// 1. "(LV op C1) op C2" ==> "LV op (C1 op C2)" -/// -/// where op is an associative binary op, LV is a loop variant, and C1 and C2 -/// are loop invariants that we want to hoist. -/// -/// TODO: This can be extended to more cases such as -/// 2. "C1 op (C2 op LV)" ==> "(C1 op C2) op LV" -/// 3. "(C1 op LV) op C2" ==> "LV op (C1 op C2)" if op is commutative -/// 4. "C1 op (LV op C2)" ==> "(C1 op C2) op LV" if op is commutative -static bool hoistBOAssociation(Instruction &I, Loop &L, - ICFLoopSafetyInfo &SafetyInfo, - MemorySSAUpdater &MSSAU, AssumptionCache *AC, - DominatorTree *DT) { - BinaryOperator *BO = dyn_cast<BinaryOperator>(&I); - if (!BO || !BO->isAssociative()) - return false; - - Instruction::BinaryOps Opcode = BO->getOpcode(); - BinaryOperator *Op0 = dyn_cast<BinaryOperator>(BO->getOperand(0)); - - // Transform: "(LV op C1) op C2" ==> "LV op (C1 op C2)" - if (Op0 && Op0->getOpcode() == Opcode) { - Value *LV = Op0->getOperand(0); - Value *C1 = Op0->getOperand(1); - Value *C2 = BO->getOperand(1); - - if (L.isLoopInvariant(LV) || !L.isLoopInvariant(C1) || - !L.isLoopInvariant(C2)) - return false; - - auto *Preheader = L.getLoopPreheader(); - assert(Preheader && "Loop is not in simplify form?"); - IRBuilder<> Builder(Preheader->getTerminator()); - Value *Inv = Builder.CreateBinOp(Opcode, C1, C2, "invariant.op"); - - auto *NewBO = - BinaryOperator::Create(Opcode, LV, Inv, BO->getName() + ".reass", BO); - NewBO->copyIRFlags(BO); - BO->replaceAllUsesWith(NewBO); - eraseInstruction(*BO, SafetyInfo, MSSAU); - - // Note: (LV op C1) might not be erased if it has more uses than the one we - // just replaced. - if (Op0->use_empty()) - eraseInstruction(*Op0, SafetyInfo, MSSAU); - - return true; - } - - return false; -} - static bool hoistArithmetics(Instruction &I, Loop &L, ICFLoopSafetyInfo &SafetyInfo, MemorySSAUpdater &MSSAU, AssumptionCache *AC, @@ -2872,12 +2816,6 @@ static bool hoistArithmetics(Instruction &I, Loop &L, return true; } - if (hoistBOAssociation(I, L, SafetyInfo, MSSAU, AC, DT)) { - ++NumHoisted; - ++NumBOAssociationsHoisted; - return true; - } - return false; } diff --git a/contrib/llvm-project/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/contrib/llvm-project/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 11f9f7822a15..91461d1ed275 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -946,13 +946,15 @@ static Immediate ExtractImmediate(const SCEV *&S, ScalarEvolution &SE) { // FIXME: AR->getNoWrapFlags(SCEV::FlagNW) SCEV::FlagAnyWrap); return Result; - } else if (EnableVScaleImmediates) - if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(S)) + } else if (const SCEVMulExpr *M = dyn_cast<SCEVMulExpr>(S)) { + if (EnableVScaleImmediates && M->getNumOperands() == 2) { if (const SCEVConstant *C = dyn_cast<SCEVConstant>(M->getOperand(0))) if (isa<SCEVVScale>(M->getOperand(1))) { S = SE.getConstant(M->getType(), 0); return Immediate::getScalable(C->getValue()->getSExtValue()); } + } + } return Immediate::getZero(); } diff --git a/contrib/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/contrib/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index 6d28b8fabe42..68363abdb817 100644 --- a/contrib/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/contrib/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -206,7 +206,7 @@ static cl::opt<unsigned> VectorizeMemoryCheckThreshold( cl::desc("The maximum allowed number of runtime memory checks")); static cl::opt<bool> UseLegacyCostModel( - "vectorize-use-legacy-cost-model", cl::init(false), cl::Hidden, + "vectorize-use-legacy-cost-model", cl::init(true), cl::Hidden, cl::desc("Use the legacy cost model instead of the VPlan-based cost model. " "This option will be removed in the future.")); |
