From bebca662d4ff77a69f5f492dc7b14dcc5208840a Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 10 Aug 2020 08:05:26 -0400 Subject: [PATCH] [InstCombine] rearrange code for readability; NFC The code comment refers to the path where we change the size of the integer type, so handle that first, otherwise deal with the general case. --- .../InstCombine/InstCombineCasts.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index c82a82c601b67c..d6d63a59754b2b 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1932,22 +1932,22 @@ Instruction *InstCombinerImpl::visitPtrToInt(PtrToIntInst &CI) { // If the destination integer type is not the intptr_t type for this target, // do a ptrtoint to intptr_t then do a trunc or zext. This allows the cast // to be exposed to other transforms. - + Value *SrcOp = CI.getPointerOperand(); Type *Ty = CI.getType(); unsigned AS = CI.getPointerAddressSpace(); + if (Ty->getScalarSizeInBits() != DL.getPointerSizeInBits(AS)) { + Type *IntPtrTy = DL.getIntPtrType(CI.getContext(), AS); + if (auto *VecTy = dyn_cast(Ty)) { + // Handle vectors of pointers. + // FIXME: what should happen for scalable vectors? + IntPtrTy = FixedVectorType::get(IntPtrTy, VecTy->getNumElements()); + } - if (Ty->getScalarSizeInBits() == DL.getPointerSizeInBits(AS)) - return commonPointerCastTransforms(CI); - - Type *PtrTy = DL.getIntPtrType(CI.getContext(), AS); - if (auto *VTy = dyn_cast(Ty)) { - // Handle vectors of pointers. - // FIXME: what should happen for scalable vectors? - PtrTy = FixedVectorType::get(PtrTy, VTy->getNumElements()); + Value *P = Builder.CreatePtrToInt(SrcOp, IntPtrTy); + return CastInst::CreateIntegerCast(P, Ty, /*isSigned=*/false); } - Value *P = Builder.CreatePtrToInt(CI.getOperand(0), PtrTy); - return CastInst::CreateIntegerCast(P, Ty, /*isSigned=*/false); + return commonPointerCastTransforms(CI); } /// This input value (which is known to have vector type) is being zero extended