Skip to content

Commit 8e40147

Browse files
pkwasnie-inteligcbot
authored andcommitted
ScalarArgAsPointerAnalysis pass refactoring
A small refactoring to ScalarArgAsPointerAnalysis pass.
1 parent c93c673 commit 8e40147

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

IGC/AdaptorOCL/ocl_igc_shared/indirect_access_detection/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ SPDX-License-Identifier: MIT
1313

1414
#pragma once
1515

16-
const uint32_t INDIRECT_ACCESS_DETECTION_VERSION = 9;
16+
const uint32_t INDIRECT_ACCESS_DETECTION_VERSION = 10;

IGC/Compiler/Optimizer/OpenCLPasses/ScalarArgAsPointer/ScalarArgAsPointer.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -201,28 +201,26 @@ ScalarArgAsPointerAnalysis::findArgs(llvm::Instruction* inst)
201201
if (!findStoredArgs(*LI, *result))
202202
return nullptr; // (1) Found indirect access, fail search
203203
}
204-
else if (SelectInst* SI = dyn_cast<SelectInst>(inst))
205-
{
206-
auto args1 = analyzeOperand(inst->getOperand(1));
207-
auto args2 = analyzeOperand(inst->getOperand(2));
208-
209-
if (!args1 && !args2)
210-
return nullptr; // propagate fail only if both paths fails
211-
212-
if (args1)
213-
result->insert(args1->begin(), args1->end());
214-
215-
if (args2)
216-
result->insert(args2->begin(), args2->end());
217-
}
218204
else
219205
{
220-
// For any other type of instruction trace back operands.
221-
unsigned int numOperands = isa<GetElementPtrInst>(inst) ? 1 : inst->getNumOperands();
206+
// Iterate and trace back operands.
207+
auto begin = inst->operands().begin();
208+
auto end = inst->operands().end();
209+
210+
if (isa<SelectInst>(inst))
211+
{
212+
// For select, skip condition operand (first arg)
213+
begin++;
214+
}
215+
else if (isa<GetElementPtrInst>(inst))
216+
{
217+
// For GEP, use only base pointer operand (first arg)
218+
end = begin + 1;
219+
}
222220

223-
for (unsigned int i = 0; i < numOperands; ++i)
221+
for (auto it = begin; it != end; ++it)
224222
{
225-
auto args = analyzeOperand(inst->getOperand(i));
223+
auto args = analyzeOperand(*it);
226224

227225
if (args)
228226
result->insert(args->begin(), args->end());

0 commit comments

Comments
 (0)