[llvm] 648faa3 - [InstCombine] Mark element type access as non-opaque (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 27 02:40:36 PST 2022
Author: Nikita Popov
Date: 2022-01-27T11:40:29+01:00
New Revision: 648faa3b5d116acfa6463bbf24f81014b6dfbaf5
URL: https://github.com/llvm/llvm-project/commit/648faa3b5d116acfa6463bbf24f81014b6dfbaf5
DIFF: https://github.com/llvm/llvm-project/commit/648faa3b5d116acfa6463bbf24f81014b6dfbaf5.diff
LOG: [InstCombine] Mark element type access as non-opaque (NFC)
Also make the function static to make it more obvious that it is
only used in the one place.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineInternal.h
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
index e8c82786a3c3..7743b4c41555 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
+++ b/llvm/lib/Transforms/InstCombine/InstCombineInternal.h
@@ -197,8 +197,6 @@ class LLVM_LIBRARY_VISIBILITY InstCombinerImpl final
bool shouldChangeType(unsigned FromBitWidth, unsigned ToBitWidth) const;
bool shouldChangeType(Type *From, Type *To) const;
Value *dyn_castNegVal(Value *V) const;
- Type *FindElementAtOffset(PointerType *PtrTy, int64_t Offset,
- SmallVectorImpl<Value *> &NewIndices);
/// Classify whether a cast is worth optimizing.
///
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index bdc72b736b85..029be5257694 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1369,10 +1369,11 @@ Instruction *InstCombinerImpl::foldBinOpIntoSelectOrPhi(BinaryOperator &I) {
/// is a sequence of GEP indices into the pointed type that will land us at the
/// specified offset. If so, fill them into NewIndices and return the resultant
/// element type, otherwise return null.
-Type *
-InstCombinerImpl::FindElementAtOffset(PointerType *PtrTy, int64_t IntOffset,
- SmallVectorImpl<Value *> &NewIndices) {
- Type *Ty = PtrTy->getPointerElementType();
+static Type *findElementAtOffset(PointerType *PtrTy, int64_t IntOffset,
+ SmallVectorImpl<Value *> &NewIndices,
+ const DataLayout &DL) {
+ // Only used by visitGEPOfBitcast(), which is skipped for opaque pointers.
+ Type *Ty = PtrTy->getNonOpaquePointerElementType();
if (!Ty->isSized())
return nullptr;
@@ -1382,7 +1383,7 @@ InstCombinerImpl::FindElementAtOffset(PointerType *PtrTy, int64_t IntOffset,
return nullptr;
for (const APInt &Index : Indices)
- NewIndices.push_back(Builder.getInt(Index));
+ NewIndices.push_back(ConstantInt::get(PtrTy->getContext(), Index));
return Ty;
}
@@ -2168,7 +2169,7 @@ Instruction *InstCombinerImpl::visitGEPOfBitcast(BitCastInst *BCI,
// field at Offset in 'A's type. If so, we can pull the cast through the
// GEP.
SmallVector<Value*, 8> NewIndices;
- if (FindElementAtOffset(SrcType, Offset.getSExtValue(), NewIndices)) {
+ if (findElementAtOffset(SrcType, Offset.getSExtValue(), NewIndices, DL)) {
Value *NGEP =
GEP.isInBounds()
? Builder.CreateInBoundsGEP(SrcEltType, SrcOp, NewIndices)
More information about the llvm-commits
mailing list