• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revisão43435c7eb0ff60f02838674efd99df93852a92cc (tree)
Hora2022-11-14 00:47:20
AutorPhilipp Tomsich <philipp.tomsich@vrul...>
CommiterPhilipp Tomsich

Mensagem de Log

RISC-V: optimize '(a >= 0) ? b : 0' to srai + andn, if compiling for Zbb

If-conversion is turning '(a >= 0) ? b : 0' into a branchless sequence
not a5,a0
srai a5,a5,63
and a0,a1,a5
missing the opportunity to combine the NOT and AND into an ANDN.

This adds a define_split to help the combiner reassociate the NOT with
the AND.

gcc/ChangeLog:

* config/riscv/bitmanip.md: New define_split.

gcc/testsuite/ChangeLog:

* gcc.target/riscv/zbb-srai-andn.c: New test.

Mudança Sumário

Diff

--- a/gcc/config/riscv/bitmanip.md
+++ b/gcc/config/riscv/bitmanip.md
@@ -128,6 +128,19 @@
128128 [(set_attr "type" "bitmanip")
129129 (set_attr "mode" "<X:MODE>")])
130130
131+;; '(a >= 0) ? b : 0' is emitted branchless (from if-conversion). Without a
132+;; bit of extra help for combine (i.e., the below split), we end up emitting
133+;; not/srai/and instead of combining the not into an andn.
134+(define_split
135+ [(set (match_operand:DI 0 "register_operand")
136+ (and:DI (neg:DI (ge:DI (match_operand:DI 1 "register_operand")
137+ (const_int 0)))
138+ (match_operand:DI 2 "register_operand")))
139+ (clobber (match_operand:DI 3 "register_operand"))]
140+ "TARGET_ZBB"
141+ [(set (match_dup 3) (ashiftrt:DI (match_dup 1) (const_int 63)))
142+ (set (match_dup 0) (and:DI (not:DI (match_dup 3)) (match_dup 2)))])
143+
131144 (define_insn "*xor_not<mode>"
132145 [(set (match_operand:X 0 "register_operand" "=r")
133146 (not:X (xor:X (match_operand:X 1 "register_operand" "r")
--- /dev/null
+++ b/gcc/testsuite/gcc.target/riscv/zbb-srai-andn.c
@@ -0,0 +1,15 @@
1+/* { dg-do compile } */
2+/* { dg-options "-march=rv64gc_zbb -mabi=lp64" } */
3+/* { dg-skip-if "" { *-*-* } { "-O0" "-Og" "-Os" "-Oz" } } */
4+
5+long long foo0(long long a, long long b)
6+{
7+ if (a >= 0)
8+ return b;
9+
10+ return 0;
11+}
12+
13+/* { dg-final { scan-assembler-times "srai\t" 1 } } */
14+/* { dg-final { scan-assembler-times "andn\t" 1 } } */
15+