aboutsummaryrefslogtreecommitdiff
path: root/gcc/match.pd
diff options
context:
space:
mode:
authorHans-Peter Nilsson <hp@axis.com>2021-02-16 22:27:53 +0100
committerHans-Peter Nilsson <hp@axis.com>2021-02-18 13:19:08 +0100
commita2ef38b1f94dd108046e702ad46dcd8e9b34625e (patch)
tree420219e9af3ec6e6a11346524ba24eec8678f761 /gcc/match.pd
parenta1541628df83eb690954f426d56d268fb57f1af6 (diff)
downloadgcc-a2ef38b1f94dd108046e702ad46dcd8e9b34625e.zip
gcc-a2ef38b1f94dd108046e702ad46dcd8e9b34625e.tar.gz
gcc-a2ef38b1f94dd108046e702ad46dcd8e9b34625e.tar.bz2
match.pd: Restrict clz cmp 0 replacement by single_use, PR99142
If we're not going to eliminate the clz, it's better for the comparison to use that result than its input, so we don't extend the lifetime of the input. Also, an additional use of the result is more likely cheaper than a compare of the input, in particular considering that the clz may have made available a non-zero condition matching the original use. The "s" modifier doesn't stop this situation, as the transformation wouldn't result in "an expression with more than one operator"; a gating single_use condition on the result is necessary. gcc: PR tree-optimization/99142 * match.pd (clz cmp 0): Gate replacement on single_use of clz result. gcc/testsuite: PR tree-optimization/99142 * gcc.dg/tree-ssa/pr99142.c: New test.
Diffstat (limited to 'gcc/match.pd')
-rw-r--r--gcc/match.pd4
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/match.pd b/gcc/match.pd
index e14f697..760f773 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -6315,8 +6315,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(for op (eq ne)
cmp (lt ge)
(simplify
- (op (clz:s @0) INTEGER_CST@1)
- (if (integer_zerop (@1))
+ (op (clz:s@2 @0) INTEGER_CST@1)
+ (if (integer_zerop (@1) && single_use (@2))
/* clz(X) == 0 is (int)X < 0 and clz(X) != 0 is (int)X >= 0. */
(with { tree stype = signed_type_for (TREE_TYPE (@0));
HOST_WIDE_INT val = 0;