Skip to content

Commit

Permalink
[InstCombine] rearrange code for readability; NFC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rotateright committed Aug 10, 2020
1 parent 3d2cf72 commit bebca66
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<VectorType>(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<VectorType>(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
Expand Down

0 comments on commit bebca66

Please sign in to comment.