@@ -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