https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88926
Bug ID: 88926 Summary: ivopts with some NOP conversions Product: gcc Version: 9.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: enhancement Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: glisse at gcc dot gnu.org Target Milestone: --- Starting from gcc.dg/tree-ssa/ivopts-lt-2.c: /* { dg-do compile } */ /* { dg-options "-O2 -fdump-tree-ivopts" } */ /* { dg-skip-if "PR68644" { hppa*-*-* powerpc*-*-* } } */ void f1 (int *p, unsigned int i) { p += i; do { *p = 0; p += 1; i++; } while (i < 100); } /* { dg-final { scan-tree-dump-times "PHI" 1 "ivopts" } } */ /* { dg-final { scan-tree-dump-times "PHI <p_" 1 "ivopts"} } */ /* { dg-final { scan-tree-dump-times "p_\[0-9\]* <" 1 "ivopts" } } */ ivopts normally manages to get rid of i in the loop. However, if I replace "p += i" with __PTRDIFF_TYPE__ o = i; o *= 4; p = (char*)p + o; (i.e. I compute i*4 in type 'long' instead of 'unsigned long') ivopts doesn't find an invariant and doesn't eliminate i anymore. This will be useful if I try to resurrect https://gcc.gnu.org/ml/gcc-patches/2017-05/msg01641.html . I am not familiar with ivopts (I don't see why the instruction p+=i is relevant, it only changes the initial value of p, but without it we do not eliminate either) so this is likely one of the last cases I'll try to fix.