[PATCH][CostModel][X86] Improved cost model for alternate shuffles.

Andrea Di Biagio andrea.dibiagio at gmail.com
Thu Jul 3 15:34:24 PDT 2014


Thanks Nadav.

Committed revision 212296.

-Andrea

On Thu, Jul 3, 2014 at 11:00 PM, Nadav Rotem <nrotem at apple.com> wrote:
> I did not review the cost model change carefully but overall LGTM.
>
>
>> On Jul 2, 2014, at 12:16 PM, Andrea Di Biagio <andrea.dibiagio at gmail.com> wrote:
>>
>> Hi
>>
>> This patch:
>> 1) Improves the cost model for x86 alternate shuffles (originally
>> added at revision 211339);
>> 2) Teaches the Cost Model Analysis pass how to analyze alternate shuffles.
>>
>> Alternate shuffles are a special kind of blend operation; on x86,
>> those shuffles are often easily lowered into a single blend
>> instruction (depending on the subtarget features).
>> For example, SSE4.1 introduces 'blendps/d' that can be used to model
>> such alternate shuffles. So, the cost for alternate shuffles would be
>> just 1 if the subtarget has SSE4.1.
>>
>> I decided to rework the x86 cost model for alternate shuffles to match
>> the correct backend behavior when lowering shuffles.
>> The first thing I noticed is that the existing cost model didn't take
>> into account subtarget features. Second (this is a minor point
>> though), the existing model had a couple of "dead" entries for vector
>> types that are never legal on x86 (example: v2i32 and v2f32 are always
>> either promoted or widened to 128-bit vector types).
>>
>> The new x86 cost model takes into account what target features we have
>> before returning the shuffle cost (i.e. the number of instructions
>> after the blend is lowered/expanded).
>>
>> I also updated CostModel.cpp.
>> Revision 211339 added support for a new shuffle kind called
>> 'SK_Alternate'. However, it didn't update the cost model analysis; so,
>> currently the cost model analysis doesn't know how to analyze
>> alternate shuffles (it returns a cost of -1 for alternate shuffles).
>> This patch teaches the Cost Model Analysis how to identify and analyze
>> alternate shuffles:
>> - added function 'isAlternateVectorMask';
>> - added some logic to check if an instruction is a alternate shuffle
>> and in case, call the target specific TTI to get the corresponding
>> shuffle cost;
>> - added a test to verify the cost model analysis on alternate shuffles.
>>
>> Please let me know if ok to submit.
>>
>> Thanks,
>> Andrea
>> <patch-alternate-shuffle-cost-model.diff>
>



More information about the llvm-commits mailing list