static LegalityPredicate isMultiple32(unsigned TypeIdx, unsigned MaxSize = 512) { return [=](const LegalityQuery &Query) { const LLT Ty = Query.Types[TypeIdx]; const LLT EltTy = Ty.getScalarType(); return Ty.getSizeInBits() <= MaxSize && EltTy.getSizeInBits() % 32 == 0; }; }
// Make sure the returned mutation makes sense for the match type. static bool mutationIsSane(const LegalizeRule &Rule, const LegalityQuery &Q, std::pair<unsigned, LLT> Mutation) { const unsigned TypeIdx = Mutation.first; const LLT OldTy = Q.Types[TypeIdx]; const LLT NewTy = Mutation.second; switch (Rule.getAction()) { case FewerElements: case MoreElements: { if (!OldTy.isVector()) return false; if (NewTy.isVector()) { if (Rule.getAction() == FewerElements) { // Make sure the element count really decreased. if (NewTy.getNumElements() >= OldTy.getNumElements()) return false; } else { // Make sure the element count really increased. if (NewTy.getNumElements() <= OldTy.getNumElements()) return false; } } // Make sure the element type didn't change. return NewTy.getScalarType() == OldTy.getElementType(); } case NarrowScalar: case WidenScalar: { if (OldTy.isVector()) { // Number of elements should not change. if (!NewTy.isVector() || OldTy.getNumElements() != NewTy.getNumElements()) return false; } else { // Both types must be vectors if (NewTy.isVector()) return false; } if (Rule.getAction() == NarrowScalar) { // Make sure the size really decreased. if (NewTy.getScalarSizeInBits() >= OldTy.getScalarSizeInBits()) return false; } else { // Make sure the size really increased. if (NewTy.getScalarSizeInBits() <= OldTy.getScalarSizeInBits()) return false; } return true; } default: return true; } }