Skip to content

Commit a5d375e

Browse files
committed
[AArch64] Allow logical immediates to have all-1 in top bits
So that constant expressions like the following are permitted: and w0, w0, #~(0xfe<<24) and w1, w1, #~(0xff<<24) The behavior matches GNU as (opcodes/aarch64-opc.c:aarch64_logical_immediate_p). Reviewed By: sdesmalen Differential Revision: https://reviews.llvm.org/D75885
1 parent 7aba6a0 commit a5d375e

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,12 +757,13 @@ class AArch64Operand : public MCParsedAsmOperand {
757757
return false;
758758

759759
int64_t Val = MCE->getValue();
760-
int64_t SVal = std::make_signed_t<T>(Val);
761-
int64_t UVal = std::make_unsigned_t<T>(Val);
762-
if (Val != SVal && Val != UVal)
760+
// Avoid left shift by 64 directly.
761+
uint64_t Upper = UINT64_C(-1) << (sizeof(T) * 4) << (sizeof(T) * 4);
762+
// Allow all-0 or all-1 in top bits to permit bitwise NOT.
763+
if ((Val & Upper) && (Val & Upper) != Upper)
763764
return false;
764765

765-
return AArch64_AM::isLogicalImmediate(UVal, sizeof(T) * 8);
766+
return AArch64_AM::isLogicalImmediate(Val & ~Upper, sizeof(T) * 8);
766767
}
767768

768769
bool isShiftedImm() const { return Kind == k_ShiftedImm; }

llvm/test/MC/AArch64/SVE/mov-diagnostics.s

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,6 @@ mov z0.b, #1, lsl #8
153153
// CHECK-NEXT: mov z0.b, #1, lsl #8
154154
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
155155

156-
mov z0.h, #-33024
157-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [-128, 127] or a multiple of 256 in range [-32768, 65280]
158-
// CHECK-NEXT: mov z0.h, #-33024
159-
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
160-
161-
mov z0.h, #-32769
162-
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [-128, 127] or a multiple of 256 in range [-32768, 65280]
163-
// CHECK-NEXT: mov z0.h, #-32769
164-
// CHECK-NOT: [[@LINE-1]]:{{[0-9]+}}:
165-
166156
mov z0.h, #-129, lsl #8
167157
// CHECK: [[@LINE-1]]:{{[0-9]+}}: error: immediate must be an integer in range [-128, 127] or a multiple of 256 in range [-32768, 65280]
168158
// CHECK-NEXT: mov z0.h, #-129, lsl #8

llvm/test/MC/AArch64/SVE/mov.s

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ mov z0.h, #65280
205205
// CHECK-ERROR: instruction requires: sve
206206
// CHECK-UNKNOWN: e0 ff 78 25 <unknown>
207207

208+
mov z0.h, #-33024
209+
// CHECK-INST: dupm z0.h, #0x7f00
210+
// CHECK-ENCODING: [0xc0,0x44,0xc0,0x05]
211+
// CHECK-ERROR: instruction requires: sve
212+
// CHECK-UNKNOWN: c0 44 c0 05 <unknown>
213+
214+
mov z0.h, #-32769
215+
// CHECK-INST: mov z0.h, #32767
216+
// CHECK-ENCODING: [0xc0,0x05,0xc0,0x05]
217+
// CHECK-ERROR: instruction requires: sve
218+
// CHECK-UNKNOWN: c0 05 c0 05 <unknown>
219+
208220
mov z0.s, #-32769
209221
// CHECK-INST: mov z0.s, #0xffff7fff
210222
// CHECK-ENCODING: [0xc0,0x83,0xc0,0x05]

llvm/test/MC/AArch64/arm64-logical-encoding.s

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,10 @@ foo:
222222
; CHECK: orn x1, x2, x3, asr #7 ; encoding: [0x41,0x1c,0xa3,0xaa]
223223
; CHECK: orn w1, w2, w3, ror #7 ; encoding: [0x41,0x1c,0xe3,0x2a]
224224
; CHECK: orn x1, x2, x3, ror #7 ; encoding: [0x41,0x1c,0xe3,0xaa]
225+
226+
;; Allow all-1 in top bits.
227+
and w0, w0, #~(0xfe<<24)
228+
and w1, w1, #~(0xff<<24)
229+
230+
; CHECK: and w0, w0, #0x1ffffff
231+
; CHECK: and w1, w1, #0xffffff

0 commit comments

Comments
 (0)