[llvm] [RISCV] Improve assembler error message for Zcmp stack adjustment. (PR #129180)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 27 20:48:40 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
Instead of referring the user to the spec, print the expected range.
---
Full diff: https://github.com/llvm/llvm-project/pull/129180.diff
6 Files Affected:
- (modified) llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp (+20-12)
- (modified) llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h (-14)
- (modified) llvm/test/MC/RISCV/rv32xqccmp-invalid.s (+7-7)
- (modified) llvm/test/MC/RISCV/rv32zcmp-invalid.s (+5-5)
- (modified) llvm/test/MC/RISCV/rv64xqccmp-invalid.s (+7-7)
- (modified) llvm/test/MC/RISCV/rv64zcmp-invalid.s (+5-5)
``````````diff
diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
index 36e2fa0262f9d..85d53f0c5045c 100644
--- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
+++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp
@@ -1684,14 +1684,9 @@ bool RISCVAsmParser::matchAndEmitInstruction(SMLoc IDLoc, unsigned &Opcode,
}
case Match_InvalidStackAdj: {
SMLoc ErrorLoc = ((RISCVOperand &)*Operands[ErrorInfo]).getStartLoc();
- StringRef SpecName = "Zc";
- if (getSTI().hasFeature(RISCV::FeatureVendorXqccmp))
- SpecName = "Xqccmp";
-
- return Error(ErrorLoc,
- Twine("stack adjustment is invalid for this instruction") +
- " and register list; refer to " + SpecName +
- " spec for a detailed range of stack adjustment");
+ return Error(
+ ErrorLoc,
+ "stack adjustment is invalid for this instruction and register list");
}
}
@@ -2771,12 +2766,25 @@ ParseStatus RISCVAsmParser::parseZcmpStackAdj(OperandVector &Operands,
SMLoc S = getLoc();
int64_t StackAdjustment = getLexer().getTok().getIntVal();
- unsigned Spimm = 0;
unsigned RlistVal = static_cast<RISCVOperand *>(Operands[1].get())->Rlist.Val;
- if (Negative != ExpectNegative ||
- !RISCVZC::getSpimm(RlistVal, Spimm, StackAdjustment, isRV64()))
- return ParseStatus::NoMatch;
+ assert(RlistVal != RISCVZC::INVALID_RLIST);
+ unsigned StackAdjBase = RISCVZC::getStackAdjBase(RlistVal, isRV64());
+ if (Negative != ExpectNegative || StackAdjustment % 16 != 0 ||
+ StackAdjustment < StackAdjBase || (StackAdjustment - StackAdjBase) > 48) {
+ int64_t Lower = StackAdjBase;
+ int64_t Upper = StackAdjBase + 48;
+ if (ExpectNegative) {
+ Lower = -Lower;
+ Upper = -Upper;
+ std::swap(Lower, Upper);
+ }
+ return generateImmOutOfRangeError(S, Lower, Upper,
+ "stack adjustment for register list must "
+ "be a multiple of 16 bytes in the range");
+ }
+
+ unsigned Spimm = (StackAdjustment - StackAdjBase) / 16;
Operands.push_back(RISCVOperand::createSpimm(Spimm << 4, S));
getLexer().Lex();
return ParseStatus::Success;
diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
index 433be1f1e87d4..82b562bec9bf6 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVBaseInfo.h
@@ -637,20 +637,6 @@ inline static unsigned getStackAdjBase(unsigned RlistVal, bool IsRV64) {
llvm_unreachable("Unexpected RlistVal");
}
-inline static bool getSpimm(unsigned RlistVal, unsigned &SpimmVal,
- int64_t StackAdjustment, bool IsRV64) {
- if (RlistVal == RLISTENCODE::INVALID_RLIST)
- return false;
- unsigned StackAdjBase = getStackAdjBase(RlistVal, IsRV64);
- StackAdjustment -= StackAdjBase;
- if (StackAdjustment % 16 != 0)
- return false;
- SpimmVal = StackAdjustment / 16;
- if (SpimmVal > 3)
- return false;
- return true;
-}
-
void printRlist(unsigned SlistEncode, raw_ostream &OS);
} // namespace RISCVZC
diff --git a/llvm/test/MC/RISCV/rv32xqccmp-invalid.s b/llvm/test/MC/RISCV/rv32xqccmp-invalid.s
index 899979cb4c601..74f96f076756c 100644
--- a/llvm/test/MC/RISCV/rv32xqccmp-invalid.s
+++ b/llvm/test/MC/RISCV/rv32xqccmp-invalid.s
@@ -13,23 +13,23 @@ qc.cm.mva01s a1, a2
# CHECK-ERROR: error: invalid register list, {ra, s0-s10} or {x1, x8-x9, x18-x26} is not supported
qc.cm.popretz {ra, s0-s10}, 112
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [16, 64]
qc.cm.popretz {ra, s0-s1}, 112
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
qc.cm.push {ra}, 16
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
qc.cm.pushfp {ra, s0}, 16
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [16, 64]
qc.cm.pop {ra, s0-s1}, -32
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
qc.cm.push {ra}, -8
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
qc.cm.pushfp {ra, s0}, -12
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [16, 64]
qc.cm.pop {ra, s0-s1}, -40
diff --git a/llvm/test/MC/RISCV/rv32zcmp-invalid.s b/llvm/test/MC/RISCV/rv32zcmp-invalid.s
index 0720a74a9b5c2..4115333fc738b 100644
--- a/llvm/test/MC/RISCV/rv32zcmp-invalid.s
+++ b/llvm/test/MC/RISCV/rv32zcmp-invalid.s
@@ -13,17 +13,17 @@ cm.mva01s a1, a2
# CHECK-ERROR: error: invalid register list, {ra, s0-s10} or {x1, x8-x9, x18-x26} is not supported
cm.popretz {ra, s0-s10}, 112
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Zc spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [16, 64]
cm.popretz {ra, s0-s1}, 112
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Zc spec for a detailed range of stack adjustment
+# CHECK-ERROR: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
cm.push {ra}, 16
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Zc spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [16, 64]
cm.pop {ra, s0-s1}, -32
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Zc spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
cm.push {ra}, -8
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Zc spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [16, 64]
cm.pop {ra, s0-s1}, -40
diff --git a/llvm/test/MC/RISCV/rv64xqccmp-invalid.s b/llvm/test/MC/RISCV/rv64xqccmp-invalid.s
index e922572a44749..ba0ed29afa108 100644
--- a/llvm/test/MC/RISCV/rv64xqccmp-invalid.s
+++ b/llvm/test/MC/RISCV/rv64xqccmp-invalid.s
@@ -13,23 +13,23 @@ qc.cm.mva01s a1, a2
# CHECK-ERROR: error: invalid register list, {ra, s0-s10} or {x1, x8-x9, x18-x26} is not supported
qc.cm.popretz {ra, s0-s10}, 112
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [32, 80]
qc.cm.popretz {ra, s0-s1}, 112
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
qc.cm.push {ra}, 16
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
qc.cm.pushfp {ra, s0}, 16
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [32, 80]
qc.cm.pop {ra, s0-s1}, -32
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
qc.cm.push {ra}, -15
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
qc.cm.push {ra, s0}, -15
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Xqccmp spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [32, 80]
qc.cm.pop {ra, s0-s1}, -33
diff --git a/llvm/test/MC/RISCV/rv64zcmp-invalid.s b/llvm/test/MC/RISCV/rv64zcmp-invalid.s
index 7e10ab5c2f902..804234d2c11e6 100644
--- a/llvm/test/MC/RISCV/rv64zcmp-invalid.s
+++ b/llvm/test/MC/RISCV/rv64zcmp-invalid.s
@@ -13,17 +13,17 @@ cm.mva01s a1, a2
# CHECK-ERROR: error: invalid register list, {ra, s0-s10} or {x1, x8-x9, x18-x26} is not supported
cm.popretz {ra, s0-s10}, 112
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Zc spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [32, 80]
cm.popretz {ra, s0-s1}, 112
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Zc spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
cm.push {ra}, 16
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Zc spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [32, 80]
cm.pop {ra, s0-s1}, -32
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Zc spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [-64, -16]
cm.push {ra}, -15
-# CHECK-ERROR: error: stack adjustment is invalid for this instruction and register list; refer to Zc spec for a detailed range of stack adjustment
+# CHECK-ERROR: error: stack adjustment for register list must be a multiple of 16 bytes in the range [32, 80]
cm.pop {ra, s0-s1}, -33
``````````
</details>
https://github.com/llvm/llvm-project/pull/129180
More information about the llvm-commits
mailing list