[PATCH] D98595: [NFC] Refactor the code to avoid check target type.
LuoYuanke via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 13 19:33:46 PST 2021
LuoYuanke updated this revision to Diff 330491.
LuoYuanke added a comment.
Fix the comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D98595/new/
https://reviews.llvm.org/D98595
Files:
llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
Index: llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineLoadStoreAlloca.cpp
@@ -590,12 +590,12 @@
// Note that we should not do this for pointer<->integer casts,
// because that would result in type punning.
if (LI.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!");
- if (BC->getType()->isX86_AMXTy())
+ // Prevent bitcasting the pointer if the cast is not lossless.
+ auto *DestPtrTy =
+ BC->getType()->getPointerTo(LI.getPointerAddressSpace());
+ auto *SrcPtrTy = LI.getPointerOperandType();
+ if (!SrcPtrTy->canLosslesslyBitCastTo(DestPtrTy))
return nullptr;
}
@@ -1121,12 +1121,11 @@
// Fold away bit casts of the stored value by storing the original type.
if (auto *BC = dyn_cast<BitCastInst>(V)) {
- assert(!BC->getType()->isX86_AMXTy() &&
- "store to x86_amx* should not happen!");
V = BC->getOperand(0);
- // Don't transform when the type is x86_amx, it makes the pass that lower
- // x86_amx type happy.
- if (V->getType()->isX86_AMXTy())
+ // Prevent bitcasting the pointer if the cast is not lossless.
+ auto *DestPtrTy = V->getType()->getPointerTo(SI.getPointerAddressSpace());
+ auto *SrcPtrTy = SI.getPointerOperandType();
+ if (!SrcPtrTy->canLosslesslyBitCastTo(DestPtrTy))
return false;
if (!SI.isAtomic() || isSupportedAtomicType(V->getType())) {
combineStoreToNewValue(IC, SI, V);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98595.330491.patch
Type: text/x-patch
Size: 1854 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210314/b7548007/attachment.bin>
More information about the llvm-commits
mailing list