-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MC][AArch64] Segregate constant pool caches by size. (#86832)
If you write a 32- and a 64-bit LDR instruction that both refer to the same constant or symbol using the = syntax: ``` ldr w0, =something ldr x1, =something ``` then the first call to `ConstantPool::addEntry` will insert the constant into its cache of existing entries, and the second one will find the cache entry and reuse it. This results in a 64-bit load from a 32-bit constant, reading nonsense into the other half of the target register. In this patch I've done the simplest fix: include the size of the constant pool entry as part of the key used to index the cache. So now 32- and 64-bit constant loads will never share a constant pool entry. There's scope for doing this better, in principle: you could imagine merging the two slots with appropriate overlap, so that the 32-bit load loads the LSW of the 64-bit value. But that's much more complicated: you have to take endianness into account, and maybe also adjust the size of an existing entry. This is the simplest fix that restores correctness.
- Loading branch information
1 parent
2a2fd48
commit 88b10f3
Showing
3 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// RUN: llvm-mc -triple aarch64-none-linux-gnu %s | FileCheck %s | ||
|
||
ldr w0, =symbol | ||
ldr x1, =symbol | ||
|
||
ldr w2, =1234567890 | ||
ldr x3, =1234567890 | ||
|
||
// CHECK: ldr w0, .Ltmp0 | ||
// CHECK: ldr x1, .Ltmp1 | ||
// CHECK: ldr w2, .Ltmp2 | ||
// CHECK: ldr x3, .Ltmp3 | ||
|
||
// CHECK: .p2align 2, 0x0 | ||
// CHECK-NEXT:.Ltmp0: | ||
// CHECK-NEXT: .word symbol | ||
// CHECK: .p2align 3, 0x0 | ||
// CHECK-NEXT:.Ltmp1: | ||
// CHECK-NEXT: .xword symbol | ||
// CHECK: .p2align 2, 0x0 | ||
// CHECK-NEXT:.Ltmp2: | ||
// CHECK-NEXT: .word 1234567890 | ||
// CHECK: .p2align 3, 0x0 | ||
// CHECK-NEXT:.Ltmp3: | ||
// CHECK-NEXT: .xword 1234567890 |