Skip to content

Commit 0850e72

Browse files
authored
[RISCV] Convert C_ADDI_NOP to C_NOP in the assembler. (#112314)
Make it a pseudoinstruction so we can convert it to C_NOP. This makes the printing from the assembler consistent with what we get from llvm-objdump. I tried to do this with an InstAlias, but I don't think it can drop operands.
1 parent 2c8ecb3 commit 0850e72

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3693,6 +3693,9 @@ bool RISCVAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
36933693
switch (Inst.getOpcode()) {
36943694
default:
36953695
break;
3696+
case RISCV::PseudoC_ADDI_NOP:
3697+
emitToStreamer(Out, MCInstBuilder(RISCV::C_NOP));
3698+
return false;
36963699
case RISCV::PseudoLLAImm:
36973700
case RISCV::PseudoLAImm:
36983701
case RISCV::PseudoLI: {

llvm/lib/Target/RISCV/RISCVInstrInfoC.td

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -418,15 +418,11 @@ def C_ADDI : RVInst16CI<0b000, 0b01, (outs GPRNoX0:$rd_wb),
418418
let Inst{6-2} = imm{4-0};
419419
}
420420

421-
let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in
422-
def C_ADDI_NOP : RVInst16CI<0b000, 0b01, (outs GPRX0:$rd_wb),
423-
(ins GPRX0:$rd, immzero:$imm),
424-
"c.addi", "$rd, $imm">,
425-
Sched<[WriteIALU, ReadIALU]> {
426-
let Constraints = "$rd = $rd_wb";
427-
let Inst{6-2} = 0;
428-
let isAsmParserOnly = 1;
429-
}
421+
// Alternate syntax for c.nop. Converted to C_NOP by the assembler.
422+
let hasSideEffects = 0, mayLoad = 0, mayStore = 0, isCodeGenOnly = 0,
423+
isAsmParserOnly = 1 in
424+
def PseudoC_ADDI_NOP : Pseudo<(outs GPRX0:$rd), (ins GPRX0:$rs1, immzero:$imm),
425+
[], "c.addi", "$rd, $imm">;
430426

431427
let hasSideEffects = 0, mayLoad = 0, mayStore = 0, isCall = 1,
432428
DecoderNamespace = "RISCV32Only_", Defs = [X1],

llvm/test/MC/RISCV/rv32c-valid.s

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ c.sub a4, a5
147147
# CHECK-ASM: encoding: [0x01,0x00]
148148
# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions) or 'Zca' (part of the C extension, excluding compressed floating point loads/stores){{$}}
149149
c.nop
150-
# CHECK-ASM: c.addi zero, 0
151-
# CHECK-OBJ: c.nop
150+
# CHECK-ASM-AND-OBJ: c.nop
152151
# CHECK-ASM: encoding: [0x01,0x00]
153152
# CHECK-NO-EXT: error: instruction requires the following: 'C' (Compressed Instructions) or 'Zca' (part of the C extension, excluding compressed floating point loads/stores){{$}}
154153
c.addi x0, 0

0 commit comments

Comments
 (0)