Skip to content

Commit b738bf1

Browse files
committed
Enable address resolution for load/store instructions relative to zero register
Handles the case of users writing instructions that access a data in the first page of a program. Such an instruction would not need the upper bits so a user is likely to use the zero register as the base to add the immediate to
1 parent 9dff558 commit b738bf1

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

cross-project-tests/tools/llvm-objdump/RISCV/riscv64-ar-coverage.s

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# RUN: %clang --target=fuchsia-elf-riscv64 -march=rv64gc_zcb %s -nostdlib -o %t
2+
# RUN: llvm-objcopy --add-symbol abs=0,global %t
23
# RUN: llvm-objdump -d %t | FileCheck %s
34

45
# CHECK: 0000000000001000 <_start>:
@@ -20,7 +21,7 @@
2021
# CHECK-NEXT: 102a: 0511 addi a0, a0, 0x4 <target>
2122
# CHECK-NEXT: 102c: 0505 addi a0, a0, 0x1
2223
# CHECK-NEXT: 102e: 00200037 lui zero, 0x200
23-
# CHECK-NEXT: 1032: 00a02423 sw a0, 0x8(zero)
24+
# CHECK-NEXT: 1032: 00a02423 sw a0, 0x8(zero) <abs+0x8>
2425
# CHECK-NEXT: 1036: 00101097 auipc ra, 0x101
2526
# CHECK-NEXT: 103a: fd6080e7 jalr -0x2a(ra) <func>
2627
# CHECK-NEXT: 103e: 640d lui s0, 0x3
@@ -71,9 +72,11 @@ _start:
7172
addi a0, a0, 0x4
7273
addi a0, a0, 0x1 # verify register tracking terminates
7374

74-
# Test 5 ensures that an instruction writing into the zero register does
75-
# not trigger resolution because that register's value cannot change and
76-
# the sequence is equivalent to never running the first instruction
75+
# Test 5 check instructions providing upper bits does not change the tracked
76+
# value of zero register + ensure load/store instructions accessing data
77+
# relative to the zero register trigger address resolution. The latter kind
78+
# of instructions are essentially memory accesses relative to the zero
79+
# register
7780

7881
# test #5
7982
lui x0, 0x200

llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCTargetDesc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class RISCVMCInstrAnalysis : public MCInstrAnalysis {
318318
case RISCV::SD_RV32: {
319319
MCRegister Reg = Inst.getOperand(1).getReg();
320320
auto TargetRegState = getGPRState(Reg);
321-
if (TargetRegState && Reg != RISCV::X0) {
321+
if (TargetRegState) {
322322
Target = *TargetRegState + Inst.getOperand(2).getImm();
323323
return true;
324324
}

0 commit comments

Comments
 (0)