public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [RISC-V][V2] Fix incorrect if-then-else nesting of Zbs usage in constant synthesis
@ 2024-05-10  3:10 Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2024-05-10  3:10 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:f273ad20d6b2b3f196a0c99a5a0c419cc13d862a

commit f273ad20d6b2b3f196a0c99a5a0c419cc13d862a
Author: Jeff Law <jlaw@ventanamicro.com>
Date:   Wed May 8 13:44:00 2024 -0600

    [RISC-V][V2] Fix incorrect if-then-else nesting of Zbs usage in constant synthesis
    
    Reposting without the patch that ignores whitespace.  The CI system doesn't
    like including both patches, that'll generate a failure to apply and none of
    the tests actually get run.
    
    So I managed to goof the if-then-else level of the bseti bits last week.  They
    were supposed to be a last ditch effort to improve the result, but ended up
    inside a conditional where they don't really belong.  I almost always use Zba,
    Zbb and Zbs together, so it slipped by.
    
    So it's NFC if you always test with Zbb and Zbs enabled together.  But if you
    enabled Zbs without Zbb you'd see a failure to use bseti.
    
    gcc/
            * config/riscv/riscv.cc (riscv_build_integer_1): Fix incorrect
            if-then-else nesting of Zbs code.
    
    (cherry picked from commit 1c234097487927a4388ddcc690b63597bb3a90dc)

Diff:
---
 gcc/config/riscv/riscv.cc | 81 ++++++++++++++++++++++++-----------------------
 1 file changed, 41 insertions(+), 40 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 62207b6b2273..633b55f9707a 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -878,50 +878,51 @@ riscv_build_integer_1 (struct riscv_integer_op codes[RISCV_MAX_INTEGER_OPS],
 	  codes[1].use_uw = false;
 	  cost = 2;
 	}
-      /* Final cases, particularly focused on bseti.  */
-      else if (cost > 2 && TARGET_ZBS)
-	{
-	  int i = 0;
+    }
 
-	  /* First handle any bits set by LUI.  Be careful of the
-	     SImode sign bit!.  */
-	  if (value & 0x7ffff800)
-	    {
-	      alt_codes[i].code = (i == 0 ? UNKNOWN : IOR);
-	      alt_codes[i].value = value & 0x7ffff800;
-	      alt_codes[i].use_uw = false;
-	      value &= ~0x7ffff800;
-	      i++;
-	    }
+  /* Final cases, particularly focused on bseti.  */
+  if (cost > 2 && TARGET_ZBS)
+    {
+      int i = 0;
 
-	  /* Next, any bits we can handle with addi.  */
-	  if (value & 0x7ff)
-	    {
-	      alt_codes[i].code = (i == 0 ? UNKNOWN : PLUS);
-	      alt_codes[i].value = value & 0x7ff;
-	      alt_codes[i].use_uw = false;
-	      value &= ~0x7ff;
-	      i++;
-	    }
+      /* First handle any bits set by LUI.  Be careful of the
+	 SImode sign bit!.  */
+      if (value & 0x7ffff800)
+	{
+	  alt_codes[i].code = (i == 0 ? UNKNOWN : IOR);
+	  alt_codes[i].value = value & 0x7ffff800;
+	  alt_codes[i].use_uw = false;
+	  value &= ~0x7ffff800;
+	   i++;
+	}
 
-	  /* And any residuals with bseti.  */
-	  while (i < cost && value)
-	    {
-	      HOST_WIDE_INT bit = ctz_hwi (value);
-	      alt_codes[i].code = (i == 0 ? UNKNOWN : IOR);
-	      alt_codes[i].value = 1UL << bit;
-	      alt_codes[i].use_uw = false;
-	      value &= ~(1ULL << bit);
-	      i++;
-	    }
+      /* Next, any bits we can handle with addi.  */
+      if (value & 0x7ff)
+	{
+	  alt_codes[i].code = (i == 0 ? UNKNOWN : PLUS);
+	  alt_codes[i].value = value & 0x7ff;
+	  alt_codes[i].use_uw = false;
+	  value &= ~0x7ff;
+	  i++;
+	}
 
-	  /* If LUI+ADDI+BSETI resulted in a more efficient
-	     sequence, then use it.  */
-	  if (i < cost)
-	    {
-	      memcpy (codes, alt_codes, sizeof (alt_codes));
-	      cost = i;
-	    }
+      /* And any residuals with bseti.  */
+      while (i < cost && value)
+	{
+	  HOST_WIDE_INT bit = ctz_hwi (value);
+	  alt_codes[i].code = (i == 0 ? UNKNOWN : IOR);
+	  alt_codes[i].value = 1UL << bit;
+	  alt_codes[i].use_uw = false;
+	  value &= ~(1ULL << bit);
+	  i++;
+	}
+
+      /* If LUI+ADDI+BSETI resulted in a more efficient
+	 sequence, then use it.  */
+      if (i < cost)
+	{
+	  memcpy (codes, alt_codes, sizeof (alt_codes));
+	  cost = i;
 	}
     }

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

* [gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [RISC-V][V2] Fix incorrect if-then-else nesting of Zbs usage in constant synthesis
@ 2024-05-27  0:05 Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2024-05-27  0:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:b30496ab6f0706b373ca68cea832fe13dd0c0e59

commit b30496ab6f0706b373ca68cea832fe13dd0c0e59
Author: Jeff Law <jlaw@ventanamicro.com>
Date:   Wed May 8 13:44:00 2024 -0600

    [RISC-V][V2] Fix incorrect if-then-else nesting of Zbs usage in constant synthesis
    
    Reposting without the patch that ignores whitespace.  The CI system doesn't
    like including both patches, that'll generate a failure to apply and none of
    the tests actually get run.
    
    So I managed to goof the if-then-else level of the bseti bits last week.  They
    were supposed to be a last ditch effort to improve the result, but ended up
    inside a conditional where they don't really belong.  I almost always use Zba,
    Zbb and Zbs together, so it slipped by.
    
    So it's NFC if you always test with Zbb and Zbs enabled together.  But if you
    enabled Zbs without Zbb you'd see a failure to use bseti.
    
    gcc/
            * config/riscv/riscv.cc (riscv_build_integer_1): Fix incorrect
            if-then-else nesting of Zbs code.
    
    (cherry picked from commit 1c234097487927a4388ddcc690b63597bb3a90dc)

Diff:
---
 gcc/config/riscv/riscv.cc | 81 ++++++++++++++++++++++++-----------------------
 1 file changed, 41 insertions(+), 40 deletions(-)

diff --git a/gcc/config/riscv/riscv.cc b/gcc/config/riscv/riscv.cc
index 62207b6b227..633b55f9707 100644
--- a/gcc/config/riscv/riscv.cc
+++ b/gcc/config/riscv/riscv.cc
@@ -878,50 +878,51 @@ riscv_build_integer_1 (struct riscv_integer_op codes[RISCV_MAX_INTEGER_OPS],
 	  codes[1].use_uw = false;
 	  cost = 2;
 	}
-      /* Final cases, particularly focused on bseti.  */
-      else if (cost > 2 && TARGET_ZBS)
-	{
-	  int i = 0;
+    }
 
-	  /* First handle any bits set by LUI.  Be careful of the
-	     SImode sign bit!.  */
-	  if (value & 0x7ffff800)
-	    {
-	      alt_codes[i].code = (i == 0 ? UNKNOWN : IOR);
-	      alt_codes[i].value = value & 0x7ffff800;
-	      alt_codes[i].use_uw = false;
-	      value &= ~0x7ffff800;
-	      i++;
-	    }
+  /* Final cases, particularly focused on bseti.  */
+  if (cost > 2 && TARGET_ZBS)
+    {
+      int i = 0;
 
-	  /* Next, any bits we can handle with addi.  */
-	  if (value & 0x7ff)
-	    {
-	      alt_codes[i].code = (i == 0 ? UNKNOWN : PLUS);
-	      alt_codes[i].value = value & 0x7ff;
-	      alt_codes[i].use_uw = false;
-	      value &= ~0x7ff;
-	      i++;
-	    }
+      /* First handle any bits set by LUI.  Be careful of the
+	 SImode sign bit!.  */
+      if (value & 0x7ffff800)
+	{
+	  alt_codes[i].code = (i == 0 ? UNKNOWN : IOR);
+	  alt_codes[i].value = value & 0x7ffff800;
+	  alt_codes[i].use_uw = false;
+	  value &= ~0x7ffff800;
+	   i++;
+	}
 
-	  /* And any residuals with bseti.  */
-	  while (i < cost && value)
-	    {
-	      HOST_WIDE_INT bit = ctz_hwi (value);
-	      alt_codes[i].code = (i == 0 ? UNKNOWN : IOR);
-	      alt_codes[i].value = 1UL << bit;
-	      alt_codes[i].use_uw = false;
-	      value &= ~(1ULL << bit);
-	      i++;
-	    }
+      /* Next, any bits we can handle with addi.  */
+      if (value & 0x7ff)
+	{
+	  alt_codes[i].code = (i == 0 ? UNKNOWN : PLUS);
+	  alt_codes[i].value = value & 0x7ff;
+	  alt_codes[i].use_uw = false;
+	  value &= ~0x7ff;
+	  i++;
+	}
 
-	  /* If LUI+ADDI+BSETI resulted in a more efficient
-	     sequence, then use it.  */
-	  if (i < cost)
-	    {
-	      memcpy (codes, alt_codes, sizeof (alt_codes));
-	      cost = i;
-	    }
+      /* And any residuals with bseti.  */
+      while (i < cost && value)
+	{
+	  HOST_WIDE_INT bit = ctz_hwi (value);
+	  alt_codes[i].code = (i == 0 ? UNKNOWN : IOR);
+	  alt_codes[i].value = 1UL << bit;
+	  alt_codes[i].use_uw = false;
+	  value &= ~(1ULL << bit);
+	  i++;
+	}
+
+      /* If LUI+ADDI+BSETI resulted in a more efficient
+	 sequence, then use it.  */
+      if (i < cost)
+	{
+	  memcpy (codes, alt_codes, sizeof (alt_codes));
+	  cost = i;
 	}
     }

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

end of thread, other threads:[~2024-05-27  0:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-10  3:10 [gcc(refs/vendors/riscv/heads/gcc-14-with-riscv-opts)] [RISC-V][V2] Fix incorrect if-then-else nesting of Zbs usage in constant synthesis Jeff Law
2024-05-27  0:05 Jeff Law

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).