Index: llvm/include/llvm/Analysis/TargetTransformInfo.h =================================================================== --- llvm/include/llvm/Analysis/TargetTransformInfo.h +++ llvm/include/llvm/Analysis/TargetTransformInfo.h @@ -396,14 +396,6 @@ /// incurs significant execution cost. bool isLoweredToCall(const Function *F) const; - /// - /// \brief isExpensiveForFolding check if instruction can be replaced - /// with conditional instruction (csel/cset etc), if not - then instruction is - /// considered as expensive - /// \param I - instructions for checking - /// \return true if it cannot be replaced with one conditional instruction - bool isExpensiveForFolding(const Instruction& I) const; - struct LSRCost { /// TODO: Some of these could be merged. Also, a lexical ordering /// isn't always optimal. Index: llvm/lib/Analysis/TargetTransformInfo.cpp =================================================================== --- llvm/lib/Analysis/TargetTransformInfo.cpp +++ llvm/lib/Analysis/TargetTransformInfo.cpp @@ -247,10 +247,6 @@ return TTIImpl->isHardwareLoopProfitable(L, SE, AC, LibInfo, HWLoopInfo); } -bool TargetTransformInfo::isExpensiveForFolding(const Instruction& I) const { - return TTIImpl->isExpensiveForFolding(I); -} - void TargetTransformInfo::getUnrollingPreferences( Loop *L, ScalarEvolution &SE, UnrollingPreferences &UP) const { return TTIImpl->getUnrollingPreferences(L, SE, UP); Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp =================================================================== --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -127,11 +127,6 @@ cl::desc("Limit maximum recursion depth when calculating costs of " "speculatively executed instructions")); -static cl::opt CheckSpeculationCost( - "check-speculation-cost", cl::Hidden, cl::init(true), - cl::desc("When merging conditional stores, add additional cost to instructions " - "which cannot be represented by one conditional instruction")); - STATISTIC(NumBitMaps, "Number of switch instructions turned into bitmaps"); STATISTIC(NumLinearMaps, "Number of switch instructions turned into linear mapping"); @@ -2410,6 +2405,23 @@ << " T: " << IfTrue->getName() << " F: " << IfFalse->getName() << "\n"); + // We need to be sure, that DomBlock has + // enough room for new instructions + // First add cost of Select instruction, that will be added to this block + // (this cost is equal to number of phi nodes in BB) + unsigned Cost = NumPhis; + + for (const auto& Instr : *DomBlock) + { + if (!isa(&Instr)) + Cost += TTI.getUserCost(&Instr); + } + + if (Cost > PHINodeFoldingThreshold * TargetTransformInfo::TCC_Basic) { + // DomBlock already too large + return false; + } + // If we can still promote the PHI nodes after this gauntlet of tests, // do all of the PHI's now. Instruction *InsertPt = DomBlock->getTerminator(); @@ -2971,10 +2983,6 @@ if (isa(I) || isa(I) || isa(I)) { ++N; - - if (CheckSpeculationCost && TTI.isExpensiveForFolding(I)) { - ++N; - } } // Free instructions. Index: llvm/test/Transforms/SimplifyCFG/AArch64/check-instr-cost-for-folding.ll =================================================================== --- llvm/test/Transforms/SimplifyCFG/AArch64/check-instr-cost-for-folding.ll +++ llvm/test/Transforms/SimplifyCFG/AArch64/check-instr-cost-for-folding.ll @@ -1,4 +1,4 @@ -; RUN: opt < %s -mtriple=aarch64-linux-gnu -simplifycfg -check-speculation-cost=true -S >%t +; RUN: opt < %s -mtriple=aarch64-linux-gnu -simplifycfg -S >%t ; RUN: FileCheck %s < %t ; ModuleID = 'do_select.c' @@ -32,7 +32,7 @@ ; CHECK-LABEL: if.then: ; CHECK-NEXT: %or = or i64 %res_in.020, %bit.addr.017 ; CHECK-NEXT: %inc = add nsw i32 %retval1.019, 1 -; CHECK-NEXT: store i8* null, i8** %proc, align 8 +; CHECK-NEXT: br label %if.end %or = or i64 %res_in.020, %bit.addr.017 %inc = add nsw i32 %retval1.019, 1 store i8* null, i8** %proc, align 8