Skip to content

Commit 60e66b5

Browse files
Ryan Taylorigcbot
authored andcommitted
_OS_SUMMARY
_OS_DESCRIPTION
1 parent 655b3ea commit 60e66b5

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

IGC/Compiler/CustomUnsafeOptPass.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
29592973
bool 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);

IGC/common/igc_flags.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ DECLARE_IGC_REGKEY(bool, SampleMultiversioning, false, "Create branches
396396
DECLARE_IGC_REGKEY(bool, EnableSMRescheduling, false, "Change instruction order to enable extra Sample Multiversioning cases", false)
397397
DECLARE_IGC_REGKEY(bool, DisableEarlyOutPatterns, false, "Disable optimization trying to create an early out after sampleC messages", false)
398398
DECLARE_IGC_REGKEY(DWORD, EarlyOutPatternSelectPS, 0xff, "Each bit selects a pattern match to enable/disable.", false)
399-
DECLARE_IGC_REGKEY(DWORD, EarlyOutPatternSelectCS, 0x8, "Each bit selects a pattern match to enable/disable.", false)
399+
DECLARE_IGC_REGKEY(DWORD, EarlyOutPatternSelectCS, 0xff, "Each bit selects a pattern match to enable/disable.", false)
400400
DECLARE_IGC_REGKEY(bool, OCLEnableReassociate, false, "Enable reassociation", true)
401401
DECLARE_IGC_REGKEY(bool, EnableOCLScratchPrivateMemory, true, "Enable the use of scratch space for private memory [OCL only]", false)
402402
DECLARE_IGC_REGKEY(bool, EnableMaxWGSizeCalculation, true, "Enable max work group size calculation [OCL only]", true)

0 commit comments

Comments
 (0)