This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine][ValueTracking] Match non-uniform constant power-of-two vectors
ClosedPublic

Authored by RKSimon on Feb 1 2018, 2:25 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

RKSimon created this revision.Feb 1 2018, 2:25 PM
spatel added inline comments.Feb 6 2018, 7:07 AM
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.

RKSimon updated this revision to Diff 133016.Feb 6 2018, 8:25 AM

Updated based on @spatel 's feedback

spatel accepted this revision.Feb 6 2018, 9:56 AM

LGTM.

This revision is now accepted and ready to land.Feb 6 2018, 9:56 AM
This revision was automatically updated to reflect the committed changes.