@@ -406,6 +406,7 @@ static Value *GEPToVectorIndex(GetElementPtrInst *GEP, AllocaInst *Alloca,
406
406
SmallVector<Instruction *> &NewInsts) {
407
407
// TODO: Extracting a "multiple of X" from a GEP might be a useful generic
408
408
// helper.
409
+ LLVMContext &Ctx = GEP->getContext ();
409
410
unsigned BW = DL.getIndexTypeSizeInBits (GEP->getType ());
410
411
SmallMapVector<Value *, APInt, 4 > VarOffsets;
411
412
APInt ConstOffset (BW, 0 );
@@ -438,27 +439,24 @@ static Value *GEPToVectorIndex(GetElementPtrInst *GEP, AllocaInst *Alloca,
438
439
439
440
assert (CurPtr == Alloca && " GEP not based on alloca" );
440
441
441
- unsigned VecElemSize = DL.getTypeAllocSize (VecElemTy);
442
+ int64_t VecElemSize = DL.getTypeAllocSize (VecElemTy);
442
443
if (VarOffsets.size () > 1 )
443
444
return nullptr ;
444
445
445
446
APInt IndexQuot;
446
- APInt Rem;
447
- APInt::sdivrem (ConstOffset, APInt (ConstOffset.getBitWidth (), VecElemSize),
448
- IndexQuot, Rem);
449
- if (!Rem.isZero ())
447
+ int64_t Rem;
448
+ APInt::sdivrem (ConstOffset, VecElemSize, IndexQuot, Rem);
449
+ if (Rem != 0 )
450
450
return nullptr ;
451
451
if (VarOffsets.size () == 0 )
452
- return ConstantInt::get (GEP-> getContext () , IndexQuot);
452
+ return ConstantInt::get (Ctx , IndexQuot);
453
453
454
454
IRBuilder<> Builder (GEP);
455
455
456
456
const auto &VarOffset = VarOffsets.front ();
457
457
APInt OffsetQuot;
458
- APInt::sdivrem (VarOffset.second ,
459
- APInt (VarOffset.second .getBitWidth (), VecElemSize), OffsetQuot,
460
- Rem);
461
- if (!Rem.isZero () || OffsetQuot.isZero ())
458
+ APInt::sdivrem (VarOffset.second , VecElemSize, OffsetQuot, Rem);
459
+ if (Rem != 0 || OffsetQuot.isZero ())
462
460
return nullptr ;
463
461
464
462
Value *Offset = VarOffset.first ;
@@ -468,7 +466,7 @@ static Value *GEPToVectorIndex(GetElementPtrInst *GEP, AllocaInst *Alloca,
468
466
469
467
if (!OffsetQuot.isOne ()) {
470
468
ConstantInt *ConstMul =
471
- ConstantInt::get (OffsetType , OffsetQuot.getSExtValue ( ));
469
+ ConstantInt::get (Ctx , OffsetQuot.sext (OffsetType-> getBitWidth () ));
472
470
Offset = Builder.CreateMul (Offset, ConstMul);
473
471
if (Instruction *NewInst = dyn_cast<Instruction>(Offset))
474
472
NewInsts.push_back (NewInst);
@@ -477,7 +475,7 @@ static Value *GEPToVectorIndex(GetElementPtrInst *GEP, AllocaInst *Alloca,
477
475
return Offset;
478
476
479
477
ConstantInt *ConstIndex =
480
- ConstantInt::get (OffsetType , IndexQuot.getSExtValue ( ));
478
+ ConstantInt::get (Ctx , IndexQuot.sext (OffsetType-> getBitWidth () ));
481
479
Value *IndexAdd = Builder.CreateAdd (Offset, ConstIndex);
482
480
if (Instruction *NewInst = dyn_cast<Instruction>(IndexAdd))
483
481
NewInsts.push_back (NewInst);
0 commit comments