Skip to content

Commit 442f066

Browse files
committed
[AArch64AsmParser] Support (xxx), lsl 16 after llvm#80571
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 rust-lang#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.
1 parent e98abc3 commit 442f066

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

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

+11-9
Original file line numberDiff line numberDiff line change
@@ -4764,6 +4764,15 @@ bool AArch64AsmParser::parseOperand(OperandVector &Operands, bool isCondCode,
47644764

47654765
// Nothing custom, so do general case parsing.
47664766
SMLoc S, E;
4767+
auto parseOptionalShiftExtend = [&](AsmToken SavedTok) {
4768+
if (parseOptionalToken(AsmToken::Comma)) {
4769+
ParseStatus Res = tryParseOptionalShiftExtend(Operands);
4770+
if (!Res.isNoMatch())
4771+
return Res.isFailure();
4772+
getLexer().UnLex(SavedTok);
4773+
}
4774+
return false;
4775+
};
47674776
switch (getLexer().getKind()) {
47684777
default: {
47694778
SMLoc S = getLoc();
@@ -4773,7 +4782,7 @@ bool AArch64AsmParser::parseOperand(OperandVector &Operands, bool isCondCode,
47734782

47744783
SMLoc E = SMLoc::getFromPointer(getLoc().getPointer() - 1);
47754784
Operands.push_back(AArch64Operand::CreateImm(Expr, S, E, getContext()));
4776-
return false;
4785+
return parseOptionalShiftExtend(getTok());
47774786
}
47784787
case AsmToken::LBrac: {
47794788
Operands.push_back(
@@ -4895,14 +4904,7 @@ bool AArch64AsmParser::parseOperand(OperandVector &Operands, bool isCondCode,
48954904
Operands.push_back(AArch64Operand::CreateImm(ImmVal, S, E, getContext()));
48964905

48974906
// Parse an optional shift/extend modifier.
4898-
AsmToken SavedTok = Tok;
4899-
if (parseOptionalToken(AsmToken::Comma)) {
4900-
ParseStatus Res = tryParseOptionalShiftExtend(Operands);
4901-
if (!Res.isNoMatch())
4902-
return Res.isFailure();
4903-
getLexer().UnLex(SavedTok);
4904-
}
4905-
return false;
4907+
return parseOptionalShiftExtend(Tok);
49064908
}
49074909
case AsmToken::Equal: {
49084910
SMLoc Loc = getLoc();

llvm/test/MC/AArch64/arm64-optional-hash.s

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
; CHECK: adds x3, x4, #1024, lsl #12 ; encoding: [0x83,0x00,0x50,0xb1]
99
adds x3, x4, 1024, lsl 12
1010

11+
; CHECK-COUNT-2: mov x3, #327680 ; encoding: [0xa3,0x00,0xa0,0xd2]
12+
movz x3, (0x54321) >> 16, lsl 16
13+
movz x3, (0x54321 >> 16), lsl 16
14+
1115
; Optional extend
1216
; CHECK: add sp, x2, x3 ; encoding: [0x5f,0x60,0x23,0x8b]
1317
add sp, x2, x3, uxtx 0

0 commit comments

Comments
 (0)