[PATCH] D125857: [InstCombine] [NFC] Use a pattern matcher for ExtractElementInst.
Chenbing.Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 18 00:41:04 PDT 2022
Chenbing.Zheng created this revision.
Chenbing.Zheng added reviewers: spatel, RKSimon, benshi001.
Chenbing.Zheng added a project: LLVM.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Chenbing.Zheng requested review of this revision.
Herald added subscribers: llvm-commits, jacquesguan.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125857
Files:
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
Index: llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2350,9 +2350,10 @@
/// usually not type-specific like scalar integer or scalar floating-point.
static Instruction *canonicalizeBitCastExtElt(BitCastInst &BitCast,
InstCombinerImpl &IC) {
- // TODO: Create and use a pattern matcher for ExtractElementInst.
- auto *ExtElt = dyn_cast<ExtractElementInst>(BitCast.getOperand(0));
- if (!ExtElt || !ExtElt->hasOneUse())
+ Value *VecOp;
+ ConstantInt *Cst;
+ if (!match(BitCast.getOperand(0),
+ m_OneUse(m_ExtractElt(m_Value(VecOp), m_ConstantInt(Cst)))))
return nullptr;
// The bitcast must be to a vectorizable type, otherwise we can't make a new
@@ -2361,10 +2362,10 @@
if (!VectorType::isValidElementType(DestType))
return nullptr;
- auto *NewVecType = VectorType::get(DestType, ExtElt->getVectorOperandType());
- auto *NewBC = IC.Builder.CreateBitCast(ExtElt->getVectorOperand(),
- NewVecType, "bc");
- return ExtractElementInst::Create(NewBC, ExtElt->getIndexOperand());
+ auto *NewVecType =
+ VectorType::get(DestType, cast<VectorType>(VecOp->getType()));
+ auto *NewBC = IC.Builder.CreateBitCast(VecOp, NewVecType, "bc");
+ return ExtractElementInst::Create(NewBC, Cst);
}
/// Change the type of a bitwise logic operation if we can eliminate a bitcast.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125857.430256.patch
Type: text/x-patch
Size: 1592 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220518/1bc611aa/attachment.bin>
More information about the llvm-commits
mailing list