Message ID | 20220121092208.3086415-1-guojiufu@linux.ibm.com |
---|---|
State | New |
Headers | show |
Series | Update the type of control.base after changed | expand |
On Fri, 21 Jan 2022, Jiufu Guo wrote: > Hi, > > This patch correct the type of niter->control.base, when it is updated > as a PLUS expr. > During build PLUS expr, the result type should align with the type of > the operands. > > Bootstrap and regtest pass on ppc64/ppc64le and x86. > Is this ok for trunk? OK. Thanks, Richard. > BR, > Jiufu > > > PR tree-optimization/102087 > > gcc/ChangeLog: > > * tree-ssa-loop-niter.c (number_of_iterations_until_wrap): > Correct PLUS result type. > > gcc/testsuite/ChangeLog: > > * gcc.dg/pr102087_1.c: New test. > > --- > gcc/tree-ssa-loop-niter.c | 17 +++++++++++++++-- > gcc/testsuite/gcc.dg/pr102087_1.c | 13 +++++++++++++ > 2 files changed, 28 insertions(+), 2 deletions(-) > create mode 100644 gcc/testsuite/gcc.dg/pr102087_1.c > > diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c > index b767056aeb0..21cc257c91b 100644 > --- a/gcc/tree-ssa-loop-niter.c > +++ b/gcc/tree-ssa-loop-niter.c > @@ -1579,8 +1579,21 @@ number_of_iterations_until_wrap (class loop *loop, tree type, affine_iv *iv0, > { IVbase - STEP, +, STEP } != bound > Here, biasing IVbase by 1 step makes 'bound' be the value before wrap. > */ > - niter->control.base = fold_build2 (MINUS_EXPR, niter_type, > - niter->control.base, niter->control.step); > + tree base_type = TREE_TYPE (niter->control.base); > + if (POINTER_TYPE_P (base_type)) > + { > + tree utype = unsigned_type_for (base_type); > + niter->control.base > + = fold_build2 (MINUS_EXPR, utype, > + fold_convert (utype, niter->control.base), > + fold_convert (utype, niter->control.step)); > + niter->control.base = fold_convert (base_type, niter->control.base); > + } > + else > + niter->control.base > + = fold_build2 (MINUS_EXPR, base_type, niter->control.base, > + niter->control.step); > + > span = fold_build2 (MULT_EXPR, niter_type, niter->niter, > fold_convert (niter_type, niter->control.step)); > niter->bound = fold_build2 (PLUS_EXPR, niter_type, span, > diff --git a/gcc/testsuite/gcc.dg/pr102087_1.c b/gcc/testsuite/gcc.dg/pr102087_1.c > new file mode 100644 > index 00000000000..ba4efe3b412 > --- /dev/null > +++ b/gcc/testsuite/gcc.dg/pr102087_1.c > @@ -0,0 +1,13 @@ > +/* PR tree-optimization/102087 */ > +/* { dg-do compile } */ > +/* { dg-options "-O3 -fprefetch-loop-arrays -w" { target x86_64-*-* powerpc*-*-* } } */ > + > +char **Gif_ClipImage_gfi_0; > +int Gif_ClipImage_gfi_1, Gif_ClipImage_y, Gif_ClipImage_shift; > +void Gif_ClipImage() { > + Gif_ClipImage_y = Gif_ClipImage_gfi_1 - 1; > + for (; Gif_ClipImage_y >= Gif_ClipImage_shift; Gif_ClipImage_y++) > + Gif_ClipImage_gfi_0[Gif_ClipImage_shift] = > + Gif_ClipImage_gfi_0[Gif_ClipImage_y]; > +} > + >
Richard Biener <rguenther@suse.de> writes: > On Fri, 21 Jan 2022, Jiufu Guo wrote: > >> Hi, >> >> This patch correct the type of niter->control.base, when it is updated >> as a PLUS expr. >> During build PLUS expr, the result type should align with the type of >> the operands. >> >> Bootstrap and regtest pass on ppc64/ppc64le and x86. >> Is this ok for trunk? > > OK. > > Thanks, > Richard. Thanks! committed as r12-6834. BR, Jiufu > >> BR, >> Jiufu >> >> >> PR tree-optimization/102087 >> >> gcc/ChangeLog: >> >> * tree-ssa-loop-niter.c (number_of_iterations_until_wrap): >> Correct PLUS result type. >> >> gcc/testsuite/ChangeLog: >> >> * gcc.dg/pr102087_1.c: New test. >> >> --- >> gcc/tree-ssa-loop-niter.c | 17 +++++++++++++++-- >> gcc/testsuite/gcc.dg/pr102087_1.c | 13 +++++++++++++ >> 2 files changed, 28 insertions(+), 2 deletions(-) >> create mode 100644 gcc/testsuite/gcc.dg/pr102087_1.c >> >> diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c >> index b767056aeb0..21cc257c91b 100644 >> --- a/gcc/tree-ssa-loop-niter.c >> +++ b/gcc/tree-ssa-loop-niter.c >> @@ -1579,8 +1579,21 @@ number_of_iterations_until_wrap (class loop *loop, tree type, affine_iv *iv0, >> { IVbase - STEP, +, STEP } != bound >> Here, biasing IVbase by 1 step makes 'bound' be the value before wrap. >> */ >> - niter->control.base = fold_build2 (MINUS_EXPR, niter_type, >> - niter->control.base, niter->control.step); >> + tree base_type = TREE_TYPE (niter->control.base); >> + if (POINTER_TYPE_P (base_type)) >> + { >> + tree utype = unsigned_type_for (base_type); >> + niter->control.base >> + = fold_build2 (MINUS_EXPR, utype, >> + fold_convert (utype, niter->control.base), >> + fold_convert (utype, niter->control.step)); >> + niter->control.base = fold_convert (base_type, niter->control.base); >> + } >> + else >> + niter->control.base >> + = fold_build2 (MINUS_EXPR, base_type, niter->control.base, >> + niter->control.step); >> + >> span = fold_build2 (MULT_EXPR, niter_type, niter->niter, >> fold_convert (niter_type, niter->control.step)); >> niter->bound = fold_build2 (PLUS_EXPR, niter_type, span, >> diff --git a/gcc/testsuite/gcc.dg/pr102087_1.c b/gcc/testsuite/gcc.dg/pr102087_1.c >> new file mode 100644 >> index 00000000000..ba4efe3b412 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.dg/pr102087_1.c >> @@ -0,0 +1,13 @@ >> +/* PR tree-optimization/102087 */ >> +/* { dg-do compile } */ >> +/* { dg-options "-O3 -fprefetch-loop-arrays -w" { target x86_64-*-* powerpc*-*-* } } */ >> + >> +char **Gif_ClipImage_gfi_0; >> +int Gif_ClipImage_gfi_1, Gif_ClipImage_y, Gif_ClipImage_shift; >> +void Gif_ClipImage() { >> + Gif_ClipImage_y = Gif_ClipImage_gfi_1 - 1; >> + for (; Gif_ClipImage_y >= Gif_ClipImage_shift; Gif_ClipImage_y++) >> + Gif_ClipImage_gfi_0[Gif_ClipImage_shift] = >> + Gif_ClipImage_gfi_0[Gif_ClipImage_y]; >> +} >> + >>
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index b767056aeb0..21cc257c91b 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -1579,8 +1579,21 @@ number_of_iterations_until_wrap (class loop *loop, tree type, affine_iv *iv0, { IVbase - STEP, +, STEP } != bound Here, biasing IVbase by 1 step makes 'bound' be the value before wrap. */ - niter->control.base = fold_build2 (MINUS_EXPR, niter_type, - niter->control.base, niter->control.step); + tree base_type = TREE_TYPE (niter->control.base); + if (POINTER_TYPE_P (base_type)) + { + tree utype = unsigned_type_for (base_type); + niter->control.base + = fold_build2 (MINUS_EXPR, utype, + fold_convert (utype, niter->control.base), + fold_convert (utype, niter->control.step)); + niter->control.base = fold_convert (base_type, niter->control.base); + } + else + niter->control.base + = fold_build2 (MINUS_EXPR, base_type, niter->control.base, + niter->control.step); + span = fold_build2 (MULT_EXPR, niter_type, niter->niter, fold_convert (niter_type, niter->control.step)); niter->bound = fold_build2 (PLUS_EXPR, niter_type, span, diff --git a/gcc/testsuite/gcc.dg/pr102087_1.c b/gcc/testsuite/gcc.dg/pr102087_1.c new file mode 100644 index 00000000000..ba4efe3b412 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr102087_1.c @@ -0,0 +1,13 @@ +/* PR tree-optimization/102087 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -fprefetch-loop-arrays -w" { target x86_64-*-* powerpc*-*-* } } */ + +char **Gif_ClipImage_gfi_0; +int Gif_ClipImage_gfi_1, Gif_ClipImage_y, Gif_ClipImage_shift; +void Gif_ClipImage() { + Gif_ClipImage_y = Gif_ClipImage_gfi_1 - 1; + for (; Gif_ClipImage_y >= Gif_ClipImage_shift; Gif_ClipImage_y++) + Gif_ClipImage_gfi_0[Gif_ClipImage_shift] = + Gif_ClipImage_gfi_0[Gif_ClipImage_y]; +} +