On 08/22/2017 06:48 AM, Wilco Dijkstra wrote:
Hi,
The register allocator inserts move preferences when an instruction has
one or more dead sources in add_insn_allocno_copies. If an instruction
doesn't have a matching constraint (eg. "0"), then any dead source is treated
as a copy with all destination registers with a low priority. In reality what
appears to happen is that the first dead source is treated as a copy. This
leads to non-intuitive allocations in eg. 4-register FMAs. Here you'd
prefer to have the accumulator and destination to use the same register
when possible: so fmadd d2, d0, d5, d2 instead of fmadd d0, d0, d5, d2.
Would it be reasonable to add an explicit move preference feature?
For example use "r#0" to indicate in ira_get_dup_out_num that an operand
prefers to be the same as the destination if possible. This would use a lower
move priority than "0" to avoid constraining the allocation but a bit higher
than
a simple dead source (eg. freq / 4 or freq / 2).
Wilco, sorry for a delay with the answer. I needed some time to think
about it.
Thank you for writing about the problem.
As I correctly understand, you just want an intuitive allocation. The
current allocation performance has the same quality as the intuitive one.
In this case it would be hard for me to approve such change because it
gives no performance improvement but complicates machine description
definition which is already too complicated.
I think if it is important for some cases may be it is possible to find
an alternative solution without introducing a new hint. Segher proposed
some solutions. They might work. If they don't work we could try to
change heuristics in LRA, for example, to favor copy destination with
the first operand to improve some regularity for human eyes.