在 2026/6/22 17:41, Hongtao Liu 写道:
> On Mon, Jun 22, 2026 at 4:52 PM Richard Biener
> <[email protected]> wrote:
>>
>> On Mon, Jun 22, 2026 at 5:04 AM Kewen Lin <[email protected]> wrote:
>>>
>>> Hi,
>>>
>>> 在 2026/6/18 20:36, Richard Biener 写道:
>>>> On Thu, Jun 18, 2026 at 2:13 PM Kewen Lin <[email protected]> wrote:
>>> snip...>>>> Do you suggest something like:
>>>>>
>>>>> diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
>>>>> index b1fd86c2b32..964c4bdef90 100644
>>>>> --- a/gcc/config/i386/i386.cc
>>>>> +++ b/gcc/config/i386/i386.cc
>>>>> @@ -26510,8 +26510,15 @@ ix86_vector_costs::add_stmt_cost (int count, 
>>>>> vect_cost_for_stmt kind,
>>>>>            break;
>>>>>
>>>>>          default:
>>>>> -          if (truth_value_p (subcode))
>>>>> +          if (TREE_CODE_CLASS (subcode) == tcc_comparison)
>>>>>              {
>>>>> +              tree op_type = vect_comparison_type (stmt_info);
>>>>> +              if (VECTOR_TYPE_P (vectype))
>>>>> +                op_type
>>>>> +                  = get_related_vectype_for_scalar_type 
>>>>> (m_vinfo->vector_mode,
>>>>> +                                                         op_type);
>>>>> +              mode = TYPE_MODE (op_type);
>>>>
>>>> More like
>>>>
>>>>               if (kind == vector_stmt)
>>>>                 op_type = SLP_TREE_VECTYPE (SLP_TREE_CHILDREN (node)[0]);
>>>>               else
>>>>                 op_type = vect_comparison_type (stmt_info);
>>>>               mode = TYPE_MODE (op_type);
>>>>
>>>
>>> Got it, thanks Richi!  As suggested, patch v2 is as below.
>>>
>>> -----
>>>
>>> This patch is authored-by: Zhongjie Guo <[email protected]>
>>>
>>> AVX512 vector comparisons produce mask results, but the instructions
>>> operate on vector operands.  The instruction cost should therefore be
>>> based on the operand vector mode rather than the mask result mode.
>>>
>>> The mismatch is especially visible on AVX512 split-regs targets, where
>>> ix86_vec_cost scales 512-bit vector operations.  Using the mask result
>>> type misses that scaling and can make 512-bit vectorization look too
>>> cheap.
>>>
>>> As Richi suggested, this can be extended to cover scalar as well.
>>> So this patch is to obtain the mode of comparison operand first, then
>>> continue with the existing comparison cost logic.  It also adjusts
>>> truth_value_p with tcc_comparison check.
>>>
>>> Bootstrapped and regtested on a hygon c86-4g-m7 machine.
>>>
>>> Is it ok for trunk?
>>
>> LGTM, please give target maintainers the chance to chime in though.
> Also LGTM.

Thanks Hongtao & Richi, pushed as r17-1744-g46dacd6b7581c9.

BR,
Kewen

Reply via email to