On Fri, May 29, 2026 at 11:50 AM H.J. Lu <[email protected]> wrote:
>
> On Fri, May 29, 2026 at 10:52 AM Hongtao Liu <[email protected]> wrote:
> >
> > On Thu, May 28, 2026 at 5:59 PM Uros Bizjak <[email protected]> wrote:
> > >
> > > On Thu, May 28, 2026 at 11:48 AM Jakub Jelinek <[email protected]> wrote:
> > > >
> > > > On Thu, May 28, 2026 at 11:31:27AM +0200, Uros Bizjak wrote:
> > > > > Hm, OTOH, is this condition correct:
> > > > >
> > > > >     case TYPE_LEA:
> > > > >       if (TARGET_APX_NDD && <nf_applied>)
> > > > >     return "%{nf%} add{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}";
> > > > >       else
> > > > >     return "#";
> > > > >
> > > > > Should it be "TARGET_APX_NDD || <nf_applied>"?
> > > >
> > > > The pattern is weird, but TARGET_APX_NDD || <nf_applied> would be wrong.
> > > > Without TARGET_APX_NDD there is no 3 operand add, so we can't use that.
> > > > Of course, question is if there will be CPUs with just APX-NF and not
> > > > APX-NDD or with just APX-NDD and not APX-NF.
> > > >
> > > > I'd say it is a bad idea to have the "lea" variant come before the
> > > > 3 apx_ndd variants, if the lea variant came last, then at least the r 
> > > > <- r, l
> > > > case would be covered for TARGET_APX_NDD by the earlier (but now later)
> > > > r <- rje, r variant and could then emit either the 3 operand add or 3
> > > > operand add with {nf}.  Anyway, with the current position it could also 
> > > > be
> > > >   if (TARGET_APX_NDD)
> > > >     return "<nf_prefix>add{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}";
> > > >   else
> > > >     {
> > > >       operands[3] = gen_rtx_PLUS (<MODE>mode, operands[1], operands[2]);
> > > >       return "lea{<imodesuffix>}\t{%E3, %0|%0, %E3}";
> > > >     }
> > >
> > > I think that the correct solution is to put LEA at the end. LEA
> > > alternative is intended for non-NDD cases to allow two-register
> > > operation, but NDD should override it, w/ or w/o NF. Let's ask
> > > Hongtao.
> > LEA and NF ADD sometimes have the same rtx pattern, we put the LEA
> > pattern first so that NF ADD rtx pattern can be recognized as LEA when
> > possible. Both have similar performance, but LEA uses less encoding
> > space (especially without EGPR - legacy LEA is smaller than NF ADD).
> > Similar reasons, we want NDD ADD to be splitted back to LEA.
> >
>
> We can add ix86_output_lea to generate the shortest encoding.
>

Something like this


diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 9b64843cec8..a013f7df048 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -6749,7 +6749,13 @@ (define_insn "*add<mode>_1<nf_name>"
   switch (get_attr_type (insn))
     {
     case TYPE_LEA:
-      if (TARGET_APX_NDD && <nf_applied>)
+      if (TARGET_APX_NDD
+          && <nf_applied>
+          && (REGNO (operands[2]) == SP_REG
+              || REX2_INT_REG_P (operands[0])
+              || REX2_INT_REG_P (operands[1])
+              || REX2_INT_REG_P (operands[2])
+              || REX2_INT_REG_P (operands[3])))
   return "%{nf%} add{<imodesuffix>}\t{%2, %1, %0|%0, %1, %2}";
       else
   {


-- 
H.J.

Reply via email to