This patch fixes an ICE compiling fast-math-pr55281.c for amdgcn.

The problem is that an "iv" is created in which both base and step are pointer types, but the base is converted to sizetype without also converting the step to a non-pointer type. Later in the compilation this results in a PLUS_EXPR with a pointer argument, which is invalid gimple.

The patch fixes the problem by ensuring that the step is converted at the same point the base is. This seems like it ought to be correct. If the step is not a pointer type then no conversion occurs.

I don't really understand why I only see this issue on amdgcn, but it might be because the pointer in question is in a MASK_LOAD which is perhaps not that commonly used?

I've tested this on amdgcn, and done a full bootstrap and test on x86_64 also.

OK to commit?

Thanks

Andrew
Fix fast-math-pr55281.c ICE.

2020-01-28  Andrew Stubbs  <a...@codesourcery.com>

	gcc/
	* tree-ssa-loop-ivopts.c (add_iv_candidate_for_use): Convert step to
	basestep similarly to basetype.

diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index a21f3077e74..1abeb13bb53 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -3472,7 +3472,7 @@ add_iv_candidate_for_use (struct ivopts_data *data, struct iv_use *use)
 {
   poly_uint64 offset;
   tree base;
-  tree basetype;
+  tree basetype, basestep;
   struct iv *iv = use->iv;
 
   add_candidate (data, iv->base, iv->step, false, use);
@@ -3482,9 +3482,14 @@ add_iv_candidate_for_use (struct ivopts_data *data, struct iv_use *use)
 
   /* Record common candidate with initial value zero.  */
   basetype = TREE_TYPE (iv->base);
+  basestep = iv->step;
   if (POINTER_TYPE_P (basetype))
-    basetype = sizetype;
-  record_common_cand (data, build_int_cst (basetype, 0), iv->step, use);
+    {
+      basetype = sizetype;
+      if (POINTER_TYPE_P (TREE_TYPE (iv->step)))
+	basestep = fold_convert (basetype, iv->step);
+    }
+  record_common_cand (data, build_int_cst (basetype, 0), basestep, use);
 
   /* Compare the cost of an address with an unscaled index with the cost of
     an address with a scaled index and add candidate if useful.  */

Reply via email to