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

Bob Wilson bob.wilson at apple.com
Thu Oct 28 11:29:38 PDT 2010


On Oct 28, 2010, at 10:09 AM, Chris Lattner wrote:

> 
> On Oct 28, 2010, at 10:06 AM, Bob Wilson wrote:
> 
>> Author: bwilson
>> Date: Thu Oct 28 12:06:14 2010
>> New Revision: 117558
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=117558&view=rev
>> Log:
>> Teach the DAG combiner to fold a splat of a splat.  Radar 8597790.
>> Also do some minor refactoring to reduce indentation.
> 
> Hi Bob, isn't this something that instcombine can do?

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?



More information about the llvm-commits mailing list