This is an archive of the discontinued LLVM Phabricator instance.

[TwoAddressInstructionPass] When prepending COPYs when processing tied operands, take the register class constraint from the instruction operands not the register we're copying.
Changes PlannedPublic

Authored by craig.topper on Sep 14 2017, 4:20 PM.

Details

Summary

We're creating a new copy here and I think all that's important is that the result of the copy satisfies the instruction that's using it. The register we're copying from may have been overconstrained by the requirements of other users and we don't need to keep those constraints if we're making a copy.

I observed this when I tried to remove the explicit copies in X86InstrCompiler.td

def : Pat<(i8 (trunc GR32:$src)),
          (EXTRACT_SUBREG (i32 (COPY_TO_REGCLASS GR32:$src, GR32_ABCD)),
                          sub_8bit)>,
      Requires<[Not64BitMode]>;
def : Pat<(i8 (trunc GR16:$src)),
          (EXTRACT_SUBREG (i16 (COPY_TO_REGCLASS GR16:$src, GR16_ABCD)),
                          sub_8bit)>,
      Requires<[Not64BitMode]>;

The EXTRACT_SUBREG handling in InstrEmitter.cpp should make these unnecessary by constraining the register class for the input to COPY that does the extract or emitting a new COPY before the extract. If it uses the constraint, then that constraint can be propagated to the result of a COPY introduced by the two address instruction pass.

Unfortunately, this seems to have broken a PowerPC test because there is a check in the pass to only handle COPY with the same source and dest class and the copy it was finding came from the two address instruction pass.

Diff Detail

Event Timeline

craig.topper created this revision.Sep 14 2017, 4:20 PM
arsenm added inline comments.Sep 14 2017, 4:36 PM
lib/CodeGen/TwoAddressInstructionPass.cpp
1521–1522

Can't this now fail if the instruction uses an unknown register class operand?

craig.topper added inline comments.Sep 14 2017, 5:06 PM
lib/CodeGen/TwoAddressInstructionPass.cpp
1521–1522

Can you give an example? I'm not very familiar with some of this stuff.

arsenm added inline comments.Sep 14 2017, 5:35 PM
lib/CodeGen/TwoAddressInstructionPass.cpp
1521–1522

You can define an instruction operand with an unknown register class, e.g. PATCHPOINT uses this:

let OutOperandList = (outs unknown:$dst);

Similarly variable_ops instructions don't have statically known register classes from the operand definition.

craig.topper added inline comments.Sep 14 2017, 5:37 PM
lib/CodeGen/TwoAddressInstructionPass.cpp
1521–1522

How likely is that to be used on a tied operand?

craig.topper planned changes to this revision.Dec 14 2017, 9:46 AM