The following enhances chrec_fold_plus_1 to handle a case to avoid
ICEing during GRAPHITE code-gen. It teaches us to handle
(signed T) { (T) x, +, y } + (signed T) z as
(signed T) ( { (T) x, +, y } + (T) (singed T) z ) instead of
failing with chrec_not_known.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.
Richard.
2018-01-24 Richard Biener <[email protected]>
PR tree-optimization/83176
* tree-chrec.c (chrec_fold_plus_1): Handle (signed T){(T) .. }
operands.
* gcc.dg/graphite/pr83176.c: New testcase.
Index: gcc/tree-chrec.c
===================================================================
--- gcc/tree-chrec.c (revision 256977)
+++ gcc/tree-chrec.c (working copy)
@@ -295,8 +295,23 @@ chrec_fold_plus_1 (enum tree_code code,
return chrec_fold_plus_poly_poly (code, type, op0, op1);
CASE_CONVERT:
- if (tree_contains_chrecs (op1, NULL))
- return chrec_dont_know;
+ {
+ /* We can strip sign-conversions to signed by performing the
+ operation in unsigned. */
+ tree optype = TREE_TYPE (TREE_OPERAND (op1, 0));
+ if (INTEGRAL_TYPE_P (type)
+ && INTEGRAL_TYPE_P (optype)
+ && tree_nop_conversion_p (type, optype)
+ && TYPE_UNSIGNED (optype))
+ return chrec_convert (type,
+ chrec_fold_plus_1 (code, optype,
+ chrec_convert (optype,
+ op0,
NULL),
+ TREE_OPERAND (op1, 0)),
+ NULL);
+ if (tree_contains_chrecs (op1, NULL))
+ return chrec_dont_know;
+ }
/* FALLTHRU */
default:
@@ -313,8 +328,23 @@ chrec_fold_plus_1 (enum tree_code code,
}
CASE_CONVERT:
- if (tree_contains_chrecs (op0, NULL))
- return chrec_dont_know;
+ {
+ /* We can strip sign-conversions to signed by performing the
+ operation in unsigned. */
+ tree optype = TREE_TYPE (TREE_OPERAND (op0, 0));
+ if (INTEGRAL_TYPE_P (type)
+ && INTEGRAL_TYPE_P (optype)
+ && tree_nop_conversion_p (type, optype)
+ && TYPE_UNSIGNED (optype))
+ return chrec_convert (type,
+ chrec_fold_plus_1 (code, optype,
+ TREE_OPERAND (op0, 0),
+ chrec_convert (optype,
+ op1, NULL)),
+ NULL);
+ if (tree_contains_chrecs (op0, NULL))
+ return chrec_dont_know;
+ }
/* FALLTHRU */
default:
Index: gcc/testsuite/gcc.dg/graphite/pr83176.c
===================================================================
--- gcc/testsuite/gcc.dg/graphite/pr83176.c (nonexistent)
+++ gcc/testsuite/gcc.dg/graphite/pr83176.c (working copy)
@@ -0,0 +1,42 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -floop-nest-optimize" } */
+
+int wx, qi;
+
+void
+yj (int gw)
+{
+ int *ak = &gw;
+
+ while (wx != 0)
+ {
+ int k2 = (__INTPTR_TYPE__)&ak;
+ int **xq = (int **)&k2;
+
+ja:
+ *xq = &gw;
+
+ while (qi < 1)
+ {
+ unsigned short int ey;
+
+be:
+ for (ey = 0; ey < 251; ++ey)
+ {
+ for (wx = 0; wx < 2; ++wx)
+ {
+ }
+
+ *ak += 8555712;
+ k2 += *ak;
+ }
+ ++qi;
+ }
+ }
+
+ gw = 1;
+ if (gw != 0)
+ goto ja;
+ else
+ goto be;
+}