We're currently seeing the following warning when building the SystemZ back-end:
warning: SubRegIndex SystemZ::subreg_h64 and SystemZ::subreg_h32 compose ambiguously as SystemZ::subreg_hh32 or SystemZ::subreg_h32
The problem appears to be that the VR128 class only has a high subreg defined (via subreg_h64), and that subreg itself also has a high subreg defined (via subreg_h32). TableGen then creates an automatic composition that allows directly accessing that composition as subreg_h32. However, the back-end also defined a *manual* composition of subreg_h64 and subreg_h32 that is defined as subreg_hh32., which is what causes the ambiguity.
The reason we need the explicit subreg_hh32 is that FP128 and GR128 both have both a low and a high 64-bit subreg (via subreg_l64 and subreg_h64), each of which itself has a high subreg via subreg_h32. Now the automatic TableGen composition here will allow accessing subreg_h32 (subreg_l64) implicitly as subreg_h32, and we need the explicit subreg_hh32 to access subreg_h32 (subreg_h64).
The reason why TableGen creates the implicit subreg_h32 (subreg_l64) but not subreg_h32 (subreg_h64) appears to be simply that in the list of subregs of FP128 and GR128, subreg_l64 is listed first.
This patch therefore removes the warning by simply reversing that order. This means that TableGen now automatically creates subreg_h32 as implicit composition for subreg_h32 (subreg_h64) on *all* register classes, and we create an explicit composition subreg_lh32 to access subreg_h32 (subreg_l64) on those registers that have a subreg_l64.
This causes no change in code generation, but avoids the warning.
We used to have subregs specified from high to low in our OOT target. But nowadays we follow how it seems to be done for all in-tree target and specify them from low to high instead. There are some problems that comes with having them specified from high to low. I think mainly related to debug information.
If you look at SystemZGenRegisterInfo.inc before your patch you get this table with offset/size information:
with this patch you instead get
So both subreg_h32 and subreg_lh32 is basically pointing out bit 32-63 in a register (counting from least significant bit). When doing the subreg composition tablegen actually seems to assume that the subregs are specified from low to high when calculating the offsets.
The SubRegIdxRanges table is for example used (in calls to getSubRegIdxOffset)
by StackMaps::parseOperand and DwarfExpression::addMachineReg when generating DWARF expressions mapping a variable to a register.
If I remember correctly swapping order of subregister indices like this will result in a different order when using MCSubRegIterator. In our case this gave in different results in the last part of DwarfExpression::addMachineReg ("Otherwise, attempt to find a covering set of sub-register numbers").
I got a feeling that you wanted subreg_h32 to also act as the old subreg_hh32. That will often work, but as described above, the debug info would probably get messed up in some situations.
So if you do not care about debug info, maybe this patch is good as-is. If you care about debug info you might need to add some more hacks to work around problems in (at least) DwarfExpression::addMachineReg and StackMaps::parseOperand.
Some alternatives that perhaps can be tried (to avoid the ambiguity warnings) may involve:
Not sure if any of the above really helps.
I guess the last resort would be to accept the solution in D50977.