[llvm] [PatternMatch] Add a matching helper `m_ElementWiseBitCast`. NFC. (PR #80764)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 22:48:34 PST 2024


================
@@ -1711,6 +1711,34 @@ m_BitCast(const OpTy &Op) {
   return CastOperator_match<OpTy, Instruction::BitCast>(Op);
 }
 
+template <typename Op_t> struct ElementWiseBitCast_match {
+  Op_t Op;
+
+  ElementWiseBitCast_match(const Op_t &OpMatch) : Op(OpMatch) {}
+
+  template <typename OpTy> bool match(OpTy *V) {
+    if (auto *I = dyn_cast<BitCastInst>(V)) {
+      Type *SrcType = I->getSrcTy();
+      Type *DstType = I->getType();
+      // Make sure the bitcast doesn't change between scalar and vector and
+      // doesn't change the number of vector elements.
+      if (SrcType->isVectorTy() != DstType->isVectorTy())
+        return false;
+      if (SrcType->isVectorTy() &&
+          cast<VectorType>(SrcType)->getElementCount() !=
----------------
arsenm wrote:

Yes, I'm saying you have isVectorTy + cast when you can do it in one with dyn_cast 

https://github.com/llvm/llvm-project/pull/80764


More information about the llvm-commits mailing list