Skip to content

Commit 9383492

Browse files
krystian-andrzejewskiigcbot
authored andcommitted
[Autobackout][FuncReg]Revert of change: 7aae34a
Allowing to combine canonicalization and saturation Considering mix mode operations for flushing denorms to zero
1 parent f5e9e3d commit 9383492

File tree

3 files changed

+30
-107
lines changed

3 files changed

+30
-107
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8836,6 +8836,10 @@ void EmitPass::EmitIntrinsicMessage(llvm::IntrinsicInst* inst)
88368836
emitSqrt(inst);
88378837
break;
88388838

8839+
case Intrinsic::canonicalize:
8840+
emitCanonicalize(inst);
8841+
break;
8842+
88398843
default:
88408844
inst->print(IGC::Debug::ods());
88418845
IGC_ASSERT_MESSAGE(0, "unknown intrinsic");
@@ -16845,7 +16849,7 @@ void EmitPass::emitFrc(llvm::GenIntrinsicInst* inst)
1684516849
m_encoder->Frc(m_destination, src0);
1684616850
}
1684716851

16848-
void IGC::EmitPass::emitCanonicalize(llvm::Instruction* inst, const DstModifier& modifier)
16852+
void IGC::EmitPass::emitCanonicalize(llvm::Instruction* inst)
1684916853
{
1685016854
// Force to flush denormal fp value to zero. Select one of two possible solutions:
1685116855
// 1. add inputVal, -0.0
@@ -16857,11 +16861,10 @@ void IGC::EmitPass::emitCanonicalize(llvm::Instruction* inst, const DstModifier&
1685716861
bool flushVal = pCodeGenContext->m_floatDenormMode16 == ::IGC::FLOAT_DENORM_FLUSH_TO_ZERO && inst->getType()->isHalfTy();
1685816862
flushVal = flushVal || (pCodeGenContext->m_floatDenormMode32 == ::IGC::FLOAT_DENORM_FLUSH_TO_ZERO && inst->getType()->isFloatTy());
1685916863
flushVal = flushVal || (pCodeGenContext->m_floatDenormMode64 == ::IGC::FLOAT_DENORM_FLUSH_TO_ZERO && inst->getType()->isDoubleTy());
16860-
if (flushVal || modifier.sat)
16864+
if (flushVal)
1686116865
{
1686216866
CVariable* inputVal = GetSymbol(inst->getOperand(0));
1686316867
CVariable* negativeZero = m_currShader->GetScalarConstant(llvm::ConstantFP::get(inst->getType(), -0.0));
16864-
m_encoder->SetDstModifier(modifier);
1686516868
m_encoder->Add(m_destination, inputVal, negativeZero);
1686616869
}
1686716870
}

IGC/Compiler/CISACodeGen/EmitVISAPass.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class EmitPass : public llvm::FunctionPass
416416
void emitAddPair(CVariable* Dst, CVariable* Src0, CVariable* Src1);
417417

418418
void emitSqrt(llvm::Instruction* inst);
419-
void emitCanonicalize(llvm::Instruction* inst, const DstModifier& modifier);
419+
void emitCanonicalize(llvm::Instruction* inst);
420420
void emitRsq(llvm::Instruction* inst);
421421
void emitFrc(llvm::GenIntrinsicInst* inst);
422422

IGC/Compiler/CISACodeGen/PatternMatchPass.cpp

Lines changed: 23 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ namespace IGC
954954
switch (I.getOpcode())
955955
{
956956
case Instruction::FSub:
957-
match = MatchFloor(I) ||
957+
match = MatchFloor(I) ||
958958
MatchFrc(I) ||
959959
MatchLrp(I) ||
960960
MatchPredAdd(I) ||
@@ -999,7 +999,7 @@ namespace IGC
999999
MatchModifier(I);
10001000
break;
10011001
case Instruction::FAdd:
1002-
match =
1002+
match =
10031003
MatchLrp(I) ||
10041004
MatchPredAdd(I) ||
10051005
MatchMad(I) ||
@@ -1220,9 +1220,6 @@ namespace IGC
12201220
case Intrinsic::fshr:
12211221
match = MatchFunnelShiftRotate(I);
12221222
break;
1223-
case Intrinsic::canonicalize:
1224-
match = MatchCanonicalizeInstruction(I);
1225-
break;
12261223
default:
12271224
match = MatchSingleInstruction(I);
12281225
// no pattern for the rest of the intrinsics
@@ -1629,9 +1626,9 @@ namespace IGC
16291626
}
16301627
return found;
16311628
}
1632-
1629+
16331630
/*
1634-
below pass handles x - frac(x) = floor(x) pattern. Refer below :
1631+
below pass handles x - frac(x) = floor(x) pattern. Refer below :
16351632
16361633
frc (8|M0) r20.0<1>:f r19.0<8;8,1>:f {Compacted, @1}
16371634
add (8|M0) (ge)f0.1 r19.0<1>:f r19.0<8;8,1>:f -r20.0<8;8,1>:f {@1}
@@ -3104,121 +3101,44 @@ namespace IGC
31043101
{
31053102
struct CanonicalizeInstPattern : Pattern
31063103
{
3107-
CanonicalizeInstPattern(llvm::Instruction* pInst) : m_pInst(pInst) {}
3104+
CanonicalizeInstPattern(llvm::Instruction* pInst, bool isNeeded) : m_pInst(pInst), m_IsNeeded(isNeeded) {}
31083105

31093106
llvm::Instruction* m_pInst;
3110-
Pattern* m_pPattern = nullptr;
3107+
bool m_IsNeeded;
31113108

31123109
virtual void Emit(EmitPass* pass, const DstModifier& modifier)
31133110
{
3114-
if (m_pPattern)
3111+
IGC_ASSERT(modifier.sat == false && modifier.flag == nullptr);
3112+
if (m_IsNeeded)
31153113
{
3116-
m_pPattern->Emit(pass, modifier);
3117-
}
3118-
else
3119-
{
3120-
pass->emitCanonicalize(m_pInst, modifier);
3114+
pass->emitCanonicalize(m_pInst);
31213115
}
31223116
}
31233117
};
31243118

3119+
IGC_ASSERT(I.getNumOperands() == 1);
3120+
bool isNeeded = true;
31253121

31263122
// FAdd, FSub, FMul, FDiv instructions flush subnormals to zero.
31273123
// However, mix mode and math instructions preserve subnormals.
31283124
// Other instructions also preserve subnormals.
3129-
// FSat intrinsic instruction can be emitted i.e. as FAdd so such an
3130-
// instruction should be inspected recursively.
3131-
std::function<bool(llvm::Value*)> DetermineIfMixMode;
3132-
DetermineIfMixMode = [&DetermineIfMixMode, this](llvm::Value* operand) -> bool
3125+
if (llvm::BinaryOperator * pBianaryOperator = llvm::dyn_cast<llvm::BinaryOperator>(I.getOperand(0)))
31333126
{
3134-
bool isMixModePossible = false;
3135-
if (m_Platform.supportMixMode())
3127+
switch (pBianaryOperator->getOpcode())
31363128
{
3137-
if (llvm::BinaryOperator* pBianaryOperator = llvm::dyn_cast<llvm::BinaryOperator>(operand))
3138-
{
3139-
// the switch instruction is executed to break the recursion if it is unneeded.
3140-
// The cause for this recursion is a possibility of constructing mad instructions.
3141-
switch (pBianaryOperator->getOpcode())
3142-
{
3143-
case llvm::BinaryOperator::BinaryOps::FAdd:
3144-
case llvm::BinaryOperator::BinaryOps::FMul:
3145-
case llvm::BinaryOperator::BinaryOps::FSub:
3146-
isMixModePossible = pBianaryOperator->getType()->isDoubleTy() == false &&
3147-
(DetermineIfMixMode(pBianaryOperator->getOperand(0)) || DetermineIfMixMode(pBianaryOperator->getOperand(1)));
3148-
break;
3149-
default:
3150-
break;
3151-
}
3152-
}
3153-
else if (isa<FPTruncInst>(operand))
3154-
{
3155-
FPTruncInst* fptruncInst = llvm::cast<FPTruncInst>(operand);
3156-
isMixModePossible = fptruncInst->getSrcTy()->isDoubleTy() == false;
3157-
}
3158-
else if (isa<FPExtInst>(operand))
3159-
{
3160-
FPExtInst* fpextInst = llvm::cast<FPExtInst>(operand);
3161-
isMixModePossible = fpextInst->getDestTy()->isDoubleTy() == false;
3162-
}
3163-
}
3164-
return isMixModePossible;
3165-
};
3166-
3167-
std::function<bool(llvm::Value*)> DetermineIfNeeded;
3168-
DetermineIfNeeded = [&DetermineIfNeeded, &DetermineIfMixMode](llvm::Value* operand) -> bool
3169-
{
3170-
bool isNeeded = true;
3171-
if (llvm::BinaryOperator* pBianaryOperator = llvm::dyn_cast<llvm::BinaryOperator>(operand))
3172-
{
3173-
// the switch instruction is to consider only the operations
3174-
// which support flushing denorms to zero.
3175-
switch (pBianaryOperator->getOpcode())
3176-
{
3177-
case llvm::BinaryOperator::BinaryOps::FAdd:
3178-
case llvm::BinaryOperator::BinaryOps::FMul:
3179-
case llvm::BinaryOperator::BinaryOps::FSub:
3180-
case llvm::BinaryOperator::BinaryOps::FDiv:
3181-
isNeeded = DetermineIfMixMode(pBianaryOperator);
3182-
break;
3183-
default:
3184-
break;
3185-
}
3186-
}
3187-
else if(GenIntrinsicInst* intrin = dyn_cast<GenIntrinsicInst>(operand))
3188-
{
3189-
switch (intrin->getIntrinsicID())
3190-
{
3191-
case GenISAIntrinsic::GenISA_fsat:
3192-
isNeeded = DetermineIfNeeded(intrin->getOperand(0));
3193-
break;
3194-
default:
3195-
break;
3196-
}
3197-
}
3198-
else if (IntrinsicInst* intrin = dyn_cast<IntrinsicInst>(operand))
3199-
{
3200-
switch (intrin->getIntrinsicID())
3201-
{
3202-
case Intrinsic::canonicalize:
3203-
isNeeded = DetermineIfNeeded(intrin->getOperand(0));
3204-
break;
3205-
default:
3206-
break;
3207-
}
3129+
case llvm::BinaryOperator::BinaryOps::FAdd:
3130+
case llvm::BinaryOperator::BinaryOps::FMul:
3131+
case llvm::BinaryOperator::BinaryOps::FSub:
3132+
case llvm::BinaryOperator::BinaryOps::FDiv:
3133+
isNeeded = false;
3134+
default:
3135+
break;
32083136
}
3209-
return isNeeded;
3210-
};
3211-
3212-
CanonicalizeInstPattern* pattern = new (m_allocator) CanonicalizeInstPattern(&I);
3213-
if (DetermineIfNeeded(I.getOperand(0)))
3214-
{
3215-
MarkAsSource(I.getOperand(0));
3216-
}
3217-
else
3218-
{
3219-
pattern->m_pPattern = Match(*llvm::cast<llvm::Instruction>(I.getOperand(0)));
32203137
}
32213138

3139+
CanonicalizeInstPattern* pattern = new (m_allocator) CanonicalizeInstPattern(&I, isNeeded);
3140+
MarkAsSource(I.getOperand(0));
3141+
32223142
AddPattern(pattern);
32233143
return true;
32243144
}

0 commit comments

Comments
 (0)