-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[RISCV] Handle 'c.addi x0, $imm' alias for c.nop using PseudoC_ADDI_NOP. #150719
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add a missing tied constraint to PseudoC_ADDI_NOP. It seemed better to handle all the c.addi aliases for c.nop in one place.
|
@llvm/pr-subscribers-mc @llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) ChangesAdd a missing tied constraint to PseudoC_ADDI_NOP. It seemed better to handle all the c.addi aliases for c.nop in one place. Full diff: https://github.com/llvm/llvm-project/pull/150719.diff 3 Files Affected:
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index a143d85f61ec2..84ef00781d800 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -3849,9 +3849,14 @@ bool RISCVAsmParser::processInstruction(MCInst &Inst, SMLoc IDLoc,
switch (Inst.getOpcode()) {
default:
break;
- case RISCV::PseudoC_ADDI_NOP:
- emitToStreamer(Out, MCInstBuilder(RISCV::C_NOP));
+ case RISCV::PseudoC_ADDI_NOP: {
+ if (Inst.getOperand(2).getImm() == 0)
+ emitToStreamer(Out, MCInstBuilder(RISCV::C_NOP));
+ else
+ emitToStreamer(Out, MCInstBuilder(RISCV::C_NOP_HINT)
+ .addOperand(Inst.getOperand(2)));
return false;
+ }
case RISCV::PseudoLLAImm:
case RISCV::PseudoLAImm:
case RISCV::PseudoLI: {
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoC.td b/llvm/lib/Target/RISCV/RISCVInstrInfoC.td
index 8252a9b170eb3..8b5e7aa90e6cd 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfoC.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfoC.td
@@ -408,11 +408,13 @@ def C_ADDI : RVInst16CI<0b000, 0b01, (outs GPRNoX0:$rd_wb),
let Constraints = "$rd = $rd_wb";
}
-// Alternate syntax for c.nop. Converted to C_NOP by the assembler.
+// Alternate syntax for c.nop. Converted to C_NOP/C_NOP_HINT by the assembler.
let hasSideEffects = 0, mayLoad = 0, mayStore = 0, isCodeGenOnly = 0,
isAsmParserOnly = 1 in
-def PseudoC_ADDI_NOP : Pseudo<(outs GPRX0:$rd), (ins GPRX0:$rs1, immzero:$imm),
- [], "c.addi", "$rd, $imm">;
+def PseudoC_ADDI_NOP : Pseudo<(outs GPRX0:$rd), (ins GPRX0:$rs1, simm6:$imm),
+ [], "c.addi", "$rd, $imm"> {
+ let Constraints = "$rs1 = $rd";
+}
let hasSideEffects = 0, mayLoad = 0, mayStore = 0, isCall = 1,
DecoderNamespace = "RV32Only", Defs = [X1],
@@ -698,11 +700,6 @@ def C_SRAI64_HINT : RVInst16CB<0b100, 0b01, (outs GPRC:$rd),
// Assembler Pseudo Instructions
//===----------------------------------------------------------------------===//
-let Predicates = [HasStdExtZca] in {
-// Just a different syntax for the c.nop hint: c.addi x0, simm6 vs c.nop simm6.
-def : InstAlias<"c.addi x0, $imm", (C_NOP_HINT simm6nonzero:$imm), 0>;
-}
-
let Predicates = [HasStdExtC, HasStdExtZihintntl] in {
def : InstAlias<"c.ntl.p1", (C_ADD_HINT X0, X2)>;
def : InstAlias<"c.ntl.pall", (C_ADD_HINT X0, X3)>;
diff --git a/llvm/test/MC/RISCV/rvc-hints-invalid.s b/llvm/test/MC/RISCV/rvc-hints-invalid.s
index 2a7a6addd31ab..9af2915af56e5 100644
--- a/llvm/test/MC/RISCV/rvc-hints-invalid.s
+++ b/llvm/test/MC/RISCV/rvc-hints-invalid.s
@@ -5,7 +5,7 @@
c.nop 0 # CHECK: :[[@LINE]]:7: error: immediate must be non-zero in the range [-32, 31]
-c.addi x0, 33 # CHECK: :[[@LINE]]:12: error: immediate must be non-zero in the range [-32, 31]
+c.addi x0, 33 # CHECK: :[[@LINE]]:12: error: immediate must be an integer in the range [-32, 31]
c.li x0, 42 # CHECK: :[[@LINE]]:10: error: immediate must be an integer in the range [-32, 31]
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
lenary
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we do the following, which seems cleaner to me:
- Merge
C_NOPandC_NOP_HINT(toC_NOPthat takes asimm6immediate, and prints asc.nop $imm) - Add an alias
c.nopto(C_NOP 0)which does print - Add aliases for
c.addi x0, $immto(C_NOP $imm)which parse but don't print.
I think this would allow us to get rid of PseudoC_ADDI_NOP and the custom processInstruction code.
I'm overlooking something, maybe?
There's maybe one or two other places in the LLVM codebase which would have to be updated as they use C_NOP right now (without any operands), but I don't think that's a problem.
I don't think the new C_NOP would need to have tied operands, but maybe that's wrong?
-Mno-aliases would disable the printing and emit |
lenary
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see.
LGTM.
|
(I sort of wish the spec didn't say that |
Yeah. binutils does treat it as an alias and I think prints |
…OP. (llvm#150719) Add a missing tied constraint to PseudoC_ADDI_NOP. It seemed better to handle all the c.addi aliases for c.nop in one place.
Add a missing tied constraint to PseudoC_ADDI_NOP.
It seemed better to handle all the c.addi aliases for c.nop in one place.