public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/113010] New: [RISCV] sign-extension lost in comparison with constant embedded in comma-op expression
@ 2023-12-13 21:55 gkm at rivosinc dot com
  2023-12-13 22:06 ` [Bug target/113010] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: gkm at rivosinc dot com @ 2023-12-13 21:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113010

            Bug ID: 113010
           Summary: [RISCV] sign-extension lost in comparison with
                    constant embedded in comma-op expression
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gkm at rivosinc dot com
  Target Milestone: ---

Implicit conversion rules in C for comparing (unsigned long) with (int) require
that (int) first widen to (long) extending sign, then convert to (unsigned
long). 

I debugged this far enough to see that expand_compound_operation () in
combine.cc converts (SIGN_EXTEND:DI (mem/c:SI ... )) into paradoxical
(SUBREG:DI (mem/c:SI ... )), and thus loses the sign extension.

It only happens when the constant comparand is within a comma operator.


Test case:
--------------------------------------------------
int minus_1 = -1;

int main ()
{
  return ((0, 0xfffffffful) < minus_1) ? 0 : 1;
}
--------------------------------------------------
Godbolt:
https://godbolt.org/z/xPMPzG1n1

The -march=rv64gc case begins to fail with gcc-13
The -march=rv64gc_zbs case begins to fail with gcc-12

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

end of thread, other threads:[~2024-03-04 18:24 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-13 21:55 [Bug target/113010] New: [RISCV] sign-extension lost in comparison with constant embedded in comma-op expression gkm at rivosinc dot com
2023-12-13 22:06 ` [Bug target/113010] " pinskia at gcc dot gnu.org
2024-01-04  1:55 ` patrick at rivosinc dot com
2024-01-09 21:56 ` gkm at rivosinc dot com
2024-01-09 22:05 ` pinskia at gcc dot gnu.org
2024-01-09 22:12 ` pinskia at gcc dot gnu.org
2024-01-09 22:12 ` pinskia at gcc dot gnu.org
2024-01-11  2:45 ` gkm at rivosinc dot com
2024-01-11  2:50 ` gkm at rivosinc dot com
2024-01-24 21:33 ` patrick at rivosinc dot com
2024-01-24 21:47 ` pinskia at gcc dot gnu.org
2024-03-03 21:50 ` cvs-commit at gcc dot gnu.org
2024-03-03 21:53 ` law at gcc dot gnu.org
2024-03-04 18:24 ` cvs-commit 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).