Skip to content

Commit c27ed5e

Browse files
jhananitsys_zuul
authored andcommitted
Adding back the support for getting the constant address from
a load instruction with constant expression as the pointer operand Change-Id: I02130a78ea6fbd15ba47825d6b2a6c6bf8ea69a0
1 parent aa02e72 commit c27ed5e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

IGC/Compiler/CISACodeGen/helper.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,26 @@ namespace IGC
588588

589589
bool EvalConstantAddress(Value* address, unsigned int& offset, const llvm::DataLayout* pDL, Value* ptrSrc)
590590
{
591+
591592
if ((ptrSrc == nullptr && isa<ConstantPointerNull>(address)) ||
592593
(ptrSrc == address))
593594
{
594595
offset = 0;
595596
return true;
596597
}
597-
else if (Instruction * ptrExpr = dyn_cast<Instruction>(address))
598+
else if (ConstantExpr * ptrExpr = dyn_cast<ConstantExpr>(address))
599+
{
600+
if (ptrExpr->getOpcode() == Instruction::IntToPtr)
601+
{
602+
Value* eltIdxVal = ptrExpr->getOperand(0);
603+
ConstantInt* eltIdx = dyn_cast<ConstantInt>(eltIdxVal);
604+
if (!eltIdx)
605+
return false;
606+
offset = int_cast<unsigned>(eltIdx->getZExtValue());
607+
return true;
608+
}
609+
}
610+
else if (Instruction* ptrExpr = dyn_cast<Instruction>(address))
598611
{
599612
if (ptrExpr->getOpcode() == Instruction::BitCast ||
600613
ptrExpr->getOpcode() == Instruction::AddrSpaceCast)

0 commit comments

Comments
 (0)