From bbaecb1bb5679d31969b7158e90a6d0d1a195921 Mon Sep 17 00:00:00 2001 From: David Woo Date: Wed, 17 Jul 2024 22:58:06 +0000 Subject: [PATCH] Preserve cache policy metadata Changed some load optimization passes so that they preserve the lsc.cache.ctrl metadata that is used to override cache policy in the HW. --- IGC/Compiler/CISACodeGen/LdShrink.cpp | 4 ++++ IGC/Compiler/CISACodeGen/VectorPreProcess.cpp | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/IGC/Compiler/CISACodeGen/LdShrink.cpp b/IGC/Compiler/CISACodeGen/LdShrink.cpp index 37c2ab500859..3b3360711273 100644 --- a/IGC/Compiler/CISACodeGen/LdShrink.cpp +++ b/IGC/Compiler/CISACodeGen/LdShrink.cpp @@ -146,6 +146,10 @@ bool LdShrink::runOnFunction(Function& F) { LoadInst* NewLoad = Builder.CreateAlignedLoad(ScalarTy, ScalarPtr, IGCLLVM::getAlign(alignment)); NewLoad->setDebugLoc(LI->getDebugLoc()); + if (MDNode* mdNode = LI->getMetadata("lsc.cache.ctrl")) + { + NewLoad->setMetadata("lsc.cache.ctrl", mdNode); + } ExtractElementInst* EEI = cast(*LI->user_begin()); EEI->replaceAllUsesWith(NewLoad); diff --git a/IGC/Compiler/CISACodeGen/VectorPreProcess.cpp b/IGC/Compiler/CISACodeGen/VectorPreProcess.cpp index 97021760442c..39754a4bd1c1 100644 --- a/IGC/Compiler/CISACodeGen/VectorPreProcess.cpp +++ b/IGC/Compiler/CISACodeGen/VectorPreProcess.cpp @@ -150,7 +150,12 @@ namespace { Type* newPtrType = PointerType::get(returnType, ptr->getType()->getPointerAddressSpace()); ptr = builder.CreateBitCast(ptr, newPtrType); - return builder.CreateAlignedLoad(returnType, ptr, IGCLLVM::getAlign(alignment), isVolatile); + LoadInst* newLI = builder.CreateAlignedLoad(returnType, ptr, IGCLLVM::getAlign(alignment), isVolatile); + if (MDNode* lscMetadata = m_inst->getMetadata("lsc.cache.ctrl")) + { + newLI->setMetadata("lsc.cache.ctrl", lscMetadata); + } + return newLI; } else {