[gcc r16-1276] [to-be-committed][RISC-V] Handle 32bit operands in condition for conditional moves

2025-06-07 Thread Jeff Law via Gcc-cvs
https://gcc.gnu.org/g:59a3da733a79f621700dd9ddc11a0efc07237c3a

commit r16-1276-g59a3da733a79f621700dd9ddc11a0efc07237c3a
Author: Jeff Law 
Date:   Sat Jun 7 07:48:46 2025 -0600

[to-be-committed][RISC-V] Handle 32bit operands in condition for 
conditional moves

So here's the next chunk of conditional move work from Shreya.

It's been a long standing wart that the conditional move expander does not
support sub-word operands in the comparison.  Particularly since we have
support routines to handle the necessary extensions for that case.

This patch adjusts the expander to use riscv_extend_comparands rather than 
fail
for that case.  I've built spec2017 before/after this and we definitely get
more conditional moves and they look sensible from a performance standpoint.
None are likely hitting terribly hot code, so I wouldn't expect any 
performance
jumps.

Waiting on pre-commit testing to do its thing.

* config/riscv/riscv.cc (riscv_expand_conditional_move): Use
riscv_extend_comparands to extend sub-word comparison arguments.

Co-authored-by: Jeff Law  

Diff:
---
 gcc/config/riscv/riscv.cc | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 99eeba64b6f9..dd29059412b1 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -5436,13 +5436,18 @@ riscv_expand_conditional_move (rtx dest, rtx op, rtx 
cons, rtx alt)
   machine_mode mode0 = GET_MODE (op0);
   machine_mode mode1 = GET_MODE (op1);
 
-  /* An integer comparison must be comparing WORD_MODE objects.  We
-must enforce that so that we don't strip away a sign_extension
-thinking it is unnecessary.  We might consider using
-riscv_extend_operands if they are not already properly extended.  */
+  /* An integer comparison must be comparing WORD_MODE objects.
+Extend the comparison arguments as necessary.  */
   if ((INTEGRAL_MODE_P (mode0) && mode0 != word_mode)
  || (INTEGRAL_MODE_P (mode1) && mode1 != word_mode))
-   return false;
+   riscv_extend_comparands (code, &op0, &op1);
+
+  /* We might have been handed back a SUBREG.  Just to make things
+easy, force it into a REG.  */
+  if (!REG_P (op0) && !CONST_INT_P (op0))
+   op0 = force_reg (word_mode, op0);
+  if (!REG_P (op1) && !CONST_INT_P (op1))
+   op1 = force_reg (word_mode, op1);
 
   /* In the fallback generic case use MODE rather than WORD_MODE for
 the output of the SCC instruction, to match the mode of the NEG


[gcc r16-1277] [PR modula2/119650, PR modula2/117203]: WriteString and Delete are missing from base libraries

2025-06-07 Thread Gaius Mulley via Gcc-cvs
https://gcc.gnu.org/g:d1c3cfa3296ae5010c514d67f57acf144a299c7a

commit r16-1277-gd1c3cfa3296ae5010c514d67f57acf144a299c7a
Author: Gaius Mulley 
Date:   Sat Jun 7 16:25:19 2025 +0100

[PR modula2/119650, PR modula2/117203]: WriteString and Delete are missing 
from base libraries

This patch introduces a Write procedure for an array of char,
the string and char datatype.  It uses the m2r10 style of
naming the module on the datatype.  This uncovered a bug
in the import handling inside Quadident.  It also includes
an Unlink procedure from a new module FileSysOp and a String
interface to this module.

gcc/m2/ChangeLog:

PR modula2/119650
PR modula2/117203
* gm2-compiler/P2Build.bnf (CheckModuleQualident): New
procedure.
(Qualident): Rewrite.
* gm2-compiler/P3Build.bnf (PushTFQualident): New procedure.
(CheckModuleQualident): Ditto.
(Qualident): Rewrite.
* gm2-compiler/PCBuild.bnf (PushTFQualident): New procedure.
(CheckModuleQualident): Ditto.
(Qualident): Rewrite.
* gm2-compiler/PHBuild.bnf (PushTFQualident): New procedure.
(CheckModuleQualident): Ditto.
(Qualident): Rewrite.
* gm2-libs/ARRAYOFCHAR.def: New file.
* gm2-libs/ARRAYOFCHAR.mod: New file.
* gm2-libs/CFileSysOp.def: New file.
* gm2-libs/CHAR.def: New file.
* gm2-libs/CHAR.mod: New file.
* gm2-libs/FileSysOp.def: New file.
* gm2-libs/FileSysOp.mod: New file.
* gm2-libs/String.def: New file.
* gm2-libs/String.mod: New file.
* gm2-libs/StringFileSysOp.def: New file.
* gm2-libs/StringFileSysOp.mod: New file.

libgm2/ChangeLog:

PR modula2/119650
PR modula2/117203
* libm2pim/Makefile.am (M2MODS): Add ARRAYOFCHAR,
CHAR.mod, StringFileSysOp.mod and String.mod.
(M2DEFS): Add ARRAYOFCHAR, CHAR.mod,
StringFileSysOp.mod and String.mod.
(libm2pim_la_SOURCES): Add CFileSysOp.c.
* libm2pim/Makefile.in: Regenerate.
* libm2pim/CFileSysOp.cc: New file.

gcc/testsuite/ChangeLog:

PR modula2/119650
* gm2/iso/fail/CHAR.mod: New test.
* gm2/iso/run/pass/CHAR.mod: New test.
* gm2/iso/run/pass/importself.mod: New test.
* gm2/pimlib/run/pass/testwrite.mod: New test.
* gm2/pimlib/run/pass/testwritechar.mod: New test.

Signed-off-by: Gaius Mulley 

Diff:
---
 gcc/m2/gm2-compiler/P2Build.bnf|  79 +++
 gcc/m2/gm2-compiler/P3Build.bnf|  99 +-
 gcc/m2/gm2-compiler/PCBuild.bnf|  97 +-
 gcc/m2/gm2-compiler/PHBuild.bnf|  86 +---
 gcc/m2/gm2-libs/ARRAYOFCHAR.def|  41 ++
 gcc/m2/gm2-libs/ARRAYOFCHAR.mod|  56 
 gcc/m2/gm2-libs/CFileSysOp.def |  56 
 gcc/m2/gm2-libs/CHAR.def   |  40 ++
 gcc/m2/gm2-libs/CHAR.mod   |  48 +++
 gcc/m2/gm2-libs/FileSysOp.def  |  44 +++
 gcc/m2/gm2-libs/FileSysOp.mod  |  98 ++
 gcc/m2/gm2-libs/String.def |  35 +
 gcc/m2/gm2-libs/String.mod |  51 
 gcc/m2/gm2-libs/StringFileSysOp.def|  40 ++
 gcc/m2/gm2-libs/StringFileSysOp.mod|  63 +
 gcc/testsuite/gm2/iso/fail/CHAR.mod|   7 +
 gcc/testsuite/gm2/iso/run/pass/CHAR.mod|   7 +
 gcc/testsuite/gm2/iso/run/pass/importself.mod  |  14 ++
 gcc/testsuite/gm2/pimlib/run/pass/testwrite.mod|   8 ++
 .../gm2/pimlib/run/pass/testwritechar.mod  |  13 ++
 libgm2/libm2pim/CFileSysOp.cc  | 145 +
 libgm2/libm2pim/Makefile.am|  20 ++-
 libgm2/libm2pim/Makefile.in|  27 +++-
 23 files changed, 1059 insertions(+), 115 deletions(-)

diff --git a/gcc/m2/gm2-compiler/P2Build.bnf b/gcc/m2/gm2-compiler/P2Build.bnf
index b9a6daa70b2e..c28e630422f7 100644
--- a/gcc/m2/gm2-compiler/P2Build.bnf
+++ b/gcc/m2/gm2-compiler/P2Build.bnf
@@ -46,7 +46,8 @@ see .  *)
 IMPLEMENTATION MODULE P2Build ;
 
 FROM M2LexBuf IMPORT currentstring, currenttoken, GetToken, InsertToken,
- InsertTokenAndRewind, GetTokenNo, MakeVirtual2Tok ;
+ InsertTokenAndRewind, GetTokenNo, MakeVirtual2Tok,
+MakeVirtualTok ;
 
 FROM M2MetaError IMPORT MetaErrorStringT0, MetaErrorT1 ;
 FROM NameKey IMPORT NulName, Name, makekey, MakeKey ;
@@ -128,13 +129,13 @@ FROM SymbolTable IMPORT MakeGnuAsm, PutGnuAsmV