Bug 31175 - RISCV load immediate relaxation leaves redundant addi
Summary: RISCV load immediate relaxation leaves redundant addi
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.39
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-16 17:01 UTC by Iain Finlay
Modified: 2023-12-16 17:01 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Tar of --save-temps and source to build image (65.01 KB, application/x-tar)
2023-12-16 17:01 UTC, Iain Finlay
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Iain Finlay 2023-12-16 17:01:21 UTC
Created attachment 15261 [details]
Tar of --save-temps and source to build image

Per the GCC g++ feedback (originally filed there), linker relaxation should remove the addi/mv in the cases 1, 2, 3. The following is an excerpt from objdump of the ELF.

20010064 <_Z6globalv>:
20010064:	80000537          	lui	a0,0x80000
20010068:	00050513          	mv	a0,a0           <-- (1)
2001006c:	00008067          	ret

20010070 <_Z4initv>:
20010070:	800007b7          	lui	a5,0x80000
20010074:	00078793          	mv	a5,a5           <-- (2)
20010078:	3e700713          	li	a4,999
2001007c:	00e7a223          	sw	a4,4(a5) # 80000004 <__global_pointer$+0xfffff804>
20010080:	0ea00713          	li	a4,234
20010084:	00e7a423          	sw	a4,8(a5)
20010088:	00008067          	ret

2001008c <_Z5pcnt0v>:
2001008c:	800007b7          	lui	a5,0x80000
20010090:	00078793          	mv	a5,a5           <-- (3)
20010094:	0047a703          	lw	a4,4(a5) # 80000004 <__global_pointer$+0xfffff804>
20010098:	60271713          	cpop	a4,a4

Command line:
riscv64-unknown-elf-g++ --save-temps -march=rv32imv_zbb_zbs -mabi=ilp32 -O3 -Wall -Wextra -o relax.elf main.cpp test.cpp startup.cpp -fno-builtin -static -fno-common -mcmodel=medlow -nostdlib -T link.ld
riscv64-unknown-elf-objdump -d relax.elf > relax.disasm