@@ -1932,22 +1932,22 @@ Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) {
1932
1932
// If the destination integer type is not the intptr_t type for this target,
1933
1933
// do a ptrtoint to intptr_t then do a trunc or zext. This allows the cast
1934
1934
// to be exposed to other transforms.
1935
-
1935
+ Value *SrcOp = CI. getPointerOperand ();
1936
1936
Type *Ty = CI.getType ();
1937
1937
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
+ }
1938
1945
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 );
1947
1948
}
1948
1949
1949
- Value *P = Builder.CreatePtrToInt (CI.getOperand (0 ), PtrTy);
1950
- return CastInst::CreateIntegerCast (P, Ty, /* isSigned=*/ false );
1950
+ return commonPointerCastTransforms (CI);
1951
1951
}
1952
1952
1953
1953
// / This input value (which is known to have vector type) is being zero extended
0 commit comments