Skip to content

Commit 672d783

Browse files
committed
[Target][AArch64] Allow for char as int8_t in AArch64AsmParser.cpp
A couple of AArch64 tests were failing on Solaris, both sparc and x86: LLVM :: MC/AArch64/SVE/add-diagnostics.s LLVM :: MC/AArch64/SVE/cpy-diagnostics.s LLVM :: MC/AArch64/SVE/cpy.s LLVM :: MC/AArch64/SVE/dup-diagnostics.s LLVM :: MC/AArch64/SVE/dup.s LLVM :: MC/AArch64/SVE/mov-diagnostics.s LLVM :: MC/AArch64/SVE/mov.s LLVM :: MC/AArch64/SVE/sqadd-diagnostics.s LLVM :: MC/AArch64/SVE/sqsub-diagnostics.s LLVM :: MC/AArch64/SVE/sub-diagnostics.s LLVM :: MC/AArch64/SVE/subr-diagnostics.s LLVM :: MC/AArch64/SVE/uqadd-diagnostics.s LLVM :: MC/AArch64/SVE/uqsub-diagnostics.s For example, reduced from `MC/AArch64/SVE/add-diagnostics.s`: add z0.b, z0.b, #0, lsl #8 missed the expected diagnostics $ ./bin/llvm-mc -triple=aarch64 -show-encoding -mattr=+sve add.s add.s:1:21: error: immediate must be an integer in range [0, 255] with a shift amount of 0 add z0.b, z0.b, #0, lsl #8 ^ The message is `Match_InvalidSVEAddSubImm8`, emitted in the generated `lib/Target/AArch64/AArch64GenAsmMatcher.inc` for `MCK_SVEAddSubImm8`. When comparing the call to `::AArch64Operand::isSVEAddSubImm<char>` on both Linux/x86_64 and Solaris, I find 875 bool IsByte = std::is_same<int8_t, std::make_signed_t<T>>::value; is `false` on Solaris, unlike Linux. The problem boils down to the fact that `int8_t` is plain `char` on Solaris: both the sparc and i386 psABIs have `char` as signed. However, with 9887 DiagnosticPredicate DP(Operand.isSVEAddSubImm<int8_t>()); in `lib/Target/AArch64/AArch64GenAsmMatcher.inc`, `std::make_signed_t<int8_t>` above yieds `signed char`, so `std::is_same<int8_t, signed char>` is `false`. This can easily be fixed by also allowing for `int8_t` here and in a few similar places. Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and `x86_64-pc-linux-gnu`. Differential Revision: https://reviews.llvm.org/D85225
1 parent 6dcd9f5 commit 672d783

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,8 @@ class AArch64Operand : public MCParsedAsmOperand {
855855
if (!isShiftedImm() && (!isImm() || !isa<MCConstantExpr>(getImm())))
856856
return DiagnosticPredicateTy::NoMatch;
857857

858-
bool IsByte = std::is_same<int8_t, std::make_signed_t<T>>::value;
858+
bool IsByte = std::is_same<int8_t, std::make_signed_t<T>>::value ||
859+
std::is_same<int8_t, T>::value;
859860
if (auto ShiftedImm = getShiftedVal<8>())
860861
if (!(IsByte && ShiftedImm->second) &&
861862
AArch64_AM::isSVECpyImm<T>(uint64_t(ShiftedImm->first)
@@ -872,7 +873,8 @@ class AArch64Operand : public MCParsedAsmOperand {
872873
if (!isShiftedImm() && (!isImm() || !isa<MCConstantExpr>(getImm())))
873874
return DiagnosticPredicateTy::NoMatch;
874875

875-
bool IsByte = std::is_same<int8_t, std::make_signed_t<T>>::value;
876+
bool IsByte = std::is_same<int8_t, std::make_signed_t<T>>::value ||
877+
std::is_same<int8_t, T>::value;
876878
if (auto ShiftedImm = getShiftedVal<8>())
877879
if (!(IsByte && ShiftedImm->second) &&
878880
AArch64_AM::isSVEAddSubImm<T>(ShiftedImm->first

llvm/lib/Target/AArch64/MCTargetDesc/AArch64AddressingModes.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,8 @@ static inline bool isSVECpyImm(int64_t Imm) {
763763
bool IsImm8 = int8_t(Imm) == Imm;
764764
bool IsImm16 = int16_t(Imm & ~0xff) == Imm;
765765

766-
if (std::is_same<int8_t, std::make_signed_t<T>>::value)
766+
if (std::is_same<int8_t, std::make_signed_t<T>>::value ||
767+
std::is_same<int8_t, T>::value)
767768
return IsImm8 || uint8_t(Imm) == Imm;
768769

769770
if (std::is_same<int16_t, std::make_signed_t<T>>::value)
@@ -775,7 +776,8 @@ static inline bool isSVECpyImm(int64_t Imm) {
775776
/// Returns true if Imm is valid for ADD/SUB.
776777
template <typename T>
777778
static inline bool isSVEAddSubImm(int64_t Imm) {
778-
bool IsInt8t = std::is_same<int8_t, std::make_signed_t<T>>::value;
779+
bool IsInt8t = std::is_same<int8_t, std::make_signed_t<T>>::value ||
780+
std::is_same<int8_t, T>::value;
779781
return uint8_t(Imm) == Imm || (!IsInt8t && uint16_t(Imm & ~0xff) == Imm);
780782
}
781783

0 commit comments

Comments
 (0)