https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99777

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
So, one thing is that tree-affine.c during store motion alias analysis feeds
very questionable expressions to the folder, in particular it attempts to fold
MULT_EXPR of (sizetype) (vector(4) short int *) ((int) ivtmp.46_14 * 3)
where ivtmp.46_14 is unsigned int, and (sizetype) -1.
Note e.g. the cast from int to pointer of different size, or pointer back to
sizetype.

And another thing is that extract_muldiv{,_1} really relies on integral types
only, is called when the divisor or second multiplication operand is
INTEGER_CST and the multiplication/division aren't defined for other types that
represent
constants as INTEGER_CST (e.g. pointers, NULLPTR_TYPE etc.).  Vector types
really should use VECTOR_CSTs...

The ICE can be fixed with:
--- gcc/fold-const.c.jj 2021-03-25 13:41:55.000000000 +0100
+++ gcc/fold-const.c    2021-03-26 11:51:57.901091895 +0100
@@ -6713,6 +6713,8 @@ extract_muldiv_1 (tree t, tree c, enum t
       break;

     CASE_CONVERT: case NON_LVALUE_EXPR:
+      if (!INTEGRAL_TYPE_P (TREE_TYPE (op0)))
+       break;
       /* If op0 is an expression ...  */
       if ((COMPARISON_CLASS_P (op0)
           || UNARY_CLASS_P (op0)
@@ -6721,8 +6723,7 @@ extract_muldiv_1 (tree t, tree c, enum t
           || EXPRESSION_CLASS_P (op0))
          /* ... and has wrapping overflow, and its type is smaller
             than ctype, then we cannot pass through as widening.  */
-         && (((ANY_INTEGRAL_TYPE_P (TREE_TYPE (op0))
-               && TYPE_OVERFLOW_WRAPS (TREE_TYPE (op0)))
+         && ((TYPE_OVERFLOW_WRAPS (TREE_TYPE (op0))
               && (TYPE_PRECISION (ctype)
                   > TYPE_PRECISION (TREE_TYPE (op0))))
              /* ... or this is a truncation (t is narrower than op0),
@@ -6737,8 +6738,7 @@ extract_muldiv_1 (tree t, tree c, enum t
              /* ... or has undefined overflow while the converted to
                 type has not, we cannot do the operation in the inner type
                 as that would introduce undefined overflow.  */
-             || ((ANY_INTEGRAL_TYPE_P (TREE_TYPE (op0))
-                  && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (op0)))
+             || (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (op0))
                  && !TYPE_OVERFLOW_UNDEFINED (type))))
        break;

Reply via email to