Skip to content

Commit

Permalink
[AArch64AsmParser] Support (xxx), lsl 16 after #80571
Browse files Browse the repository at this point in the history
An immediate integer operand not prefixed with # can also be followed
by "lsl". Parse "lsl".
In the wild, edk2 ArmPkg/Include/AsmMacroIoLibV8.h has
`movz      Reg, (Val) >> 16, lsl #16`.

Note: our support for paren expression not prefixed with # is not very
good. For example, `adds x3, x4, (1024>>0), lsl 12` fails to be parsed.
  • Loading branch information
MaskRay committed Feb 19, 2024
1 parent e98abc3 commit 442f066
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 11 additions & 9 deletions llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4764,6 +4764,15 @@ bool AArch64AsmParser::parseOperand(OperandVector &Operands, bool isCondCode,

// Nothing custom, so do general case parsing.
SMLoc S, E;
auto parseOptionalShiftExtend = [&](AsmToken SavedTok) {
if (parseOptionalToken(AsmToken::Comma)) {
ParseStatus Res = tryParseOptionalShiftExtend(Operands);
if (!Res.isNoMatch())
return Res.isFailure();
getLexer().UnLex(SavedTok);
}
return false;
};
switch (getLexer().getKind()) {
default: {
SMLoc S = getLoc();
Expand All @@ -4773,7 +4782,7 @@ bool AArch64AsmParser::parseOperand(OperandVector &Operands, bool isCondCode,

SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
Operands.push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
return false;
return parseOptionalShiftExtend(getTok());
}
case AsmToken::LBrac: {
Operands.push_back(
Expand Down Expand Up @@ -4895,14 +4904,7 @@ bool AArch64AsmParser::parseOperand(OperandVector &Operands, bool isCondCode,
Operands.push_back(AArch64Operand::CreateImm(ImmVal, S, E, getContext()));

// Parse an optional shift/extend modifier.
AsmToken SavedTok = Tok;
if (parseOptionalToken(AsmToken::Comma)) {
ParseStatus Res = tryParseOptionalShiftExtend(Operands);
if (!Res.isNoMatch())
return Res.isFailure();
getLexer().UnLex(SavedTok);
}
return false;
return parseOptionalShiftExtend(Tok);
}
case AsmToken::Equal: {
SMLoc Loc = getLoc();
Expand Down
4 changes: 4 additions & 0 deletions llvm/test/MC/AArch64/arm64-optional-hash.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
; CHECK: adds x3, x4, #1024, lsl #12 ; encoding: [0x83,0x00,0x50,0xb1]
adds x3, x4, 1024, lsl 12

; CHECK-COUNT-2: mov x3, #327680 ; encoding: [0xa3,0x00,0xa0,0xd2]
movz x3, (0x54321) >> 16, lsl 16
movz x3, (0x54321 >> 16), lsl 16

; Optional extend
; CHECK: add sp, x2, x3 ; encoding: [0x5f,0x60,0x23,0x8b]
add sp, x2, x3, uxtx 0
Expand Down

0 comments on commit 442f066

Please sign in to comment.