[llvm-commits] [llvm] r117558 - in /llvm/trunk: lib/CodeGen/SelectionDAG/DAGCombiner.cpp test/CodeGen/ARM/vmla.ll

Chris Lattner clattner at apple.com
Sun Oct 31 10:46:54 PDT 2010

On Oct 28, 2010, at 11:29 AM, Bob Wilson wrote:

> Instcombine tries to fold two shuffles, but it is very conservative -- it requires the folded shuffle mask to be identical to either one of the original masks. From the comment in InstCombiner::visitShuffleVectorInst:
>  // we are absolutely afraid of producing a shuffle mask not in the input
>  // program, because the code gen may not be smart enough to turn a merged
>  // shuffle into two specific shuffles: it may produce worse code.  As such,
>  // we only merge two shuffles if the result is one of the two input shuffle
>  // masks.  In this case, merging the shuffles just removes one instruction,
>  // which we know is safe.  This is good for things like turning:
>  // (splat(splat)) -> splat.
> This is failing to catch the case I was trying to fix because one of the masks is mostly undef values.  The folded mask is [ 1, 1, 1, 1] but the original masks are [ 0, 0, 0, 0 ] and [ 1, u, u, u ].  They don't match so instcombine doesn't combine them.  I suppose we could make instcombine ignore undef values when comparing the masks, but that could produce new shuffles that lead to bad code.  If you want to handle this in instcombine, how about treating splats as a special case, i.e., fold the shuffles if the new mask is a splat OR if it matches one of the original shuffles?

I know it's too late, but I think that explicitly allowing splats in instcombine is the right thing to do.


More information about the llvm-commits mailing list