[llvm] bebca66 - [InstCombine] rearrange code for readability; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 10 05:07:37 PDT 2020
Author: Sanjay Patel
Date: 2020-08-10T08:07:29-04:00
New Revision: bebca662d4ff77a69f5f492dc7b14dcc5208840a
URL: https://github.com/llvm/llvm-project/commit/bebca662d4ff77a69f5f492dc7b14dcc5208840a
DIFF: https://github.com/llvm/llvm-project/commit/bebca662d4ff77a69f5f492dc7b14dcc5208840a.diff
LOG: [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.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
index c82a82c601b6..d6d63a59754b 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<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
More information about the llvm-commits
mailing list