https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128794

Luis Silva <luismgsilva at outlook dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |luismgsilva at outlook dot com

--- Comment #5 from Luis Silva <luismgsilva at outlook dot com> ---
(In reply to Roger Sayle from comment #3)
> Created attachment 66210 [details]
> proposed patch
> 
> So looking a little deeper into this issue reveals that it's actually a
> missed optimization opportunity.  Notice that the new code for ubar is:
> 
>         mpy.f   r0,r0,r1
>         mov_s   r2,5    ;3
>         j_s.d   [blink]
>         mov.eq  r0,r2
> 
> when (with this patch) it could be:
> 
>         mpy.f   r0,r0,r1
>         j_s.d   [blink]
>         mov.eq  r0,5
> 
> The hold-up is that in combine we see, but fail to recognize:
> 
> (set (reg/v:SI 152 [ <retval> ])
>     (if_then_else:SI (ne (reg:CC_ZN 61 cc)
>             (const_int 0 [0]))
>         (reg/v:SI 152 [ <retval> ])
>         (const_int 5 [0x5])))
> 
> The recent patch to *movsicc_insn allowed it to invert the condition, to
> swap the true and false branches if they are both registers.  Alas, this
> helps (eliminates a mov instruction) when we have two registers, but doesn't
> help when the problematic operand is an immediate constant.
> 
> This patch adds a second define_insn to specifically handle the case that the
> else operand of a movsicc_insn is a constant.  As shown in the regressed
> test case, this allows us to reduce the number of instructions.
> 
> If someone can (please) confirm that this is OK on real hardware, the
> regression  status of this PR should allow us to get this optimization into
> GCC 17.

Yes, this is OK on real hardware, but we found 2 regressions:

a) gcc.target/arc/shldi-1.c produces worse code now. Combine merges the
   cmov into the hard register copy to r0, which adds an extra mov_s, so
   the test's scans fail.

b) ICE with -fpic. The pattern doesn't handle ARC_UNSPEC_GOTOFFPC addresses
   (Cal rejects them and there is no register alternative). Reproducer:

     /* -O2 -fpic */
     static int x;
     int *f (int *p, int c) { return c ? p : &x; }

   This also breaks the arc*-linux libgcc build (fp-bit.c/dp-bit.c).

Reply via email to