Index: include/llvm/CodeGen/FastISel.h =================================================================== --- include/llvm/CodeGen/FastISel.h +++ include/llvm/CodeGen/FastISel.h @@ -113,7 +113,7 @@ /// This is a wrapper around getRegForValue that also takes care of truncating /// or sign-extending the given getelementptr index value. - std::pair getRegForGEPIndex(const Value *V); + std::pair getRegForGEPIndex(MVT PtrVT, const Value *V); /// \brief We're checking to see if we can fold \p LI into \p FoldInst. Note /// that we could have a sequence where multiple LLVM IR instructions are Index: lib/CodeGen/SelectionDAG/FastISel.cpp =================================================================== --- lib/CodeGen/SelectionDAG/FastISel.cpp +++ lib/CodeGen/SelectionDAG/FastISel.cpp @@ -205,7 +205,7 @@ if (!Reg) { // Try to emit the constant by using an integer constant with a cast. const APFloat &Flt = CF->getValueAPF(); - EVT IntVT = TLI.getPointerTy(); + EVT IntVT = TLI.getPointerTy(0); uint64_t x[2]; uint32_t IntBitWidth = IntVT.getSizeInBits(); @@ -284,7 +284,8 @@ } } -std::pair FastISel::getRegForGEPIndex(const Value *Idx) { +std::pair FastISel::getRegForGEPIndex(MVT PtrVT, + const Value *Idx) { unsigned IdxN = getRegForValue(Idx); if (IdxN == 0) // Unhandled operand. Halt "fast" selection and bail. @@ -293,7 +294,6 @@ bool IdxNIsKill = hasTrivialKill(Idx); // If the index is smaller or larger than intptr_t, truncate or extend it. - MVT PtrVT = TLI.getPointerTy(); EVT IdxVT = EVT::getEVT(Idx->getType(), /*HandleUnknown=*/false); if (IdxVT.bitsLT(PtrVT)) { IdxN = FastEmit_r(IdxVT.getSimpleVT(), PtrVT, ISD::SIGN_EXTEND, @@ -477,7 +477,7 @@ // FIXME: What's a good SWAG number for MaxOffs? uint64_t MaxOffs = 2048; Type *Ty = I->getOperand(0)->getType(); - MVT VT = TLI.getPointerTy(); + MVT VT = TLI.getPointerTy(Ty->getPointerAddressSpace()); for (GetElementPtrInst::const_op_iterator OI = I->op_begin()+1, E = I->op_end(); OI != E; ++OI) { const Value *Idx = *OI; @@ -526,7 +526,7 @@ // N = N + Idx * ElementSize; uint64_t ElementSize = DL.getTypeAllocSize(Ty); - std::pair Pair = getRegForGEPIndex(Idx); + std::pair Pair = getRegForGEPIndex(VT, Idx); unsigned IdxN = Pair.first; bool IdxNIsKill = Pair.second; if (IdxN == 0) Index: lib/Target/X86/X86FastISel.cpp =================================================================== --- lib/Target/X86/X86FastISel.cpp +++ lib/Target/X86/X86FastISel.cpp @@ -415,7 +415,8 @@ // Prepare for inserting code in the local-value area. SavePoint SaveInsertPt = enterLocalValueArea(); - if (TLI.getPointerTy() == MVT::i64) { + unsigned AS = GV->getType()->getPointerAddressSpace(); + if (TLI.getPointerTy(AS) == MVT::i64) { Opc = X86::MOV64rm; RC = &X86::GR64RegClass; @@ -495,18 +496,20 @@ // Look past bitcasts. return X86SelectAddress(U->getOperand(0), AM); - case Instruction::IntToPtr: + case Instruction::IntToPtr: { // Look past no-op inttoptrs. - if (TLI.getValueType(U->getOperand(0)->getType()) == TLI.getPointerTy()) + unsigned AS = U->getType()->getPointerAddressSpace(); + if (TLI.getValueType(U->getOperand(0)->getType()) == TLI.getPointerTy(AS)) return X86SelectAddress(U->getOperand(0), AM); break; - - case Instruction::PtrToInt: + } + case Instruction::PtrToInt: { // Look past no-op ptrtoints. - if (TLI.getValueType(U->getType()) == TLI.getPointerTy()) + unsigned AS = U->getOperand(0)->getType()->getPointerAddressSpace(); + if (TLI.getValueType(U->getType()) == TLI.getPointerTy(AS)) return X86SelectAddress(U->getOperand(0), AM); break; - + } case Instruction::Alloca: { // Do static allocas. const AllocaInst *A = cast(V); @@ -541,6 +544,7 @@ unsigned IndexReg = AM.IndexReg; unsigned Scale = AM.Scale; gep_type_iterator GTI = gep_type_begin(U); + MVT PtrTy = TLI.getPointerTy(U->getType()->getPointerAddressSpace()); // Iterate through the indices, folding what we can. Constants can be // folded, and one dynamic index can be handled, if the scale is supported. for (User::const_op_iterator i = U->op_begin() + 1, e = U->op_end(); @@ -575,7 +579,7 @@ (S == 1 || S == 2 || S == 4 || S == 8)) { // Scaled-index addressing. Scale = S; - IndexReg = getRegForGEPIndex(Op).first; + IndexReg = getRegForGEPIndex(PtrTy, Op).first; if (IndexReg == 0) return false; break; @@ -670,20 +674,27 @@ return X86SelectCallAddress(U->getOperand(0), AM); break; - case Instruction::IntToPtr: + case Instruction::IntToPtr: { // Look past no-op inttoptrs if its operand is in the same BB. - if (InMBB && - TLI.getValueType(U->getOperand(0)->getType()) == TLI.getPointerTy()) + if (!InMBB) + break; + + unsigned AS = U->getType()->getPointerAddressSpace(); + if (TLI.getValueType(U->getOperand(0)->getType()) == TLI.getPointerTy(AS)) return X86SelectCallAddress(U->getOperand(0), AM); break; - - case Instruction::PtrToInt: + } + case Instruction::PtrToInt: { // Look past no-op ptrtoints if its operand is in the same BB. - if (InMBB && - TLI.getValueType(U->getType()) == TLI.getPointerTy()) + if (!InMBB) + break; + + unsigned AS = U->getOperand(0)->getType()->getPointerAddressSpace(); + if (TLI.getValueType(U->getType()) == TLI.getPointerTy(AS)) return X86SelectCallAddress(U->getOperand(0), AM); break; } + } // Handle constant address. if (const GlobalValue *GV = dyn_cast(V)) { @@ -2440,7 +2451,8 @@ AM.IndexReg == 0 && AM.Disp == 0 && AM.GV == 0) return AM.Base.Reg; - Opc = TLI.getPointerTy() == MVT::i32 ? X86::LEA32r : X86::LEA64r; + unsigned AS = C->getType()->getPointerAddressSpace(); + Opc = TLI.getPointerTy(AS) == MVT::i32 ? X86::LEA32r : X86::LEA64r; unsigned ResultReg = createResultReg(RC); addFullAddress(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), ResultReg), AM); @@ -2496,7 +2508,8 @@ if (!X86SelectAddress(C, AM)) return 0; unsigned Opc = Subtarget->is64Bit() ? X86::LEA64r : X86::LEA32r; - const TargetRegisterClass* RC = TLI.getRegClassFor(TLI.getPointerTy()); + unsigned AS = C->getType()->getPointerAddressSpace(); + const TargetRegisterClass *RC = TLI.getRegClassFor(TLI.getPointerTy(AS)); unsigned ResultReg = createResultReg(RC); addFullAddress(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc, TII.get(Opc), ResultReg), AM);