[PATCH] D15250: Detecte vector reduction operations just before instruction selection.

Cong Hou via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 10 16:18:16 PST 2015


congh added inline comments.

================
Comment at: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:2410
@@ +2409,3 @@
+          return false;
+      } else if (isa<ExtractElementInst>(U)) {
+        // At this moment we should have reduced all elements in the vector.
----------------
hfinkel wrote:
> congh wrote:
> > hfinkel wrote:
> > > We should also catch the way that this is often programmed "by hand":
> > > 
> > >   typedef float v4f __attribute__((vector_size(16)));
> > >   v4f foo(void);
> > >   float bar() {
> > >     v4f phi = { 0, 0, 0, 0 };
> > >     for (int i = 0; i < 1600; ++i)
> > >       phi += foo();
> > > 
> > >     return phi[0] + phi[1] + phi[2] + phi[3];
> > >   }
> > > 
> > > thus, we have multiple extracts instead of shuffles. One might argue that we should canonicalize this to the shuffle form, but we don't have anything that does this currently (AFAIK). What do you think?
> > > 
> > OK, as long as this pattern often appears. After all, programs made by hand can have many different forms. For example, we can use target specific intrinsics (like movehl or hadd on X86) in the final reduction. As we don't have canonicalization now, I agree that we should make this function open to support more patterns.
> Thinking about it, I think it is better to canonicalize these in instcombine. The shuffle form will use fewer instructions in all cases (except the two-element case). Don't bother matching it here, we should add canonicalization to instcombine in a separate patch.
> 
> FWIW, however, yes, I've seen code like this from several users at our facility.
> 
I agree. Then I will not modify this part now.


http://reviews.llvm.org/D15250





More information about the llvm-commits mailing list