]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end: fix 0 offset creation and folding [PR115936]
authorTamar Christina <tamar.christina@arm.com>
Wed, 17 Jul 2024 15:22:14 +0000 (16:22 +0100)
committerTamar Christina <tamar.christina@arm.com>
Wed, 17 Jul 2024 15:22:14 +0000 (16:22 +0100)
As shown in PR115936 SCEV and IVOPTS create an invalidate IV when the IV is
a pointer type:

ivtmp.39_65 = ivtmp.39_59 + 0B;

where the IVs are DI mode and the offset is a pointer.
This comes from this weird candidate:

Candidate 8:
  Var befor: ivtmp.39_59
  Var after: ivtmp.39_65
  Incr POS: before exit test
  IV struct:
    Type:       sizetype
    Base:       0
    Step:       0B
    Biv:        N
    Overflowness wrto loop niter:       No-overflow

This IV was always created just ended up not being used.

This is created by SCEV.

simple_iv_with_niters in the case where no CHREC is found creates an IV with
base == ev, offset == 0;

however in this case EV is a POINTER_PLUS_EXPR and so the type is a pointer.
it ends up creating an unusable expression.

gcc/ChangeLog:

PR tree-optimization/115936
* tree-scalar-evolution.cc (simple_iv_with_niters): Use sizetype for
pointers.

gcc/tree-scalar-evolution.cc

index 5aa95a2497a317f9b43408ce78a2d50c20151314..abb2bad777375889d6c980b54d60699672fd5742 100644 (file)
@@ -3243,7 +3243,11 @@ simple_iv_with_niters (class loop *wrto_loop, class loop *use_loop,
   if (tree_does_not_contain_chrecs (ev))
     {
       iv->base = ev;
-      iv->step = build_int_cst (TREE_TYPE (ev), 0);
+      tree ev_type = TREE_TYPE (ev);
+      if (POINTER_TYPE_P (ev_type))
+       ev_type = sizetype;
+
+      iv->step = build_int_cst (ev_type, 0);
       iv->no_overflow = true;
       return true;
     }