Fix ctz issues (PR93231)
authorWilco Dijkstra <wdijkstr@arm.com>
Wed, 15 Jan 2020 15:23:54 +0000 (15:23 +0000)
committerWilco Dijkstra <wdijkstr@arm.com>
Wed, 15 Jan 2020 18:38:21 +0000 (18:38 +0000)
commitbc071d3a951a98284a3f46043afd44c03c123376
tree4fdacca959bb6ac3ad5a46af26c642f9a675a959
parent2a0f6c61b4db19535c632be68bddad74b6adb6cf
Fix ctz issues (PR93231)

Further improve the ctz recognition: Avoid ICEing on negative shift
counts or multiply constants.  Check the type is a char type for the
string constant case to avoid accidentally matching a wide STRING_CST.
Add a tree_expr_nonzero_p check to allow the optimization even if
CTZ_DEFINED_VALUE_AT_ZERO returns 0 or 1.  Add extra test cases.

Bootstrap OK on AArch64 and x64.

    gcc/
PR tree-optimization/93231
* tree-ssa-forwprop.c (optimize_count_trailing_zeroes): Check
input_type is unsigned.  Use tree_to_shwi for shift constant.
Check CST_STRING element size is CHAR_TYPE_SIZE bits.
(simplify_count_trailing_zeroes): Add test to handle known non-zero
inputs more efficiently.

    testsuite/
PR tree-optimization/93231
* gcc.dg/pr90838.c: New test.
* gcc.dg/pr93231.c: New test.
* gcc.target/aarch64/pr90838.c: Use #define u 0.
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr90838.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/pr93231.c [new file with mode: 0644]
gcc/testsuite/gcc.target/aarch64/pr90838.c
gcc/tree-ssa-forwprop.c