This is an archive of the discontinued LLVM Phabricator instance.

[mips] Support 'z' inline asm constraint
AbandonedPublic

Authored by atanasyan on Feb 23 2018, 8:12 AM.

Details

Reviewers
sdardis
Summary

The 'z' constraint is used to deal with the floating-point condition code register. Using this constraint the following short, although useless piece of code

float a = 1.0, b = 2.0;
int res;
__asm__ __volatile__(
       "c.eq.s %1,%2"
   : "+z" (res) : "f" (a), "f" (a) : );

translated to this series of assembler commands

ctc1    $1, $fcc0
c.eq.s  $f2, $f0
cfc1    $1, $fcc0

So we can read/write the floating-point condition code register from/to a variable.

This patch adds support for the 'z' constraint on LLVM level only. One more fix is required to support the constraint in the Clang.

Diff Detail

Repository
rL LLVM

Event Timeline

atanasyan created this revision.Feb 23 2018, 8:12 AM
sdardis requested changes to this revision.Feb 26 2018, 5:12 AM

Reading and writing to the fcc register set directly is somewhat cumbersome, in that we have to perform mask and shift operations or bit insertions. If that constraint can allocate any fcc register it will probably require some sort of pseudo instruction to generate the correct sequence.

lib/Target/Mips/MipsISelLowering.cpp
3655

Document the constraint in the above comment.

lib/Target/Mips/MipsSEInstrInfo.cpp
106–107

This is insufficient to read a particular fcc register. cfc1 and ctc1 operate on the float point control registers, not the fcc register set. The $fcsr register or the $fccr register can used to read/write the entire set of $fcc registers (i'd suggest the $fccr / $25). You then have to mask off the non-relevant bits.

Additionally, it may require a pseudo instruction which uses a scratch GPR and is expanded post register allocation to make the correct sequence if any other register that $fcc0 is used.

test/CodeGen/Mips/inlineasm_constraint_z.ll
1

This need -verify-machineinstrs, also use -mtriple=mips-unknown-linux-gnu and use the update_llc_checks script.

This revision now requires changes to proceed.Feb 26 2018, 5:12 AM
atanasyan abandoned this revision.Mar 2 2018, 11:27 AM

I discussed the 'z' constraint with Matthew Fortune and we reached a conclusion that it does not make a sense to support this constraint in LLVM. Probably the 'z' constraint should be marked as "internal" in the gcc code.

Anyway, thanks for review.