public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/vrull/heads/for-upstream)] RISC-V: split to allow formation of sh[123]add before 32bit divw
@ 2022-11-15 14:00 Philipp Tomsich
  0 siblings, 0 replies; 3+ messages in thread
From: Philipp Tomsich @ 2022-11-15 14:00 UTC (permalink / raw)
  To: gcc-cvs

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

commit e322d16dbdfe2965b4310fa6bfdbcf7530a5a11e
Author: Philipp Tomsich <philipp.tomsich@vrull.eu>
Date:   Tue Nov 8 20:45:51 2022 +0100

    RISC-V: split to allow formation of sh[123]add before 32bit divw
    
    When using strength-reduction, we will reduce a multiplication to a
    sequence of shifts and adds.  If this is performed with 32-bit types
    and followed by a division, the lack of w-form sh[123]add will make
    combination impossible and lead to a slli + addw being generated.
    
    Split the sequence with the knowledge that a w-form div will perform
    implicit sign-extensions.
    
    gcc/ChangeLog:
    
            * config/riscv/bitmanip.md: Add a define_split to optimize
              slliw + addiw + divw into sh[123]add + divw.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/riscv/zba-shNadd-05.c: New test.
    
    Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
    
    Series-to: gcc-patches@gcc.gnu.org
    Series-cc: Palmer Dabbelt <palmer@rivosinc.com>
    Series-cc: Vineet Gupta <vineetg@rivosinc.com>
    Series-cc: Christoph Muellner <christoph.muellner@vrull.eu>
    Series-cc: Kito Cheng <kito.cheng@gmail.com>
    Series-cc: Jeff Law <jlaw@ventanamicro.com>

Diff:
---
 gcc/config/riscv/bitmanip.md                   | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c | 11 +++++++++++
 2 files changed, 28 insertions(+)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index 1d603906cb2..75252c37df2 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -39,6 +39,23 @@
   [(set_attr "type" "bitmanip")
    (set_attr "mode" "<X:MODE>")])
 
+; When using strength-reduction, we will reduce a multiplication to a
+; sequence of shifts and adds.  If this is performed with 32-bit types
+; and followed by a division, the lack of w-form sh[123]add will make
+; combination impossible and lead to a slli + addw being generated.
+; Split the sequence with the knowledge that a w-form div will perform
+; implicit sign-extensions.
+(define_split
+  [(set (match_operand:DI 0 "register_operand")
+	(sign_extend:DI (div:SI (plus:SI (subreg:SI (ashift:DI (match_operand:DI 1 "register_operand")
+							       (match_operand:QI 2 "imm123_operand")) 0)
+						    (subreg:SI (match_operand:DI 3 "register_operand") 0))
+		(subreg:SI (match_operand:DI 4 "register_operand") 0))))
+   (clobber (match_operand:DI 5 "register_operand"))]
+  "TARGET_64BIT && TARGET_ZBA"
+   [(set (match_dup 5) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
+    (set (match_dup 0) (sign_extend:DI (div:SI (subreg:SI (match_dup 5) 0) (subreg:SI (match_dup 4) 0))))])
+
 (define_insn "*shNadduw"
   [(set (match_operand:DI 0 "register_operand" "=r")
 	(plus:DI
diff --git a/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c b/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c
new file mode 100644
index 00000000000..271c3a8c0ac
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-Oz" "-Og" } } */
+
+long long f(int a, int b)
+{
+  return (a * 3) / b;
+}
+
+/* { dg-final { scan-assembler-times "sh1add\t" 1 } } */
+/* { dg-final { scan-assembler-times "divw\t" 1 } } */

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

* [gcc(refs/vendors/vrull/heads/for-upstream)] RISC-V: split to allow formation of sh[123]add before 32bit divw
@ 2022-11-18 11:34 Philipp Tomsich
  0 siblings, 0 replies; 3+ messages in thread
From: Philipp Tomsich @ 2022-11-18 11:34 UTC (permalink / raw)
  To: gcc-cvs

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

commit e3783003e67b550b9b1e82a0cc99c2bc1283f7f0
Author: Philipp Tomsich <philipp.tomsich@vrull.eu>
Date:   Tue Nov 8 20:45:51 2022 +0100

    RISC-V: split to allow formation of sh[123]add before 32bit divw
    
    When using strength-reduction, we will reduce a multiplication to a
    sequence of shifts and adds.  If this is performed with 32-bit types
    and followed by a division, the lack of w-form sh[123]add will make
    combination impossible and lead to a slli + addw being generated.
    
    Split the sequence with the knowledge that a w-form div will perform
    implicit sign-extensions.
    
    gcc/ChangeLog:
    
            * config/riscv/bitmanip.md: Add a define_split to optimize
              slliw + addiw + divw into sh[123]add + divw.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/riscv/zba-shNadd-05.c: New test.
    
    Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
    
    Series-to: gcc-patches@gcc.gnu.org
    Series-cc: Palmer Dabbelt <palmer@rivosinc.com>
    Series-cc: Vineet Gupta <vineetg@rivosinc.com>
    Series-cc: Christoph Muellner <christoph.muellner@vrull.eu>
    Series-cc: Kito Cheng <kito.cheng@gmail.com>
    Series-cc: Jeff Law <jlaw@ventanamicro.com>

Diff:
---
 gcc/config/riscv/bitmanip.md                   | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c | 11 +++++++++++
 2 files changed, 28 insertions(+)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index 2175c626ee5..ab411996398 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -39,6 +39,23 @@
   [(set_attr "type" "bitmanip")
    (set_attr "mode" "<X:MODE>")])
 
+; When using strength-reduction, we will reduce a multiplication to a
+; sequence of shifts and adds.  If this is performed with 32-bit types
+; and followed by a division, the lack of w-form sh[123]add will make
+; combination impossible and lead to a slli + addw being generated.
+; Split the sequence with the knowledge that a w-form div will perform
+; implicit sign-extensions.
+(define_split
+  [(set (match_operand:DI 0 "register_operand")
+	(sign_extend:DI (div:SI (plus:SI (subreg:SI (ashift:DI (match_operand:DI 1 "register_operand")
+							       (match_operand:QI 2 "imm123_operand")) 0)
+						    (subreg:SI (match_operand:DI 3 "register_operand") 0))
+		(subreg:SI (match_operand:DI 4 "register_operand") 0))))
+   (clobber (match_operand:DI 5 "register_operand"))]
+  "TARGET_64BIT && TARGET_ZBA"
+   [(set (match_dup 5) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
+    (set (match_dup 0) (sign_extend:DI (div:SI (subreg:SI (match_dup 5) 0) (subreg:SI (match_dup 4) 0))))])
+
 (define_insn "*shNadduw"
   [(set (match_operand:DI 0 "register_operand" "=r")
 	(plus:DI
diff --git a/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c b/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c
new file mode 100644
index 00000000000..271c3a8c0ac
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-Oz" "-Og" } } */
+
+long long f(int a, int b)
+{
+  return (a * 3) / b;
+}
+
+/* { dg-final { scan-assembler-times "sh1add\t" 1 } } */
+/* { dg-final { scan-assembler-times "divw\t" 1 } } */

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

* [gcc(refs/vendors/vrull/heads/for-upstream)] RISC-V: split to allow formation of sh[123]add before 32bit divw
@ 2022-11-17 22:24 Philipp Tomsich
  0 siblings, 0 replies; 3+ messages in thread
From: Philipp Tomsich @ 2022-11-17 22:24 UTC (permalink / raw)
  To: gcc-cvs

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

commit eed5fa208b0d1c7e0c46e5c37100768a130934d4
Author: Philipp Tomsich <philipp.tomsich@vrull.eu>
Date:   Tue Nov 8 20:45:51 2022 +0100

    RISC-V: split to allow formation of sh[123]add before 32bit divw
    
    When using strength-reduction, we will reduce a multiplication to a
    sequence of shifts and adds.  If this is performed with 32-bit types
    and followed by a division, the lack of w-form sh[123]add will make
    combination impossible and lead to a slli + addw being generated.
    
    Split the sequence with the knowledge that a w-form div will perform
    implicit sign-extensions.
    
    gcc/ChangeLog:
    
            * config/riscv/bitmanip.md: Add a define_split to optimize
              slliw + addiw + divw into sh[123]add + divw.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/riscv/zba-shNadd-05.c: New test.
    
    Signed-off-by: Philipp Tomsich <philipp.tomsich@vrull.eu>
    
    Series-to: gcc-patches@gcc.gnu.org
    Series-cc: Palmer Dabbelt <palmer@rivosinc.com>
    Series-cc: Vineet Gupta <vineetg@rivosinc.com>
    Series-cc: Christoph Muellner <christoph.muellner@vrull.eu>
    Series-cc: Kito Cheng <kito.cheng@gmail.com>
    Series-cc: Jeff Law <jlaw@ventanamicro.com>

Diff:
---
 gcc/config/riscv/bitmanip.md                   | 17 +++++++++++++++++
 gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c | 11 +++++++++++
 2 files changed, 28 insertions(+)

diff --git a/gcc/config/riscv/bitmanip.md b/gcc/config/riscv/bitmanip.md
index 2175c626ee5..ab411996398 100644
--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -39,6 +39,23 @@
   [(set_attr "type" "bitmanip")
    (set_attr "mode" "<X:MODE>")])
 
+; When using strength-reduction, we will reduce a multiplication to a
+; sequence of shifts and adds.  If this is performed with 32-bit types
+; and followed by a division, the lack of w-form sh[123]add will make
+; combination impossible and lead to a slli + addw being generated.
+; Split the sequence with the knowledge that a w-form div will perform
+; implicit sign-extensions.
+(define_split
+  [(set (match_operand:DI 0 "register_operand")
+	(sign_extend:DI (div:SI (plus:SI (subreg:SI (ashift:DI (match_operand:DI 1 "register_operand")
+							       (match_operand:QI 2 "imm123_operand")) 0)
+						    (subreg:SI (match_operand:DI 3 "register_operand") 0))
+		(subreg:SI (match_operand:DI 4 "register_operand") 0))))
+   (clobber (match_operand:DI 5 "register_operand"))]
+  "TARGET_64BIT && TARGET_ZBA"
+   [(set (match_dup 5) (plus:DI (ashift:DI (match_dup 1) (match_dup 2)) (match_dup 3)))
+    (set (match_dup 0) (sign_extend:DI (div:SI (subreg:SI (match_dup 5) 0) (subreg:SI (match_dup 4) 0))))])
+
 (define_insn "*shNadduw"
   [(set (match_operand:DI 0 "register_operand" "=r")
 	(plus:DI
diff --git a/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c b/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c
new file mode 100644
index 00000000000..271c3a8c0ac
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zba-shNadd-05.c
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-march=rv64gc_zba -mabi=lp64" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" "-O1" "-Os" "-Oz" "-Og" } } */
+
+long long f(int a, int b)
+{
+  return (a * 3) / b;
+}
+
+/* { dg-final { scan-assembler-times "sh1add\t" 1 } } */
+/* { dg-final { scan-assembler-times "divw\t" 1 } } */

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

end of thread, other threads:[~2022-11-18 11:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 14:00 [gcc(refs/vendors/vrull/heads/for-upstream)] RISC-V: split to allow formation of sh[123]add before 32bit divw Philipp Tomsich
2022-11-17 22:24 Philipp Tomsich
2022-11-18 11:34 Philipp Tomsich

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