This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Remove incorrect use of COPY_TO_REGCLASS in fast isel
ClosedPublic

Authored by uweigand on Mar 30 2016, 8:53 AM.

Details

Summary

The fast isel pass currently emits a COPY_TO_REGCLASS node to convert from a F4RC to a F8RC register class during conversion of a floating-point number to integer. There is actually no support in the common code instruction printers to emit COPY_TO_REGCLASS nodes, so the PowerPC back-end has special code there to simply ignore COPY_TO_REGCLASS.

This is correct *if and only if* the source and destination registers of COPY_TO_REGCLASS are the same (except for the different register class). But nothing guarantees this to be the case, and if the register allocator does end up allocating source and destination to different registers after all, the back-end simply generates incorrect code. I've included a test case that shows such incorrect code generation.

However, it seems that COPY_TO_REGCLASS is actually not intended to be used at the MI layer at all. It is used during SelectionDAG, but always lowered to a plain COPY before emitting MI. Other back-end's fast isel passes never emit COPY_TO_REGCLASS at all. I suspect it is simply wrong for the PowerPC back-end to emit it here.

This patch changes the PowerPC back-end to directly emit COPY instead of COPY_TO_REGCLASS and removes the special handling in the instruction printers. This makes the test case work, and shows no regressions in either test suite. While there is a comment in the code that just using COPY isn't supposed to work, I wasn't able to find any actual problem with using COPY ...

Diff Detail

Repository
rL LLVM

Event Timeline

uweigand updated this revision to Diff 52071.Mar 30 2016, 8:53 AM
uweigand retitled this revision from to [PowerPC] Remove incorrect use of COPY_TO_REGCLASS in fast isel.
uweigand updated this object.
uweigand added reviewers: kbarton, hfinkel, wschmidt.
uweigand added a subscriber: llvm-commits.
wschmidt accepted this revision.Mar 30 2016, 9:02 AM
wschmidt edited edge metadata.

This patch LGTM. I was responsible for the original code here. Whatever problem I thought I was solving here appears to no longer be an issue, so let's go forward with this.

This revision is now accepted and ready to land.Mar 30 2016, 9:02 AM
This revision was automatically updated to reflect the committed changes.