@@ -1918,6 +1918,8 @@ namespace {
1918
1918
AU.setPreservesCFG ();
1919
1919
AU.addRequired <CodeGenContextWrapper>();
1920
1920
}
1921
+ private:
1922
+ bool isICBOffseted (llvm::LoadInst* inst, uint offset);
1921
1923
};
1922
1924
1923
1925
} // namespace
@@ -1949,47 +1951,78 @@ bool IGCIndirectICBPropagaion::runOnFunction(Function &F)
1949
1951
bool directBuf;
1950
1952
unsigned bufId;
1951
1953
BufferType bufType = IGC::DecodeAS4GFXResource (as, directBuf, bufId);
1952
- if (bufType == CONSTANT_BUFFER && directBuf && bufId == modMD->pushInfo .inlineConstantBufferSlot )
1954
+ bool bICBNoOffset =
1955
+ (IGC::INVALID_CONSTANT_BUFFER_INVALID_ADDR == modMD->pushInfo .inlineConstantBufferOffset && bufType == CONSTANT_BUFFER && directBuf && bufId == modMD->pushInfo .inlineConstantBufferSlot );
1956
+ bool bICBOffseted =
1957
+ (IGC::INVALID_CONSTANT_BUFFER_INVALID_ADDR != modMD->pushInfo .inlineConstantBufferOffset && ADDRESS_SPACE_CONSTANT == as && isICBOffseted (inst, modMD->pushInfo .inlineConstantBufferOffset ));
1958
+ if (bICBNoOffset || bICBOffseted)
1953
1959
{
1954
1960
Value *ptrVal = inst->getPointerOperand ();
1955
- ConstantExpr *ptrExpr = dyn_cast<ConstantExpr>(ptrVal) ;
1956
- IntToPtrInst *i2p = dyn_cast<IntToPtrInst>(ptrVal) ;
1957
- if (ptrExpr == nullptr && i2p )
1961
+ Value *eltPtr = nullptr ;
1962
+ Value *eltIdx = nullptr ;
1963
+ if (IntToPtrInst *i2p = dyn_cast<IntToPtrInst>(ptrVal) )
1958
1964
{
1959
- m_builder.SetInsertPoint (inst);
1965
+ eltPtr = i2p->getOperand (0 );
1966
+ }
1967
+ else if (GetElementPtrInst *gep = dyn_cast<GetElementPtrInst>(ptrVal))
1968
+ {
1969
+ if (gep->getNumOperands () != 3 )
1970
+ {
1971
+ continue ;
1972
+ }
1973
+
1974
+ Type* eleType = gep->getPointerOperandType ()->getPointerElementType ();
1975
+ if (!eleType->isArrayTy () ||
1976
+ !(eleType->getArrayElementType ()->isFloatTy () || eleType->getArrayElementType ()->isIntegerTy (32 )))
1977
+ {
1978
+ continue ;
1979
+ }
1980
+
1981
+ eltIdx = gep->getOperand (2 );
1982
+ }
1983
+ else
1984
+ {
1985
+ continue ;
1986
+ }
1987
+
1988
+ m_builder.SetInsertPoint (inst);
1989
+
1990
+ unsigned int size_in_bytes = inst->getType ()->getPrimitiveSizeInBits () / 8 ;
1991
+ if (size_in_bytes)
1992
+ {
1993
+ Value* ICBbuffer = UndefValue::get (VectorType::get (inst->getType (), maxImmConstantSizePushed / size_in_bytes));
1994
+ if (inst->getType ()->isFloatTy ())
1995
+ {
1996
+ float returnConstant = 0 ;
1997
+ for (unsigned int i = 0 ; i < maxImmConstantSizePushed; i += size_in_bytes)
1998
+ {
1999
+ memcpy_s (&returnConstant, size_in_bytes, offset + i, size_in_bytes);
2000
+ Value *fp = ConstantFP::get (inst->getType (), returnConstant);
2001
+ ICBbuffer = m_builder.CreateInsertElement (ICBbuffer, fp, m_builder.getInt32 (i / size_in_bytes));
2002
+ }
1960
2003
1961
- unsigned int size_in_bytes = inst->getType ()->getPrimitiveSizeInBits () / 8 ;
1962
- if (size_in_bytes)
2004
+ if (eltPtr)
2005
+ {
2006
+ eltIdx = m_builder.CreateLShr (eltPtr, m_builder.getInt32 (2 ));
2007
+ }
2008
+ Value *ICBvalue = m_builder.CreateExtractElement (ICBbuffer, eltIdx);
2009
+ inst->replaceAllUsesWith (ICBvalue);
2010
+ }
2011
+ else if (inst->getType ()->isIntegerTy (32 ))
1963
2012
{
1964
- Value* ICBbuffer = UndefValue::get ( VectorType::get (inst-> getType (), maxImmConstantSizePushed / size_in_bytes)) ;
1965
- if (inst-> getType ()-> isFloatingPointTy () )
2013
+ int returnConstant = 0 ;
2014
+ for ( unsigned int i = 0 ; i < maxImmConstantSizePushed; i += size_in_bytes )
1966
2015
{
1967
- float returnConstant = 0 ;
1968
- for (unsigned int i = 0 ; i < maxImmConstantSizePushed; i += size_in_bytes)
1969
- {
1970
- memcpy_s (&returnConstant, size_in_bytes, offset + i, size_in_bytes);
1971
- Value *fp = ConstantFP::get (inst->getType (), returnConstant);
1972
- ICBbuffer = m_builder.CreateInsertElement (ICBbuffer, fp, m_builder.getInt32 (i / size_in_bytes));
1973
- }
1974
- Value *eltIdxVal = i2p->getOperand (0 );
1975
- Value *div = m_builder.CreateLShr (eltIdxVal, m_builder.getInt32 (2 ));
1976
- Value *ICBvalue = m_builder.CreateExtractElement (ICBbuffer, div);
1977
- inst->replaceAllUsesWith (ICBvalue);
2016
+ memcpy_s (&returnConstant, size_in_bytes, offset + i, size_in_bytes);
2017
+ Value *fp = ConstantInt::get (inst->getType (), returnConstant);
2018
+ ICBbuffer = m_builder.CreateInsertElement (ICBbuffer, fp, m_builder.getInt32 (i / size_in_bytes));
1978
2019
}
1979
- else if (inst-> getType ()-> isIntegerTy () )
2020
+ if (eltPtr )
1980
2021
{
1981
- int returnConstant = 0 ;
1982
- for (unsigned int i = 0 ; i < maxImmConstantSizePushed; i += size_in_bytes)
1983
- {
1984
- memcpy_s (&returnConstant, size_in_bytes, offset + i, size_in_bytes);
1985
- Value *fp = ConstantInt::get (inst->getType (), returnConstant);
1986
- ICBbuffer = m_builder.CreateInsertElement (ICBbuffer, fp, m_builder.getInt32 (i / size_in_bytes));
1987
- }
1988
- Value *eltIdxVal = i2p->getOperand (0 );
1989
- Value *div = m_builder.CreateLShr (eltIdxVal, m_builder.getInt32 (2 ));
1990
- Value *ICBvalue = m_builder.CreateExtractElement (ICBbuffer, div);
1991
- inst->replaceAllUsesWith (ICBvalue);
2022
+ eltIdx = m_builder.CreateLShr (eltPtr, m_builder.getInt32 (2 ));
1992
2023
}
2024
+ Value *ICBvalue = m_builder.CreateExtractElement (ICBbuffer, eltIdx);
2025
+ inst->replaceAllUsesWith (ICBvalue);
1993
2026
}
1994
2027
}
1995
2028
}
@@ -2001,6 +2034,24 @@ bool IGCIndirectICBPropagaion::runOnFunction(Function &F)
2001
2034
return false ;
2002
2035
}
2003
2036
2037
+ bool IGCIndirectICBPropagaion::isICBOffseted (llvm::LoadInst* inst, uint offset) {
2038
+ Value *ptrVal = inst->getPointerOperand ();
2039
+ std::vector<Value*> srcInstList;
2040
+ IGC::TracePointerSource (ptrVal, false , true , srcInstList);
2041
+ if (srcInstList.size ())
2042
+ {
2043
+ CallInst* inst = dyn_cast<CallInst>(srcInstList.back ());
2044
+ GenIntrinsicInst* genIntr = inst ? dyn_cast<GenIntrinsicInst>(inst) : nullptr ;
2045
+ if (!genIntr || (genIntr->getIntrinsicID () != GenISAIntrinsic::GenISA_RuntimeValue))
2046
+ return false ;
2047
+
2048
+ llvm::ConstantInt* ci = dyn_cast<llvm::ConstantInt>(inst->getOperand (0 ));
2049
+ return ci && (uint)ci->getZExtValue () == offset;
2050
+ }
2051
+
2052
+ return false ;
2053
+ }
2054
+
2004
2055
IGC_INITIALIZE_PASS_BEGIN (IGCIndirectICBPropagaion, " IGCIndirectICBPropagaion" ,
2005
2056
" IGCIndirectICBPropagaion" , false , false )
2006
2057
IGC_INITIALIZE_PASS_END(IGCIndirectICBPropagaion, " IGCIndirectICBPropagaion" ,
0 commit comments