avr-llvm / llvm

[MERGED UPSTREAM] AVR backend for the LLVM compiler library
220 stars 21 forks source link

InstPrinter does not print aliases with duplicate operands #89

Closed dylanmckay closed 6 years ago

dylanmckay commented 9 years ago

The first two instructions, when printed, are not written as tst Rd or clr Rd - they are printed as and Rd, Rd and eor Rd, Rd. The last instruction correctly maps to ser Rd when printed.

The only difference between the two is that ser Rd only has Rd once in the pattern, whereas tst and clr have Rd repeated in the pattern.

It appears that instruction aliases with repeated operands in the patterns do not work correctly with regards to the instruction printer. A brief debugging shows that inside printAliasInstr in AVRGenAsmWriter.inc (generated by TableGen) checks if the MCInst has 2 operands (presumably a brief sanity check), before it checks whether the instruction corresponds to tst or clr - however, the instruction always contains 3 operands - Rd repeated three times, causing the conditional to never be true, and the alias to not be printed.

In utils/TableGen, the CodeGenInstAlias class holds information about an alias - the string pattern, the instruction that is being aliased, and the arguments to the instruction. TableGen isn't adding duplicate operands from the CodeGenInstruction Result into the ResultOperands field in the CodeGenInstAlias if it is a duplicate.

dylanmckay commented 9 years ago

Adding testing flag because we have to write our machine code tests around this bug, and will have to update them all once it is fixed.

dylanmckay commented 9 years ago

This is a bug in LLVM.

In AVRGenAsmWriter.inc, the instruction alias printer does not handle duplicate operands that are constrained to be identical. The symptom of this is that whenever there is an alias of an instruction with a repeated operand, the alias will never be resolved.

dylanmckay commented 9 years ago

Here is my private branch with half a fix.

dylanmckay commented 9 years ago

I have opened up LLVM bug 23925

dylanmckay commented 6 years ago

This seems to be fixed since r318895