[PATCH] D42818: [InstCombine][ValueTracking] Match non-uniform constant power-of-two vectors
Sanjay Patel via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 6 07:08:00 PST 2018
spatel added inline comments.
================
Comment at: include/llvm/IR/PatternMatch.h:296
return this->isValue(CI->getValue());
+ if (const auto *CDV = dyn_cast<ConstantDataVector>(V)) {
+ unsigned E = CDV->getNumElements();
----------------
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.
Repository:
rL LLVM
https://reviews.llvm.org/D42818
More information about the llvm-commits
mailing list