@@ -399,33 +399,39 @@ bool X86FastISel::X86SelectAddress(const Value *V, X86AddressMode &AM) {
399
399
Disp += SL->getElementOffset (Idx);
400
400
} else {
401
401
uint64_t S = TD.getTypeAllocSize (GTI.getIndexedType ());
402
- SmallVector<const Value *, 4 > Worklist;
403
- Worklist.push_back (Op);
404
- do {
405
- Op = Worklist.pop_back_val ();
402
+ for (;;) {
406
403
if (const ConstantInt *CI = dyn_cast<ConstantInt>(Op)) {
407
404
// Constant-offset addressing.
408
405
Disp += CI->getSExtValue () * S;
409
- } else if (isa<AddOperator>(Op) &&
410
- isa<ConstantInt>(cast<AddOperator>(Op)->getOperand (1 ))) {
411
- // An add with a constant operand. Fold the constant.
406
+ break ;
407
+ }
408
+ if (isa<AddOperator>(Op) &&
409
+ (!isa<Instruction>(Op) ||
410
+ FuncInfo.MBBMap [cast<Instruction>(Op)->getParent ()]
411
+ == FuncInfo.MBB ) &&
412
+ isa<ConstantInt>(cast<AddOperator>(Op)->getOperand (1 ))) {
413
+ // An add (in the same block) with a constant operand. Fold the
414
+ // constant.
412
415
ConstantInt *CI =
413
416
cast<ConstantInt>(cast<AddOperator>(Op)->getOperand (1 ));
414
417
Disp += CI->getSExtValue () * S;
415
- // Add the other operand back to the work list.
416
- Worklist.push_back (cast<AddOperator>(Op)->getOperand (0 ));
417
- } else if (IndexReg == 0 &&
418
- (!AM.GV || !Subtarget->isPICStyleRIPRel ()) &&
419
- (S == 1 || S == 2 || S == 4 || S == 8 )) {
418
+ // Iterate on the other operand.
419
+ Op = cast<AddOperator>(Op)->getOperand (0 );
420
+ continue ;
421
+ }
422
+ if (IndexReg == 0 &&
423
+ (!AM.GV || !Subtarget->isPICStyleRIPRel ()) &&
424
+ (S == 1 || S == 2 || S == 4 || S == 8 )) {
420
425
// Scaled-index addressing.
421
426
Scale = S;
422
427
IndexReg = getRegForGEPIndex (Op).first ;
423
428
if (IndexReg == 0 )
424
429
return false ;
425
- } else
426
- // Unsupported.
427
- goto unsupported_gep;
428
- } while (!Worklist.empty ());
430
+ break ;
431
+ }
432
+ // Unsupported.
433
+ goto unsupported_gep;
434
+ }
429
435
}
430
436
}
431
437
// Check for displacement overflow.
0 commit comments