[PATCH] Fix PR83580
Richard Biener
rguenther@suse.de
Mon Jan 8 09:20:00 GMT 2018
The following fixes PR83580, split_constant_offset is a somewhat odd
beast, replicating SCEV code and tree-affine a bit. It also got
similar tricks as those with regarding to looking through conversions
but while being pedantic about overflow it simply strips sign-conversions.
That's of course wrong, thus the following patch removes that.
I do expect eventual fallout (in missed optimizations), so it needs
some baking on trunk before backporting.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
Richard.
2018-01-08 Richard Biener <rguenther@suse.de>
PR middle-end/83580
* tree-data-ref.c (split_constant_offset): Remove STRIP_NOPS.
* gcc.dg/torture/pr83580.c: New testcase.
Index: gcc/tree-data-ref.c
===================================================================
--- gcc/tree-data-ref.c (revision 256275)
+++ gcc/tree-data-ref.c (working copy)
@@ -723,23 +723,21 @@ split_constant_offset_1 (tree type, tree
void
split_constant_offset (tree exp, tree *var, tree *off)
{
- tree type = TREE_TYPE (exp), otype, op0, op1, e, o;
+ tree type = TREE_TYPE (exp), op0, op1, e, o;
enum tree_code code;
*var = exp;
*off = ssize_int (0);
- STRIP_NOPS (exp);
if (tree_is_chrec (exp)
|| get_gimple_rhs_class (TREE_CODE (exp)) == GIMPLE_TERNARY_RHS)
return;
- otype = TREE_TYPE (exp);
code = TREE_CODE (exp);
extract_ops_from_tree (exp, &code, &op0, &op1);
- if (split_constant_offset_1 (otype, op0, code, op1, &e, &o))
+ if (split_constant_offset_1 (type, op0, code, op1, &e, &o))
{
- *var = fold_convert (type, e);
+ *var = e;
*off = o;
}
}
Index: gcc/testsuite/gcc.dg/torture/pr83580.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr83580.c (nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr83580.c (working copy)
@@ -0,0 +1,16 @@
+/* { dg-do run } */
+
+int a[2] = { 0, 1 };
+int x = 129;
+
+int
+main ()
+{
+ volatile int v = 0;
+ int t = x, i;
+ for (i = 0; i < 1 + v + v + v + v + v + v + v + v + a[a[0]]; i++)
+ t = a[(signed char) (130 - x)];
+ if (t != 1)
+ __builtin_abort ();
+ return 0;
+}
More information about the Gcc-patches
mailing list