[llvm] cf348f6 - [InstCombine] [NFC] Use a pattern matcher for ExtractElementInst

Chenbing Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu May 19 19:32:00 PDT 2022


Author: Chenbing Zheng
Date: 2022-05-20T10:31:40+08:00
New Revision: cf348f6a2cac654bfc97dda964c319066bb9c961

URL: https://github.com/llvm/llvm-project/commit/cf348f6a2cac654bfc97dda964c319066bb9c961
DIFF: https://github.com/llvm/llvm-project/commit/cf348f6a2cac654bfc97dda964c319066bb9c961.diff

LOG: [InstCombine] [NFC] Use a pattern matcher for ExtractElementInst

Reviewed By: RKSimon, rampitec

Differential Revision: https://reviews.llvm.org/D125857

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 764c8df2313d0..fd76ea6bbcc73 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -2350,9 +2350,9 @@ static Value *optimizeIntegerToVectorInsertions(BitCastInst &CI,
 /// 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, *Index;
+  if (!match(BitCast.getOperand(0),
+             m_OneUse(m_ExtractElt(m_Value(VecOp), m_Value(Index)))))
     return nullptr;
 
   // The bitcast must be to a vectorizable type, otherwise we can't make a new
@@ -2361,10 +2361,10 @@ static Instruction *canonicalizeBitCastExtElt(BitCastInst &BitCast,
   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, Index);
 }
 
 /// Change the type of a bitwise logic operation if we can eliminate a bitcast.


        


More information about the llvm-commits mailing list