>> But combine doesn't run at -O0.  So something is 
inconsistent.  I >> certainly believe we need to avoid the 
mem->mem case, but that's >> independent of combine and affects all 
optimization levels.  > This is an new bug when running all tests after 
fixing the combine bug. > I understand that maybe I should send a separate 
patch to fix the problem. > Maybe this problem was exposed after I changed 
the pattern. I will continue to track it.
Just now, I debug and found that the -O0 problem
after repairing error combine was caused by the condition
of pred_mov becoming more strict. Before was
(MEM_P (operands[0]) || MEM_P (operands[3])  || CONST_VECTOR_P 
(operands[1])
That is, mem->mem is allowed. This faulty condition causes
two problems at once. One is error combine, the other is to hide
the error pattern with -O0. After correcting the condition with this patch,
I fixed the error combine problem, and also exposed the problem under -O0.
So I think force_reg still needs to be put together with this patch.



------------------ Original ------------------
From:                                                                           
                                             "Lehua Ding"                       
                                                             
<lehua.d...@rivai.ai&gt;;
Date:&nbsp;Sat, Aug 12, 2023 00:30 AM
To:&nbsp;"Jeff 
Law"<jeffreya...@gmail.com&gt;;"gcc-patches"<gcc-patches@gcc.gnu.org&gt;;
Cc:&nbsp;"juzhe.zhong"<juzhe.zh...@rivai.ai&gt;;"rdapp.gcc"<rdapp....@gmail.com&gt;;"kito.cheng"<kito.ch...@gmail.com&gt;;"palmer"<pal...@rivosinc.com&gt;;
Subject:&nbsp;Re: [PATCH] RISC-V: Fix error combine of pred_mov pattern



&amp;gt; But combine doesn't run at -O0.&amp;nbsp; So something is 
inconsistent.&amp;nbsp; I
&amp;gt; certainly believe we need to avoid the mem-&amp;gt;mem case, but that's
&amp;gt; independent of combine and affects all optimization levels.


This is an new bug when running all tests after fixing the combine bug.
I understand that maybe I should send a separate patch to fix the problem.
Maybe this problem was exposed after I changed the pattern. I will continue to 
track it.


&amp;gt; I think we can simplify to just
&amp;gt; !(MEM_P (operands[0]) &amp;amp;&amp;amp; MEM_P (operands[1])


&amp;gt; I would have expected those to be handled by the constraints rather 
than
&amp;gt; the pattern's condition.
Yeh, the condition of the V2 becomes much simpler after split.







------------------&amp;nbsp;Original&amp;nbsp;------------------
From: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p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
 <gcc-patches@gcc.gnu.org&amp;gt;;
Date:&amp;nbsp;Fri, Aug 11, 2023 11:57 PM
To:&amp;nbsp;"Lehua 
Ding"<lehua.d...@rivai.ai&amp;gt;;"gcc-patches"<gcc-patches@gcc.gnu.org&amp;gt;;
Cc:&amp;nbsp;"juzhe.zhong"<juzhe.zh...@rivai.ai&amp;gt;;"rdapp.gcc"<rdapp....@gmail.com&amp;gt;;"kito.cheng"<kito.ch...@gmail.com&amp;gt;;"palmer"<pal...@rivosinc.com&amp;gt;;
Subject:&amp;nbsp;Re: [PATCH] RISC-V: Fix error combine of pred_mov pattern



On 8/8/23 21:54, Lehua Ding wrote:
&amp;gt; Hi Jeff,
&amp;gt; 
&amp;gt;&amp;nbsp; &amp;gt; The pattern's operand 0 explicitly allows MEMs as 
do the constraints.
&amp;gt;&amp;nbsp; &amp;gt;&amp;nbsp;So forcing the operand into a register 
just seems like it's papering
&amp;gt;&amp;nbsp; &amp;gt;&amp;nbsp;over the real problem.
&amp;gt; 
&amp;gt; The added of force_reg code is address the problem preduced after 
&amp;gt; address the error combine.
&amp;gt; The more restrict condtion of the pattern forbidden mem-&amp;gt;mem 
pattern 
&amp;gt; which will
&amp;gt; produced in -O0. I think the implementation forgot to do this 
force_reg 
&amp;gt; operation before
&amp;gt; when doing the intrinis expansion The reason this problem isn't 
exposed 
&amp;gt; before is because
&amp;gt; the reload pass will converts mem-&amp;gt;mem to mem-&amp;gt;reg; 
reg-&amp;gt;mem based on 
&amp;gt; the constraint.
So if the core issue if mem-&amp;gt;mem, that is a common thing to avoid.

Basically in the expander you use a force_reg and then have a test like
!(MEM_P (op0) &amp;amp;&amp;amp; MEM_P (op1)) in the define_insn's condition.

But the v1 had a much more complex condition.&amp;nbsp; It looks like that got 
cleaned up in the v2.&amp;nbsp; So I'll need to look at that one more closely.


&amp;gt; 
&amp;gt;&amp;nbsp; &amp;gt; This comment doesn't make sense in conjuction with 
your earlier details.
&amp;gt;&amp;nbsp; &amp;gt; In particular combine doesn't run at -O0, so your 
earlier comment that
&amp;gt;&amp;nbsp; &amp;gt; combine creates the problem seems inconsistent with 
the comment above.
&amp;gt; 
&amp;gt; As the above says, the code addresses the problem which produced
&amp;gt; after addressing the combine problem.
But combine doesn't run at -O0.&amp;nbsp; So something is 
inconsistent.&amp;nbsp; I 
certainly believe we need to avoid the mem-&amp;gt;mem case, but that's 
independent of combine and affects all optimization levels.


&amp;gt; 
&amp;gt;&amp;nbsp; &amp;gt; Umm, wow.&amp;nbsp; I haven't thought deeply about 
this, but the complexity of
&amp;gt;&amp;nbsp; &amp;gt; that insn condition is a huge red flag that our 
operand predicates
&amp;gt;&amp;nbsp; &amp;gt; aren't correct for this pattern.
&amp;gt; 
&amp;gt; This condition is large because the vsetvl info need (compare to 
scalar 
&amp;gt; mov or *mov<mode&amp;gt;_whole pattern),
&amp;gt; but I think this condition is enough clear to understand. Let me 
explain 
&amp;gt; briefly.
&amp;gt; 
&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (register_operand (operands[0], 
<MODE&amp;gt;mode) &amp;amp;&amp;amp; MEM_P (operands[3]))
&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; || (MEM_P (operands[0]) 
&amp;amp;&amp;amp; register_operand(operands[3], <MODE&amp;gt;mode))
&amp;gt; 
&amp;gt; This two conditons mean allow mem-&amp;gt;reg and reg-&amp;gt;mem 
pattern.
I think we can simplify to just

!(MEM_P (operands[0]) &amp;amp;&amp;amp; MEM_P (operands[1])

&amp;gt; 
&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; (register_operand (operands[0], 
<MODE&amp;gt;mode) &amp;amp;&amp;amp; 
&amp;gt; satisfies_constraint_Wc1 (operands[1]))
&amp;gt; 
&amp;gt; This condition mean the mask must be all trues for 
reg-&amp;gt;reg_or_imm 
&amp;gt; pattern since&amp;gt; reg-&amp;gt;reg insn doen't support mask operand.
I would have expected those to be handled by the constraints rather than 
the pattern's condition.

Jeff

Reply via email to