aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>2013-09-17 13:29:41 +0000
committerKyrylo Tkachov <ktkachov@gcc.gnu.org>2013-09-17 13:29:41 +0000
commite3d3cfb4a5ac9560c78662c36568fde2675b201f (patch)
treec7ad9c99c8373202fc0c56229c3ab24d5189bba2 /gcc
parent4fce5f027cf84b6237b6f7d90b3b00f7ab7ca4d4 (diff)
downloadgcc-e3d3cfb4a5ac9560c78662c36568fde2675b201f.zip
gcc-e3d3cfb4a5ac9560c78662c36568fde2675b201f.tar.gz
gcc-e3d3cfb4a5ac9560c78662c36568fde2675b201f.tar.bz2
re PR tree-optimization/58088 (ICE in gcc.c)
[gcc/] 2013-09-17 Kyrylo Tkachov <kyrylo.tkachov@arm.com> PR tree-optimization/58088 * fold-const.c (mask_with_trailing_zeros): New function. (fold_binary_loc): Make sure we don't recurse infinitely when the X in (X & C1) | C2 is a tree of the form (Y * K1) & K2. Use mask_with_trailing_zeros where appropriate. [gcc/testsuite] 2013-09-17 Kyrylo Tkachov <kyrylo.tkachov@arm.com> PR tree-optimization/58088 * gcc.c-torture/compile/pr58088.c: New test. From-SVN: r202652
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog8
-rw-r--r--gcc/fold-const.c62
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/pr58088.c5
4 files changed, 63 insertions, 17 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index e05412a..16e7ae2 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,11 @@
+2013-09-17 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
+
+ PR tree-optimization/58088
+ * fold-const.c (mask_with_trailing_zeros): New function.
+ (fold_binary_loc): Make sure we don't recurse infinitely
+ when the X in (X & C1) | C2 is a tree of the form (Y * K1) & K2.
+ Use mask_with_trailing_zeros where appropriate.
+
2013-09-17 Yuri Rumyantsev <ysrumyan@gmail.com>
* config/i386/i386.c (distance_agu_use_in_bb) : Proper initialization
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index c70437b..d23c173 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -9942,6 +9942,24 @@ exact_inverse (tree type, tree cst)
}
}
+/* Mask out the tz least significant bits of X of type TYPE where
+ tz is the number of trailing zeroes in Y. */
+static double_int
+mask_with_tz (tree type, double_int x, double_int y)
+{
+ int tz = y.trailing_zeros ();
+
+ if (tz > 0)
+ {
+ double_int mask;
+
+ mask = ~double_int::mask (tz);
+ mask = mask.ext (TYPE_PRECISION (type), TYPE_UNSIGNED (type));
+ return mask & x;
+ }
+ return x;
+}
+
/* Fold a binary expression of code CODE and type TYPE with operands
OP0 and OP1. LOC is the location of the resulting expression.
Return the folded expression if folding is successful. Otherwise,
@@ -11266,6 +11284,8 @@ fold_binary_loc (location_t loc,
{
double_int c1, c2, c3, msk;
int width = TYPE_PRECISION (type), w;
+ bool try_simplify = true;
+
c1 = tree_to_double_int (TREE_OPERAND (arg0, 1));
c2 = tree_to_double_int (arg1);
@@ -11300,7 +11320,21 @@ fold_binary_loc (location_t loc,
break;
}
}
- if (c3 != c1)
+
+ /* If X is a tree of the form (Y * K1) & K2, this might conflict
+ with that optimization from the BIT_AND_EXPR optimizations.
+ This could end up in an infinite recursion. */
+ if (TREE_CODE (TREE_OPERAND (arg0, 0)) == MULT_EXPR
+ && TREE_CODE (TREE_OPERAND (TREE_OPERAND (arg0, 0), 1))
+ == INTEGER_CST)
+ {
+ tree t = TREE_OPERAND (TREE_OPERAND (arg0, 0), 1);
+ double_int masked = mask_with_tz (type, c3, tree_to_double_int (t));
+
+ try_simplify = (masked != c1);
+ }
+
+ if (try_simplify && c3 != c1)
return fold_build2_loc (loc, BIT_IOR_EXPR, type,
fold_build2_loc (loc, BIT_AND_EXPR, type,
TREE_OPERAND (arg0, 0),
@@ -11690,22 +11724,16 @@ fold_binary_loc (location_t loc,
&& TREE_CODE (arg0) == MULT_EXPR
&& TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
{
- int arg1tz
- = tree_to_double_int (TREE_OPERAND (arg0, 1)).trailing_zeros ();
- if (arg1tz > 0)
- {
- double_int arg1mask, masked;
- arg1mask = ~double_int::mask (arg1tz);
- arg1mask = arg1mask.ext (TYPE_PRECISION (type),
- TYPE_UNSIGNED (type));
- masked = arg1mask & tree_to_double_int (arg1);
- if (masked.is_zero ())
- return omit_two_operands_loc (loc, type, build_zero_cst (type),
- arg0, arg1);
- else if (masked != tree_to_double_int (arg1))
- return fold_build2_loc (loc, code, type, op0,
- double_int_to_tree (type, masked));
- }
+ double_int masked
+ = mask_with_tz (type, tree_to_double_int (arg1),
+ tree_to_double_int (TREE_OPERAND (arg0, 1)));
+
+ if (masked.is_zero ())
+ return omit_two_operands_loc (loc, type, build_zero_cst (type),
+ arg0, arg1);
+ else if (masked != tree_to_double_int (arg1))
+ return fold_build2_loc (loc, code, type, op0,
+ double_int_to_tree (type, masked));
}
/* For constants M and N, if M == (1LL << cst) - 1 && (N & M) == M,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 48f6256..a7b90f0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2013-09-17 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
+
+ PR tree-optimization/58088
+ * gcc.c-torture/compile/pr58088.c: New test.
+
2013-09-17 Nick Clifton <nickc@redhat.com>
* lib/target-supports.exp (check_effective_target_trampolines):
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr58088.c b/gcc/testsuite/gcc.c-torture/compile/pr58088.c
new file mode 100644
index 0000000..07a9c68
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr58088.c
@@ -0,0 +1,5 @@
+int
+bar (int i)
+{
+ return 1 | ((i * 2) & 254);
+}