> I was looking at the code in more detail and just wanted to check.
> We have:
> 
>   int last_needs_comparison = -1;
> 
>   bool ok = noce_convert_multiple_sets_1
>     (if_info, &need_no_cmov, &rewired_src, &targets, &temporaries,
>      &unmodified_insns, &last_needs_comparison);
>   if (!ok)
>       return false;
> 
>   /* If there are insns that overwrite part of the initial
>      comparison, we can still omit creating temporaries for
>      the last of them.
>      As the second try will always create a less expensive,
>      valid sequence, we do not need to compare and can discard
>      the first one.  */
>   if (last_needs_comparison != -1)
>     {
>       end_sequence ();
>       start_sequence ();
>       ok = noce_convert_multiple_sets_1
>       (if_info, &need_no_cmov, &rewired_src, &targets, &temporaries,
>        &unmodified_insns, &last_needs_comparison);
>       /* Actually we should not fail anymore if we reached here,
>        but better still check.  */
>       if (!ok)
>         return false;
>     }
> 
> But noce_convert_multiple_sets_1 ends with:
> 
>   /* Even if we did not actually need the comparison, we want to make sure
>      to try a second time in order to get rid of the temporaries.  */
>   if (*last_needs_comparison == -1)
>     *last_needs_comparison = 0;
> 
> 
>   return true;
> 
> AFAICT that means that the first attempt is always redundant.
> 
> Have I missed something?

(I might not have fully gotten the question)

The idea is that the first attempt goes through all insns and sets
*last_need_comparison to the insn number that either
- used the condition/comparison by preferring seq1 or
- used the condition as a side-effect insn when creating a CC-using
  insn in seq2.
(And we only know that after actually creating the sequences). 

The second attempt then improves on the first one by skipping
any temporary destination registers after the last insn that required
the condition (even though its target overlaps with the condition
registers).  This is true for all cmovs that only use the CC
(instead of the condition).  Essentially, we know that all following
cmovs can be created via the CC which is not overwritten.

So, even when we never used the condition because of all CC-using
cmovs we would skip the temporary targets in the second attempt.
But we can't know that all we ever needed is the CC comparison
before actually creating the sequences in the first attempt.

Regards
 Robin

Reply via email to