At the very end of instruction selection, in InstrEmitter,handle
overlapping register classes to eliminate redundant copy instructions.
Also, update various tests.
Given the following code:
a = def c = CopyToReg a
The current implementation of InstrEmitter checks whether a and`c`
belong to the same register class, and, if so, coalesces CopyToReg away:
a = def c = CopyToReg a => c = def
In pseudocode, the algorithm can be expressed as
if RegClass(c) == RegClass(a): make it "c = def"
However, in a case where register classes are not exactly equal
but overlap, the CopyToReg is not eliminated. This patch checks
whether two register classes overlap and the number of registers
in the overlap is greater than MinRCSize. In pseudocode:
if |RegClass(c) ∩ RegClass(a)| ≥ MinRCSize: make it "c = def"
Corresponding discussion on llvm-dev:
http://lists.llvm.org/pipermail/llvm-dev/2018-May/123663.html
https://groups.google.com/forum/#!topic/llvm-dev/BHFhRkYY2ng
Patch by Ulrich Weigand.