[Bug target/114168] New: [RISC-V] Compiler generates impossible addend
schwab@linux-m68k.org
gcc-bugzilla@gcc.gnu.org
Thu Feb 29 15:15:34 GMT 2024
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114168
Bug ID: 114168
Summary: [RISC-V] Compiler generates impossible addend
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: schwab@linux-m68k.org
Target Milestone: ---
Target: riscv*-*-*
$ cat string-equal.cc
inline static bool
StringEqual (const char *p, const char *q, int nChar = 0x7fffffff)
{
if (p == q)
return true;
int n = 0;
while (*p && *q && *p == *q && n < nChar)
{
++p;
++q;
++n;
}
if (n == nChar || (*p == 0 && *q == 0))
return true;
return false;
}
bool
ToBool (const char *str, bool *value)
{
if (StringEqual (str, "true"))
{
*value = true;
return true;
}
else if (StringEqual (str, "false"))
{
*value = false;
return true;
}
return false;
}
$ gcc -O2 -S string-equal.cc
_Z6ToBoolPKcPb:
.LFB1:
.cfi_startproc
lui a5,%hi(.LC0)
addi a4,a5,%lo(.LC0)
beq a0,a4,.L24
lbu a7,0(a0)
beq a7,zero,.L36
lui t1,%hi(.LC0+2147483647)
mv a2,a7
mv a4,a0
li a6,0
addi a5,a5,%lo(.LC0)
addi t1,t1,%lo(.LC0+2147483647)
j .L3
The value of .LC0+2147483647 will never fit in the 32 bits that the lui+addi
combination can produce.
With -fPIC, the compiler generates
_Z6ToBoolPKcPb:
.LFB1:
.cfi_startproc
lla a5,.LC0
beq a0,a5,.L24
lbu a7,0(a0)
beq a7,zero,.L36
mv a2,a7
mv a4,a0
li a6,0
lla t1,.LC0+2147483647
j .L3
where lla cannot represent .LC0+2147483647.
More information about the Gcc-bugs
mailing list