@@ -1932,22 +1932,22 @@ Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {
19321932 // If the destination integer type is not the intptr_t type for this target,
19331933 // do a ptrtoint to intptr_t then do a trunc or zext. This allows the cast
19341934 // to be exposed to other transforms.
1935-
1935+ Value *SrcOp = CI. getPointerOperand ();
19361936 Type *Ty = CI.getType ();
19371937 unsigned AS = CI.getPointerAddressSpace ();
1938+ if (Ty->getScalarSizeInBits () != DL.getPointerSizeInBits (AS)) {
1939+ Type *IntPtrTy = DL.getIntPtrType (CI.getContext (), AS);
1940+ if (auto *VecTy = dyn_cast<VectorType>(Ty)) {
1941+ // Handle vectors of pointers.
1942+ // FIXME: what should happen for scalable vectors?
1943+ IntPtrTy = FixedVectorType::get (IntPtrTy, VecTy->getNumElements ());
1944+ }
19381945
1939- if (Ty->getScalarSizeInBits () == DL.getPointerSizeInBits (AS))
1940- return commonPointerCastTransforms (CI);
1941-
1942- Type *PtrTy = DL.getIntPtrType (CI.getContext (), AS);
1943- if (auto *VTy = dyn_cast<VectorType>(Ty)) {
1944- // Handle vectors of pointers.
1945- // FIXME: what should happen for scalable vectors?
1946- PtrTy = FixedVectorType::get (PtrTy, VTy->getNumElements ());
1946+ Value *P = Builder.CreatePtrToInt (SrcOp, IntPtrTy);
1947+ return CastInst::CreateIntegerCast (P, Ty, /* isSigned=*/ false );
19471948 }
19481949
1949- Value *P = Builder.CreatePtrToInt (CI.getOperand (0 ), PtrTy);
1950- return CastInst::CreateIntegerCast (P, Ty, /* isSigned=*/ false );
1950+ return commonPointerCastTransforms (CI);
19511951}
19521952
19531953// / This input value (which is known to have vector type) is being zero extended
0 commit comments