This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
| Other format: | [Raw text] | |
Some of the new AMDFAM10 patterns recently added to i386.md by Harsha
contained the interesting RTL:
(set (reg FLAGS_REG)
(compare
(popcount:SI (match_operand:SI 1 "nonimmediate_operand" "rm"))
(const_int 0)))
What's most interesting about this to the RTL optimizers, is that with a
little thought it should be possible to simplify or optimize away all
comparisons of __builtin_popcount against zero as follows:
(eq (popcount x) 0) -> (eq x 0)
(ne (popcount x) 0) -> (ne x 0)
(lt (popcount x) 0) -> false
(ltu (popcount x) 0) -> false
(le (popcount x) 0) -> (eq x 0)
(leu (popcount x) 0) -> (eq x 0)
(gt (popcount x) 0) -> (ne x 0)
(gtu (popcount x) 0) -> (ne x 0)
(ge (popcount x) 0) -> true
(geu (popcount x) 0) -> true
The following patch implements the transformations above not already
performed by the compiler.
The following patch has been tested on both i686-pc-linux-gnu and
ia64-unknown-linux-gnu with a full "make bootstrap", all default languages
(including Ada on IA-32), and regression tested with a top-level "make -k
check" with no new failures. The new testcases confirm that we emit the
Itanium's "popcnt" instruction for __builtin_popcount, but that we can
optimize it away when used as "__builtin_popcount(x) == 0".
Committed to mainline as revision 121838.
2007-02-11 Roger Sayle <roger@eyesopen.com>
* simplify-rtx.c (simplify_relational_operation_1): Optimize
comparisons of POPCOUNT against zero.
(simplify_const_relational_operation): Likewise.
* gcc.target/ia64/builtin-popcount-1.c: New test case.
* gcc.target/ia64/builtin-popcount-2.c: Likewise.
Roger
--
Attachment:
patchp.txt
Description: Text document
Attachment:
builtin-popcount-1.c
Description: Text document
Attachment:
builtin-popcount-2.c
Description: Text document
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |