> Actually I'm testing a patch to simplify the function down to just
> return gimple_convert (gsi, true, GSI_SAME_STMT, loc, type, val);
> which should perform the optimization by means of match.pd simplifications.

I see, thanks Richard. Do you prefer just go gimple_convert way, or commit this 
one first to fix ICE?
Both are Ok to me.

Pan

-----Original Message-----
From: Richard Biener <[email protected]> 
Sent: Friday, October 10, 2025 4:04 PM
To: Li, Pan2 <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; 
[email protected]; [email protected]; Chen, Ken <[email protected]>; 
Liu, Hongtao <[email protected]>; [email protected]; 
[email protected]
Subject: Re: [PATCH v1] Widen-Mul: Fix ICE when cast pointer/reference of 
build_and_insert_cast

On Fri, Oct 10, 2025 at 9:57 AM Richard Biener
<[email protected]> wrote:
>
> On Thu, Oct 9, 2025 at 9:37 AM <[email protected]> wrote:
> >
> > From: Pan Li <[email protected]>
> >
> > When the val of build_and_insert_cast comes from a cast already, we
> > can refine it to the val casted from to avoid duplicated cast on
> > condition.  However, it is valid only for int types, other types
> > like pointer/reference is invalid as it at least requires the
> > type precision is totoally the same.
> >
> > The below test suites are passed for this patch:
> > 1. The x86 bootstrap tests.
> > 2. The x86 fully regression tests.
> > 3. The pr122111.c test of arm.
>
> OK.

Actually I'm testing a patch to simplify the function down to just

  return gimple_convert (gsi, true, GSI_SAME_STMT, loc, type, val);

which should perform the optimization by means of match.pd simplifications.

Richard.

> >         PR middel-end/122111
> >
> > gcc/ChangeLog:
> >
> >         * tree-ssa-math-opts.cc (build_and_insert_cast): Add the
> >         INTEGRAL_TYPE_P check for the cast val.
> >
> > gcc/testsuite/ChangeLog:
> >
> >         * gcc.target/arm/pr122111.c: New test.
> >
> > Signed-off-by: Pan Li <[email protected]>
> > ---
> >  gcc/testsuite/gcc.target/arm/pr122111.c | 14 ++++++++++++++
> >  gcc/tree-ssa-math-opts.cc               |  3 ++-
> >  2 files changed, 16 insertions(+), 1 deletion(-)
> >  create mode 100644 gcc/testsuite/gcc.target/arm/pr122111.c
> >
> > diff --git a/gcc/testsuite/gcc.target/arm/pr122111.c 
> > b/gcc/testsuite/gcc.target/arm/pr122111.c
> > new file mode 100644
> > index 00000000000..82d15e9a43b
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/arm/pr122111.c
> > @@ -0,0 +1,14 @@
> > +/* Test that we do not have ice when compile */
> > +/* { dg-do compile } */
> > +/* { dg-options "-O3" } */
> > +
> > +typedef long long wide;
> > +
> > +void g(void);
> > +wide f(int *a, unsigned t)
> > +{
> > +  wide i = t;
> > +  i *= 4;
> > +  unsigned long ai = (__SIZE_TYPE__)a;
> > +  return i + ai;
> > +}
> > diff --git a/gcc/tree-ssa-math-opts.cc b/gcc/tree-ssa-math-opts.cc
> > index 0db39f330ea..0bc4ea32f65 100644
> > --- a/gcc/tree-ssa-math-opts.cc
> > +++ b/gcc/tree-ssa-math-opts.cc
> > @@ -1639,7 +1639,8 @@ build_and_insert_cast (gimple_stmt_iterator *gsi, 
> > location_t loc,
> >        gimple *def = SSA_NAME_DEF_STMT (val);
> >
> >        if (is_gimple_assign (def)
> > -         && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def)))
> > +         && CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def))
> > +         && INTEGRAL_TYPE_P (TREE_TYPE (gimple_assign_rhs1 (def))))
> >         {
> >           tree cast_rhs = gimple_assign_rhs1 (def);
> >           tree cast_rhs_type = TREE_TYPE (cast_rhs);
> > --
> > 2.43.0
> >

Reply via email to