https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117460
Bug ID: 117460
Summary: riscv64 backend emits large relocations due to loop
strength reduction
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: aurelien at aurel32 dot net
Target Milestone: ---
The following code, extracted from lziprecover 1.25~pre1, and compiled with -O2
-mcmodel=medany causes the riscv backend to emit out of range relocation due to
loop strength reduction, whcih then cause issues at link time:
#include <limits.h>
#include <stdbool.h>
bool foo(const char *const arg) {
const char *const target = "foo";
if (arg[0] == target[0]) {
for (int i = 1; i < INT_MAX; ++i) {
if (arg[i] == 0) return true;
if (arg[i] != target[i]) break;
}
}
return false;
}
See how both side of the loop, 1 and INT_MAX, end up in the generated code:
.L9:
addi a0,a0,1
lla a5,.LC0+1
lla a2,.LC0+2147483647
j .L3
(Thanks to Jessica Clarke for helping understanding the issue)