@@ -2481,6 +2481,7 @@ class EarlyOutPatterns : public FunctionPass
24812481 static bool canOptimizeNdotL (SmallVector<Instruction*, 4 > & Values, FCmpInst* FC);
24822482 static bool canOptimizeDirectOutput (SmallVector<Instruction*, 4 > & Values, GenIntrinsicInst* GII, Value*& SI, unsigned int ShaderLength);
24832483 static bool canOptimizeMulMaxMatch (SmallVector<Instruction*, 4 > & Values, Instruction* I);
2484+ static bool canOptimizeSelectOutput (SelectInst* SI);
24842485 static bool DotProductMatch (const Instruction* I);
24852486 static bool DotProductSourceMatch (const Instruction* I);
24862487 static BasicBlock* tryFoldAndSplit (
@@ -2956,6 +2957,19 @@ bool EarlyOutPatterns::canOptimizeMulMaxMatch(SmallVector<Instruction*, 4> & Val
29562957 return true ;
29572958}
29582959
2960+ bool EarlyOutPatterns::canOptimizeSelectOutput (SelectInst *SI)
2961+ {
2962+ if (FCmpInst* FC = dyn_cast<FCmpInst>(SI->getCondition ()))
2963+ {
2964+ ConstantFP* src1 = dyn_cast<ConstantFP>(FC->getOperand (1 ));
2965+ if (FC->getPredicate () != FCmpInst::FCMP_OGT || !FC->hasOneUse () || !src1 || !src1->isZero ()) {
2966+ return false ;
2967+ }
2968+ return true ;
2969+ }
2970+ return false ;
2971+ }
2972+
29592973bool EarlyOutPatterns::canOptimizeNdotL (SmallVector<Instruction*, 4 > & Values, FCmpInst* FC)
29602974{
29612975 // this function checks the lighting pattern -
@@ -3135,6 +3149,7 @@ bool EarlyOutPatterns::processBlock(BasicBlock* BB)
31353149 bool NdotLPatternEnable = 0 ;
31363150 bool DirectOutputPatternEnable = 0 ;
31373151 bool MulMaxMatchEnable = 0 ;
3152+ bool SelectFcmpPatternEnable = 0 ;
31383153
31393154 // Each pattern below is given a bit to toggle on/off
31403155 // to isolate the performance for each individual pattern.
@@ -3144,6 +3159,7 @@ bool EarlyOutPatterns::processBlock(BasicBlock* BB)
31443159 DPMaxPatternEnable = (IGC_GET_FLAG_VALUE (EarlyOutPatternSelectCS) & 0x2 ) != 0 ;
31453160 DPFSatPatternEnable = (IGC_GET_FLAG_VALUE (EarlyOutPatternSelectCS) & 0x4 ) != 0 ;
31463161 NdotLPatternEnable = (IGC_GET_FLAG_VALUE (EarlyOutPatternSelectCS) & 0x8 ) != 0 ;
3162+ SelectFcmpPatternEnable = (IGC_GET_FLAG_VALUE (EarlyOutPatternSelectCS) & 0x10 ) != 0 ;
31473163 }
31483164 else if (m_ctx->type == ShaderType::PIXEL_SHADER)
31493165 {
@@ -3246,12 +3262,17 @@ bool EarlyOutPatterns::processBlock(BasicBlock* BB)
32463262 Values.push_back (&II);
32473263 }
32483264 }
3265+ else if (auto * SI = dyn_cast<SelectInst>(&II))
3266+ {
3267+ OptCandidate = SelectFcmpPatternEnable && canOptimizeSelectOutput (SI);
3268+ if (OptCandidate)
3269+ Values.push_back (&II);
3270+ }
32493271 if (OptCandidate)
32503272 {
32513273 BasicBlock* BB1 = tryFoldAndSplit (Values, Root,
32523274 FoldThreshold, FoldThresholdMultiChannel, RatioNeeded);
32533275 BBSplit = (BB1 != nullptr );
3254-
32553276 if (BBSplit)
32563277 {
32573278 BB = BB1;
@@ -3454,6 +3475,8 @@ BasicBlock* EarlyOutPatterns::SplitBasicBlock(Instruction* inst, const DenseSet<
34543475 builder.CreateBr (endifBlock);
34553476 // split the blocks
34563477 ValueToValueMapTy VMap;
3478+
3479+ // TODO: Create if block only for affected instructions
34573480 BasicBlock* ifBlock = CloneBasicBlock (elseBlock, VMap);
34583481 ifBlock->setName (VALUE_NAME (" EO_IF" ));
34593482 currentBB->getParent ()->getBasicBlockList ().insertAfter (currentBB->getIterator (), ifBlock);
0 commit comments