Skip to content

Commit bebca66

Browse files
committed
[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.
1 parent 3d2cf72 commit bebca66

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Diff for: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)