@@ -1918,8 +1918,6 @@ namespace {
1918
1918
AU.setPreservesCFG ();
1919
1919
AU.addRequired <CodeGenContextWrapper>();
1920
1920
}
1921
- private:
1922
- bool isICBOffseted (llvm::LoadInst* inst, uint offset);
1923
1921
};
1924
1922
1925
1923
} // namespace
@@ -1951,78 +1949,47 @@ bool IGCIndirectICBPropagaion::runOnFunction(Function &F)
1951
1949
bool directBuf;
1952
1950
unsigned bufId;
1953
1951
BufferType bufType = IGC::DecodeAS4GFXResource (as, directBuf, bufId);
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)
1952
+ if (bufType == CONSTANT_BUFFER && directBuf && bufId == modMD->pushInfo .inlineConstantBufferSlot )
1959
1953
{
1960
1954
Value *ptrVal = inst->getPointerOperand ();
1961
- Value *eltPtr = nullptr ;
1962
- Value *eltIdx = nullptr ;
1963
- if (IntToPtrInst *i2p = dyn_cast<IntToPtrInst>(ptrVal) )
1955
+ ConstantExpr *ptrExpr = dyn_cast<ConstantExpr>(ptrVal) ;
1956
+ IntToPtrInst *i2p = dyn_cast<IntToPtrInst>(ptrVal) ;
1957
+ if (ptrExpr == nullptr && i2p )
1964
1958
{
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
- }
1959
+ m_builder.SetInsertPoint (inst);
2003
1960
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 ))
1961
+ unsigned int size_in_bytes = inst->getType ()->getPrimitiveSizeInBits () / 8 ;
1962
+ if (size_in_bytes)
2012
1963
{
2013
- int returnConstant = 0 ;
2014
- for ( unsigned int i = 0 ; i < maxImmConstantSizePushed; i += size_in_bytes )
1964
+ Value* ICBbuffer = UndefValue::get ( VectorType::get (inst-> getType (), maxImmConstantSizePushed / size_in_bytes)) ;
1965
+ if (inst-> getType ()-> isFloatingPointTy () )
2015
1966
{
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));
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);
2019
1978
}
2020
- if (eltPtr )
1979
+ else if (inst-> getType ()-> isIntegerTy () )
2021
1980
{
2022
- eltIdx = m_builder.CreateLShr (eltPtr, m_builder.getInt32 (2 ));
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);
2023
1992
}
2024
- Value *ICBvalue = m_builder.CreateExtractElement (ICBbuffer, eltIdx);
2025
- inst->replaceAllUsesWith (ICBvalue);
2026
1993
}
2027
1994
}
2028
1995
}
@@ -2034,24 +2001,6 @@ bool IGCIndirectICBPropagaion::runOnFunction(Function &F)
2034
2001
return false ;
2035
2002
}
2036
2003
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
-
2055
2004
IGC_INITIALIZE_PASS_BEGIN (IGCIndirectICBPropagaion, " IGCIndirectICBPropagaion" ,
2056
2005
" IGCIndirectICBPropagaion" , false , false )
2057
2006
IGC_INITIALIZE_PASS_END(IGCIndirectICBPropagaion, " IGCIndirectICBPropagaion" ,
0 commit comments