[PATCH] D42132: [RISCV] Fixed setting predicates for compressed instructions.

Ana Pazos via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 16 14:07:55 PST 2018


apazos added a comment.

Fixed setting target features.

Before we had:
let Predicates = [A] in {
def Inst : xxx, Requires[B];
}
This is not setting Predicates to A, B. It just takes A.

For example, c.addw should depend on C extension and 64bit support, but look at  AsmMatcherEmitter auto generated header:
{ 1014 /* c.addw */, RISCV::C_ADDW, Convert__Reg1_0__Tie0__Reg1_1, Feature_HasStdExtC, { MCK_GPRC, MCK_GPRC }, },

You can also see the problem here: 
echo 'c.addw x8, x9' |llvm-mc -triple=riscv64 -mattr=+c -show-encoding

  c.addw  s0, s1                  # encoding: [0x25,0x9c]

echo 'c.addw x8, x9' |llvm-mc -triple=riscv32 -mattr=+c -show-encoding

  c.addw  s0, s1                  # encoding: [0x25,0x9c]  --> should have failed.

There are different ways to fix it.
To avoid moving instructions around I just opted to redefining Predicates: 
let Predicates = [A, B] in {
def Inst : xxx;
}

Now the auto-generated code looks correct:
 { 1014 /* c.addw */, RISCV::C_ADDW, Convert__Reg1_0__Tie0__Reg1_1, Feature_HasStdExtC|Feature_IsRV64, { MCK_GPRC, MCK_GPRC }, },


https://reviews.llvm.org/D42132





More information about the llvm-commits mailing list