This is an archive of the discontinued LLVM Phabricator instance.

[mips][ias] Check '$rs = $rd' constraints when both registers are in AsmText.
ClosedPublic

Authored by dsanders on Jul 5 2016, 7:42 AM.

Details

Summary

This is one possible solution to the problem of ignoring constraints that Simon
raised in D21473 but it's a bit of a hack.

The integrated assembler currently ignores violations of the tied register
constraints when the operands involved in a tie are both present in the AsmText.
For example, 'dati $rs, $rt, $imm' with the '$rs = $rt' will silently replace
$rt with $rs. So 'dati $2, $3, 1' is processed as if the user provided
'dati $2, $2, 1' without any diagnostic being emitted.

This is difficult to solve properly because there are multiple parts of the
matcher that are silently forcing these constraints to be met. Tied operands are
rendered to instructions by cloning previously rendered operands but this is
unnecessary because the matcher was already instructed to render the operand it
would have cloned. This is also unnecessary because earlier code has already
replaced the MCParsedOperand with the one it was tied to (so the parsed input
is matched as if it were 'dati <RegIdx 2>, <RegIdx 2>, <Imm 1>'). As a result,
it looks like fixing this properly amounts to a rewrite of the tied operand
handling which affects all targets.

This patch however, merely inserts a checking hook just before the
substitution of MCParsedOperands and the Mips target overrides it. It's not
possible to accurately check the registers are the same this early (because
numeric registers haven't been bound to a register class yet) so it cheats a
bit and checks that the tokens that produced the operand are lexically
identical. This works because tied registers need to have the same register
class but it does have a flaw. It will reject 'dati $4, $a0, 1' for violating
the constraint even though $a0 ends up as the same register as $4.

Diff Detail

Event Timeline

dsanders updated this revision to Diff 62751.Jul 5 2016, 7:42 AM
dsanders retitled this revision from to [mips][ias] Check '$rs = $rd' constraints when both registers are in AsmText..
dsanders updated this object.
dsanders added a reviewer: sdardis.
dsanders added a subscriber: llvm-commits.
sdardis accepted this revision.Jul 22 2016, 2:53 AM
sdardis edited edge metadata.

LGTM with the two nits addressed (inlined).

lib/Target/Mips/AsmParser/MipsAsmParser.cpp
1468

GCC 4.9.2 is reporting: control reaches end of non-void function [-Wreturn-type] here.

3720

GCC is reporting: enumeral mismatch in conditional expression: 'llvm::MCTargetAsmParser::MatchResultTy' vs '{anonymous::MipsParser::MipsMatchResultTy' here.

This revision is now accepted and ready to land.Jul 22 2016, 2:53 AM
dsanders closed this revision.Jul 27 2016, 6:57 AM
dsanders marked an inline comment as done.Jul 27 2016, 7:00 AM
dsanders added inline comments.
lib/Target/Mips/AsmParser/MipsAsmParser.cpp
3720

I couldn't reproduce this one despite using the same compiler (gcc 4.9.2). I've committed without changing this bit but I'll see if any of the buildbots report it. Is that ok?

sdardis added inline comments.Jul 27 2016, 7:02 AM
lib/Target/Mips/AsmParser/MipsAsmParser.cpp
3720

Yeah, that's fine.