This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: patches to reorg.c for c4x
- To: Herman ten Brugge <Haj dot Ten dot Brugge at net dot HCC dot nl>
- Subject: Re: patches to reorg.c for c4x
- From: Jeffrey A Law <law at cygnus dot com>
- Date: Tue, 13 Oct 1998 10:58:56 -0600
- Cc: egcs-patches at cygnus dot com
- Reply-To: law at cygnus dot com
In message <199810122150.WAA23753@htbrug.net.HCC.nl>you write:
> Hello Jeff,
>
> Some more notes to message <199810051656.RAA01005@htbrug.net.HCC.nl>.
Thanks. I'd been meaning to get back to your message about the sparc and
find out exactly how we're getting cmp insns in the delay slots of conditional
branches.
> The patch before the main for loop checks if there is a conditional
> instruction in the sequence we want to steal from. This can only happen
> when the jump is an unconditional jump when we have only one delay slot.
I'm sorry, I've lost context. Which "main loop"?
fill_slots_from_thread can be called to fill delay slots for both conditional
and unconditional jumps. I believe it can call steal_delay_list_from_target
in both of those cases (it can also call steal_delay_list_from_fallthrough
when trying to fill the delay slot for a conditional branch).
I do see how we can get insns which set conditional codes into delay slots now;
they can easily come from the target/fallthrough paths for machines which
do not define HAVE_cc0. Stupidity leak on my part to not realize this.
They can also come from paths before the branch -- consider a machine that
has multiple condition code registers (call them cc1 & cc2). An insn that
sets cc1 can be pushed down into a delay slot of a branch that tests cc2.
Note that this is entirely controlled via data dependency.
> BccD label
> <empty> - delay list
>
> BccD label1 \ seq
> insn that sets cc /
>
> The sequence above can never happen when we have one delay slot because
> the '<empty>' delay list should be the compare instruction for the second
> conditional branch. Just to be sure I verified that on the sparc only
> unconditional jumps are in seq when the main loop is enterred.
Not necessarily. Consider if they both used the same compare, but just checked
different bits in the resulting condition code. On machines which do not use
cc0, the comparison itself is subject to all the traditional optimizations,
including common subexpression elimination. So initially we could have:
compare #1
BccD target1
<empty>
Bcc'D target2
<empty>
compare #2
Both BccD and Bcc'D use compare#1, they just check different conditions.
We may then create this via delay slot filling
compare #1
BccD target1
<empty>
Bcc'D target2
compare #2
But I would expect that the data dependency between Bcc'D and compare #2
would prevent us from trying to move compare #2 into the delay slot of
BccD. That's probably the first thing to make sure we handle correctly.
So, returning to your original problem:
bned label : delayed branch to label when condition is not equal
cmp 1,r0 : 3 delay slots the first one modifies the
<empty> condition codes.
<empty>
label:
bned anotherlabel
cmp r2,r3 : another instruction that modifies the
<empty> condition codes.
<empty>
Shouldn't there be a data dependency that prevents cmp r2,r3 from being moved
up past the second branch? Check that first. This is not a condition code
issue, this is a data dependency issue.
Now if we look at the case where the second jump is unconditional:
bned label : delayed branch to label when condition is not equal
cmp 1,r0 : 3 delay slots the first one modifies the
<empty> condition codes.
<empty>
label:
unconditional branch anotherlabel
cmp r2,r3 : another instruction that modifies the
<empty> condition codes.
<empty>
In this case there is no data dependency between the unconditional branch and
the cmp in its delay slot.
However, I would have expected that we show that the condition code register
is needed in both threads of the first branch, which should inhibit moving
the second compare into the delay slot of the first branch. Again, data
dependencies should be preventing the incorrect transformations.
So, in summary, we need to make sure we're checking the right data dependencies.
The whole condition code issue is red herring. I could just as easily show the
same problems if we were not dealing with condition codes and the solutions to
those should be the same - make sure we're doing proper data dependency checks.
jeff