[llvm] a009364 - [InstCombine] improve readability of combineLoadToOperationType(); NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 28 13:00:16 PST 2022
Author: Sanjay Patel
Date: 2022-11-28T16:00:06-05:00
New Revision: a00936484b65f4d9756e03ab32c7ec3705fcdc53
URL: https://github.com/llvm/llvm-project/commit/a00936484b65f4d9756e03ab32c7ec3705fcdc53
DIFF: https://github.com/llvm/llvm-project/commit/a00936484b65f4d9756e03ab32c7ec3705fcdc53.diff
LOG: [InstCombine] improve readability of combineLoadToOperationType(); NFC
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
index d38e856cd4d68..c11510cc159b4 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -582,43 +582,43 @@ static bool isMinMaxWithLoads(Value *V, Type *&LoadTy) {
/// later. However, it is risky in case some backend or other part of LLVM is
/// relying on the exact type loaded to select appropriate atomic operations.
static Instruction *combineLoadToOperationType(InstCombinerImpl &IC,
- LoadInst &LI) {
+ LoadInst &Load) {
// FIXME: We could probably with some care handle both volatile and ordered
// atomic loads here but it isn't clear that this is important.
- if (!LI.isUnordered())
+ if (!Load.isUnordered())
return nullptr;
- if (LI.use_empty())
+ if (Load.use_empty())
return nullptr;
// swifterror values can't be bitcasted.
- if (LI.getPointerOperand()->isSwiftError())
+ if (Load.getPointerOperand()->isSwiftError())
return nullptr;
- const DataLayout &DL = IC.getDataLayout();
-
// Fold away bit casts of the loaded value by loading the desired type.
// Note that we should not do this for pointer<->integer casts,
// because that would result in type punning.
- if (LI.hasOneUse()) {
+ if (Load.hasOneUse()) {
// Don't transform when the type is x86_amx, it makes the pass that lower
// x86_amx type happy.
- if (auto *BC = dyn_cast<BitCastInst>(LI.user_back())) {
- assert(!LI.getType()->isX86_AMXTy() &&
- "load from x86_amx* should not happen!");
+ Type *LoadTy = Load.getType();
+ if (auto *BC = dyn_cast<BitCastInst>(Load.user_back())) {
+ assert(!LoadTy->isX86_AMXTy() && "Load from x86_amx* should not happen!");
if (BC->getType()->isX86_AMXTy())
return nullptr;
}
- if (auto* CI = dyn_cast<CastInst>(LI.user_back()))
- if (CI->isNoopCast(DL) && LI.getType()->isPtrOrPtrVectorTy() ==
- CI->getDestTy()->isPtrOrPtrVectorTy())
- if (!LI.isAtomic() || isSupportedAtomicType(CI->getDestTy())) {
- LoadInst *NewLoad = IC.combineLoadToNewType(LI, CI->getDestTy());
- CI->replaceAllUsesWith(NewLoad);
- IC.eraseInstFromFunction(*CI);
- return &LI;
- }
+ if (auto *CastUser = dyn_cast<CastInst>(Load.user_back())) {
+ Type *DestTy = CastUser->getDestTy();
+ if (CastUser->isNoopCast(IC.getDataLayout()) &&
+ LoadTy->isPtrOrPtrVectorTy() == DestTy->isPtrOrPtrVectorTy() &&
+ (!Load.isAtomic() || isSupportedAtomicType(DestTy))) {
+ LoadInst *NewLoad = IC.combineLoadToNewType(Load, DestTy);
+ CastUser->replaceAllUsesWith(NewLoad);
+ IC.eraseInstFromFunction(*CastUser);
+ return &Load;
+ }
+ }
}
// FIXME: We should also canonicalize loads of vectors when their elements are
More information about the llvm-commits
mailing list