@@ -2351,6 +2351,17 @@ Constant* IGCConstProp::replaceShaderConstant(LoadInst* inst)
23512351 return nullptr ;
23522352}
23532353
2354+ llvm::Constant* IGC::IGCConstantFolder::CreateCanonicalize (llvm::Constant* C0, bool flushDenorms /* = true*/ ) const
2355+ {
2356+ assert (llvm::isa<ConstantFP>(C0));
2357+ auto APF = llvm::cast<ConstantFP>(C0)->getValueAPF ();
2358+ if (flushDenorms && APF.isDenormal ())
2359+ {
2360+ APF = APFloat::getZero (APF.getSemantics (), APF.isNegative ());
2361+ }
2362+ return ConstantFP::get (C0->getContext (), APF);
2363+ }
2364+
23542365Constant* IGCConstProp::ConstantFoldCallInstruction (CallInst* inst)
23552366{
23562367 Constant* C = nullptr ;
@@ -2453,6 +2464,22 @@ Constant* IGCConstProp::ConstantFoldCallInstruction(CallInst* inst)
24532464 C = ConstantFP::get (inst->getContext (), minnum (One, maxnum (zero, A)));
24542465 }
24552466 }
2467+ break ;
2468+ case llvm_canonicalize:
2469+ {
2470+ // If the instruction should be emitted anyway, then remove the condition.
2471+ // Please, be aware of the fact that clients can understand the term canonical FP value in other way.
2472+ if (C0)
2473+ {
2474+ IGCConstantFolder constantFolder;
2475+ CodeGenContext* pCodeGenContext = getAnalysis<CodeGenContextWrapper>().getCodeGenContext ();
2476+ bool flushVal = pCodeGenContext->m_floatDenormMode16 == ::IGC::FLOAT_DENORM_FLUSH_TO_ZERO && inst->getType ()->isHalfTy ();
2477+ flushVal = flushVal || (pCodeGenContext->m_floatDenormMode32 == ::IGC::FLOAT_DENORM_FLUSH_TO_ZERO && inst->getType ()->isFloatTy ());
2478+ flushVal = flushVal || (pCodeGenContext->m_floatDenormMode64 == ::IGC::FLOAT_DENORM_FLUSH_TO_ZERO && inst->getType ()->isDoubleTy ());
2479+ C = constantFolder.CreateCanonicalize (C0, flushVal);
2480+ }
2481+ }
2482+ break ;
24562483 default :
24572484 break ;
24582485 }
@@ -2934,7 +2961,6 @@ bool IGCConstProp::runOnFunction(Function& F)
29342961 return Changed;
29352962}
29362963
2937-
29382964namespace {
29392965
29402966 class IGCIndirectICBPropagaion : public FunctionPass
@@ -2945,7 +2971,7 @@ namespace {
29452971 {
29462972 initializeIGCIndirectICBPropagaionPass (*PassRegistry::getPassRegistry ());
29472973 }
2948- virtual llvm::StringRef getPassName () const { return " Indirect ICB Propagaion " ; }
2974+ virtual llvm::StringRef getPassName () const { return " Indirect ICB Propagation " ; }
29492975 virtual bool runOnFunction (Function& F);
29502976 virtual void getAnalysisUsage (llvm::AnalysisUsage& AU) const
29512977 {
@@ -4186,5 +4212,4 @@ bool LogicalAndToBranch::runOnFunction(Function& F)
41864212 }
41874213
41884214 return changed;
4189- }
4190-
4215+ }
0 commit comments