Commit 7e7091b
arc: Add const attribute support for mathematical ARC builtins
The ARC builtin functions __builtin_arc_ffs and __builtin_arc_fls
perform pure mathematical operations equivalent to the standard
GCC __builtin_ffs function, which is marked with the const attribute.
However, the ARC target-specific versions were not marked as const,
preventing compiler optimizations like common subexpression elimination.
Extend the ARC builtin infrastructure to support function attributes
and mark the appropriate mathematical builtins as const:
- __builtin_arc_ffs: Find first set bit (const)
- __builtin_arc_fls: Find last set bit (const)
- __builtin_arc_norm: Count leading zeros (const)
- __builtin_arc_normw: Count leading zeros for 16-bit (const)
- __builtin_arc_swap: Endian swap (const)
gcc/ChangeLog:
* config/arc/builtins.def: Add ATTRS parameter to DEF_BUILTIN
macro calls. Mark mathematical builtins (FFS, FLS, NORM, NORMW,
SWAP) with attr_const, leave others as NULL_TREE.
* config/arc/arc.cc: Add support for builtin function attributes.
Create attr_const using tree_cons. Update DEF_BUILTIN macro to
pass ATTRS parameter to add_builtin_function.
gcc/testsuite/ChangeLog:
* gcc.target/arc/builtin_fls_const.c: New test. Verify that
const attribute enables CSE optimization for mathematical ARC
builtins by checking that duplicate calls are eliminated and
results are optimized to shift operations.
Signed-off-by: Kees Cook <kees@kernel.org>1 parent 7fa8420 commit 7e7091b
File tree
3 files changed
+197
-157
lines changed- gcc
- config/arc
- testsuite/gcc.target/arc
3 files changed
+197
-157
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6705 | 6705 | | |
6706 | 6706 | | |
6707 | 6707 | | |
6708 | | - | |
| 6708 | + | |
6709 | 6709 | | |
6710 | 6710 | | |
6711 | 6711 | | |
| |||
6723 | 6723 | | |
6724 | 6724 | | |
6725 | 6725 | | |
6726 | | - | |
| 6726 | + | |
6727 | 6727 | | |
6728 | 6728 | | |
6729 | 6729 | | |
| |||
6855 | 6855 | | |
6856 | 6856 | | |
6857 | 6857 | | |
| 6858 | + | |
| 6859 | + | |
| 6860 | + | |
6858 | 6861 | | |
6859 | | - | |
| 6862 | + | |
6860 | 6863 | | |
6861 | 6864 | | |
6862 | 6865 | | |
| |||
6866 | 6869 | | |
6867 | 6870 | | |
6868 | 6871 | | |
6869 | | - | |
| 6872 | + | |
6870 | 6873 | | |
6871 | 6874 | | |
6872 | 6875 | | |
| |||
0 commit comments