Generalize existing constant matching to work with non-uniform constant vectors as well.
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
include/llvm/IR/PatternMatch.h | ||
---|---|---|
296 ↗ | (On Diff #132474) | Is there a reason to limit the matcher to ConstantDataVector? If not, we should generalize to: // Non-splat vector constant: check each element for a match. unsigned NumElts = V->getType()->getVectorNumElements(); assert(NumElts != 0 && "Constant vector with no elements?"); for (unsigned i = 0; i != NumElts; ++i) { Constant *Elt = C->getAggregateElement(i); if (!Elt) return false; if (isa<UndefValue>(Elt)) continue; auto *CI = dyn_cast<ConstantInt>(Elt); if (!CI || !this->isValue(CI->getValue())) return false; } return true; The difference is that this matcher can handle weird types (and undef elts): define <3 x i30> @test_weird_vec_type_nonsplat_pow2(<3 x i30> %a0) { %1 = urem <3 x i30> %a0, <i30 1, i30 2, i30 8> ret <3 x i30> %1 } Side note: I copied that loop from a chunk of InstCombineCompares.cpp, and it's not the first time. We should make that available from one place, so we don't keep copying code. |