This is an archive of the discontinued LLVM Phabricator instance.

[InstCombine] PR32078: convert scalar operations to vector.
AbandonedPublic

Authored by ABataev on Apr 14 2017, 11:57 AM.

Details

Summary

If we have a code like:

%xn = extractelement <2 x i32> %x, i32 %n
%yn = extractelement <2 x i32> %y, i32 %n
%cmpn = icmp eq i32 %xn, %yn

we can convert it to something like this:

%cmp = icmp eq <2 x i32> %x, %y
%cmpn = extractelement <2 x i1> %cmp0, i32 %n

Event Timeline

ABataev created this revision.Apr 14 2017, 11:57 AM
spatel requested changes to this revision.Apr 17 2017, 7:51 AM
spatel added a reviewer: efriedma.

This transform is not safe as written. This program compiled with -O1 will crash/cause exception after this patch, but it does not before:

typedef int v4si __attribute__((__vector_size__(16)));

v4si divs(v4si x, v4si y) {
  int eltX = x[1];
  int eltY = y[1];
  x[1] = eltX / eltY;
  return x;
}

int main() {
  v4si x = (v4si){0, 1, 2, 3};
  x = divs(x, x);
  return x[0];
}

The division example shows that we're operating on elements that the original program does not, so any FP op would also be a concern. If some element in a vector is a denorm, that could cause a perf explosion that doesn't exist in the original program. Besides that, I'm not sure that we can actually do this transform for any op in a target-independent pass. We're replacing scalar ops with potentially more expensive vector ops.

This revision now requires changes to proceed.Apr 17 2017, 7:51 AM
ABataev abandoned this revision.May 18 2017, 8:24 AM

Need cost analysis for this kind of transformation, moving it back to SLP vectorizer.