On Mon, Mar 15, 2010 at 5:24 AM, Jim Wilson <[email protected]> wrote:
> On 03/10/2010 10:48 PM, fanqifei wrote:
>>
>> For below piece of code, the instruction "clr.w a15" obviously doesn't
>> belong to the inner loop.
>> 6: bd f4 clr.w a15; #clear to zero
>> 8: 80 af 00 std.w a10 0x0 a15;
>
> There is info lacking here. Did you compile with optimization? What does
> the RTL look like before and after the loop opt passes?
>
> I'd guess that your movsi pattern is defined wrong. You probably have
> predicates that allow either registers or constants in the set source, which
> is normal, and constraints that only allow registers when the dest is a mem.
> But constraints are only used by the reload pass, so a store zero to mem
> rtl insn will be generated early, and then fixed late during the reload
> pass. So the loop opt did not move the clear insn out of the loop because
> there was no clear insn at this time.
>
> The way to fix this is to add a condition to the movsi pattern that excludes
> this case. For instance, something like this:
> "(register_operand (operands[0], SImode)
> || register_operand (operands[1], SImode))"
> This will prevent a store zero to mem RTL insn from being accepted. In
> order to make this work, you need to make movsi an expander that accepts
> anything, and then forces the source to a register if you have a store
> constant to memory. See for instance the sparc_expand_move function or the
> mips_legitimize_move function.
>
> Use -da (old) or -fdump-rtl-all (new) to see the RTL dumps to see what is
> going on.
>
> Jim
>
It's compiled with -O2.
You are correct. The reload pass emitted the clr.w insn.
However, I can see loop opt passes after reload:
problem1.c.174r.loop2_invariant1
problem1.c.174r.redo_loop2_invariant
problem1.c.175r.loop2_unswitch
problem1.c.177r.redo_loop2_invariant
After reload pass, the clr.w insn is in the loop. And after above
loop2 passes, the insn is not moved outside of the loop.
I am not sure the issue is in these loop2 passes. I guess there is.
For the definition of movsi expander, I will try to do what you pointed out.
(I am not very familiar with these code and that may take me some time.)
current definition of mov pattern:
(define_insn "mov<mode>"
[(set
(match_operand:BWD 0 "nonimmediate_operand" "=r,m,r,r,r,r,r,r,x,r")
(match_operand:BWD 1 "move_source_operand" "Z,r,L,I,Q,P,ni,x,r,r"))]
""
"@
%L1<m> %0 %1;
%S0<m> %0 %1;
clr<m> %0;
mv %0 %1;
... ...
Thanks!
--
-Qifei Fan
http://freshtime.org