]> git.ipfire.org Git - thirdparty/gcc.git/commit - gcc/config/arc/arc.cc
ARC: Provide a TARGET_FOLD_BUILTIN target hook.
authorRoger Sayle <roger@nextmovesoftware.com>
Mon, 13 Nov 2023 09:11:42 +0000 (09:11 +0000)
committerRoger Sayle <roger@nextmovesoftware.com>
Mon, 13 Nov 2023 09:11:42 +0000 (09:11 +0000)
commite9d59a2a5a8e8ce667847372cc480215fa862aa4
treec7ec6f4663a575f1c94651e4bdbe34b689550fba
parent0a140730c970870a5125beb1114f6c01679a040e
ARC: Provide a TARGET_FOLD_BUILTIN target hook.

This patch implements a arc_fold_builtin target hook to allow ARC
builtins to be folded at the tree-level.  Currently this function
converts __builtin_arc_swap into a LROTATE_EXPR at the tree-level,
and evaluates __builtin_arc_norm and __builtin_arc_normw of integer
constant arguments at compile-time.  Because ARC_BUILTIIN_SWAP is
now handled at the tree-level, UNSPEC_ARC_SWAP no longer used,
allowing it and the "swap" define_insn to be removed.

An example benefit of folding things at compile-time is that
calling __builtin_arc_swap on the result of __builtin_arc_swap
now eliminates both and generates no code, and likewise calling
__builtin_arc_swap of a constant integer argument is evaluated
at compile-time.

2023-11-13  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* config/arc/arc.cc (TARGET_FOLD_BUILTIN): Define to
arc_fold_builtin.
(arc_fold_builtin): New function.  Convert ARC_BUILTIN_SWAP
into a rotate.  Evaluate ARC_BUILTIN_NORM and
ARC_BUILTIN_NORMW of constant arguments.
* config/arc/arc.md (UNSPEC_ARC_SWAP): Delete.
(normw): Make output template/assembler whitespace consistent.
(swap): Remove define_insn, only use of SWAP UNSPEC.
* config/arc/builtins.def: Tweak indentation.
(SWAP): Expand using rotlsi2_cnt16 instead of using swap.

gcc/testsuite/ChangeLog
* gcc.target/arc/builtin_norm-1.c: New test case.
* gcc.target/arc/builtin_norm-2.c: Likewise.
* gcc.target/arc/builtin_normw-1.c: Likewise.
* gcc.target/arc/builtin_normw-2.c: Likewise.
* gcc.target/arc/builtin_swap-1.c: Likewise.
* gcc.target/arc/builtin_swap-2.c: Likewise.
* gcc.target/arc/builtin_swap-3.c: Likewise.
gcc/config/arc/arc.cc
gcc/config/arc/arc.md
gcc/config/arc/builtins.def
gcc/testsuite/gcc.target/arc/builtin_norm-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arc/builtin_norm-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arc/builtin_normw-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arc/builtin_normw-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arc/builtin_swap-1.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arc/builtin_swap-2.c [new file with mode: 0644]
gcc/testsuite/gcc.target/arc/builtin_swap-3.c [new file with mode: 0644]