public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/114168] New: [RISC-V] Compiler generates impossible addend
@ 2024-02-29 15:15 schwab@linux-m68k.org
  2024-04-01  5:54 ` [Bug target/114168] " pinskia at gcc dot gnu.org
  2024-04-01  5:55 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: schwab@linux-m68k.org @ 2024-02-29 15:15 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-04-01  5:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-29 15:15 [Bug target/114168] New: [RISC-V] Compiler generates impossible addend schwab@linux-m68k.org
2024-04-01  5:54 ` [Bug target/114168] " pinskia at gcc dot gnu.org
2024-04-01  5:55 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).