diff options
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/FastISel.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 27 | 
2 files changed, 12 insertions, 21 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp index faa36b038e7..16724b0af7e 100644 --- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -497,7 +497,7 @@ bool FastISel::selectGetElementPtr(const User *I) {         OI != E; ++OI) {      const Value *Idx = *OI;      if (auto *StTy = dyn_cast<StructType>(Ty)) { -      unsigned Field = cast<ConstantInt>(Idx)->getZExtValue(); +      uint64_t Field = cast<ConstantInt>(Idx)->getZExtValue();        if (Field) {          // N = N + Offset          TotalOffs += DL.getStructLayout(StTy)->getElementOffset(Field); @@ -518,8 +518,8 @@ bool FastISel::selectGetElementPtr(const User *I) {          if (CI->isZero())            continue;          // N = N + Offset -        TotalOffs += -            DL.getTypeAllocSize(Ty) * cast<ConstantInt>(CI)->getSExtValue(); +        uint64_t IdxN = CI->getValue().sextOrTrunc(64).getSExtValue(); +        TotalOffs += DL.getTypeAllocSize(Ty) * IdxN;          if (TotalOffs >= MaxOffs) {            N = fastEmit_ri_(VT, ISD::ADD, N, NIsKill, TotalOffs, VT);            if (!N) // Unhandled operand. Halt "fast" selection and bail. diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 6fc6eb174e0..5a5827375b8 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -3448,30 +3448,21 @@ void SelectionDAGBuilder::visitGetElementPtr(const User &I) {        Ty = StTy->getElementType(Field);      } else {        Ty = cast<SequentialType>(Ty)->getElementType(); +      MVT PtrTy = DAG.getTargetLoweringInfo().getPointerTy(AS); +      unsigned PtrSize = PtrTy.getSizeInBits(); +      APInt ElementSize(PtrSize, DL->getTypeAllocSize(Ty));        // If this is a constant subscript, handle it quickly. -      const TargetLowering &TLI = DAG.getTargetLoweringInfo(); -      if (const ConstantInt *CI = dyn_cast<ConstantInt>(Idx)) { -        if (CI->isZero()) continue; -        uint64_t Offs = -            DL->getTypeAllocSize(Ty)*cast<ConstantInt>(CI)->getSExtValue(); -        SDValue OffsVal; -        EVT PTy = TLI.getPointerTy(AS); -        unsigned PtrBits = PTy.getSizeInBits(); -        if (PtrBits < 64) -          OffsVal = DAG.getNode(ISD::TRUNCATE, getCurSDLoc(), PTy, -                                DAG.getConstant(Offs, MVT::i64)); -        else -          OffsVal = DAG.getConstant(Offs, PTy); - -        N = DAG.getNode(ISD::ADD, getCurSDLoc(), N.getValueType(), N, -                        OffsVal); +      if (const auto *CI = dyn_cast<ConstantInt>(Idx)) { +        if (CI->isZero()) +          continue; +        APInt Offs = ElementSize * CI->getValue().sextOrTrunc(PtrSize); +        SDValue OffsVal = DAG.getConstant(Offs, PtrTy); +        N = DAG.getNode(ISD::ADD, getCurSDLoc(), N.getValueType(), N, OffsVal);          continue;        }        // N = N + Idx * ElementSize; -      APInt ElementSize = -          APInt(TLI.getPointerSizeInBits(AS), DL->getTypeAllocSize(Ty));        SDValue IdxN = getValue(Idx);        // If the index is smaller or larger than intptr_t, truncate or extend  | 

