[1/3] middle-end: enable ranger in gimple-isel

Message ID patch-20683-tamar@arm.com
State New
Headers
Series [1/3] middle-end: enable ranger in gimple-isel |

Commit Message

Tamar Christina July 7, 2026, 10:13 a.m. UTC
  This enabled ranger for use in isel to do some ranged based foldings.

Not much else to write about this one :)

Bootstrapped Regtested on aarch64-none-linux-gnu,
arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
-m32, -m64 and no issues.

Ok for master?

Thanks,
Tamar

gcc/ChangeLog:

	* gimple-isel.cc (pass_gimple_isel::execute): Enable and disable ranger
	on fun.

---


--
  

Comments

Richard Biener July 7, 2026, 11:32 a.m. UTC | #1
On Tue, 7 Jul 2026, Tamar Christina wrote:

> This enabled ranger for use in isel to do some ranged based foldings.
> 
> Not much else to write about this one :)
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu,
> arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
> -m32, -m64 and no issues.
> 
> Ok for master?
> 
> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
> 	* gimple-isel.cc (pass_gimple_isel::execute): Enable and disable ranger
> 	on fun.
> 
> ---
> diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc
> index b193e27b183e1a83d73369b629c81ea0d7db43cd..0bd3a2f732922bc939c9d5fb4a221764def6e756 100644
> --- a/gcc/gimple-isel.cc
> +++ b/gcc/gimple-isel.cc
> @@ -40,6 +40,8 @@ along with GCC; see the file COPYING3.  If not see
>  #include "gimple-fold.h"
>  #include "internal-fn.h"
>  #include "fold-const.h"
> +#include "gimple-range.h"
> +
>  
>  /* Expand all ARRAY_REF(VIEW_CONVERT_EXPR) gimple assignments into calls to
>     internal function based on vector type of selected expansion.
> @@ -1352,6 +1354,9 @@ pass_gimple_isel::execute (struct function *fun)
>    gimple_stmt_iterator gsi;
>    basic_block bb;
>    bool cfg_changed = false;
> +  bool created_ranger = get_range_query (fun) == get_global_range_query ();
> +  if (created_ranger)
> +    enable_ranger (fun);

We shouldn't have an active ranger across passes, do we?  I do not
see us folding stmts here, not .WHILE_ULT anyway, so I'm missing
the point of this (in isolation).

That said, just enable_ranger()/disable_ranger() w/o checks is OK
with me, hopefully all the cost is on-demand.

>    FOR_EACH_BB_FN (bb, fun)
>      {
> @@ -1390,6 +1395,8 @@ pass_gimple_isel::execute (struct function *fun)
>  	}
>      }
>  
> +  if (created_ranger)
> +    disable_ranger (fun);
>    return cfg_changed ? TODO_cleanup_cfg : 0;
>  }
>  
> 
> 
>
  
Tamar Christina July 7, 2026, 12:04 p.m. UTC | #2
> -----Original Message-----
> From: Richard Biener <rguenther@suse.de>
> Sent: 07 July 2026 12:32
> To: Tamar Christina <Tamar.Christina@arm.com>
> Cc: gcc-patches@gcc.gnu.org; nd <nd@arm.com>
> Subject: Re: [patch 1/3]middle-end: enable ranger in gimple-isel
> 
> On Tue, 7 Jul 2026, Tamar Christina wrote:
> 
> > This enabled ranger for use in isel to do some ranged based foldings.
> >
> > Not much else to write about this one :)
> >
> > Bootstrapped Regtested on aarch64-none-linux-gnu,
> > arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
> > -m32, -m64 and no issues.
> >
> > Ok for master?
> >
> > Thanks,
> > Tamar
> >
> > gcc/ChangeLog:
> >
> > 	* gimple-isel.cc (pass_gimple_isel::execute): Enable and disable ranger
> > 	on fun.
> >
> > ---
> > diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc
> > index
> b193e27b183e1a83d73369b629c81ea0d7db43cd..0bd3a2f732922bc939c
> 9d5fb4a221764def6e756 100644
> > --- a/gcc/gimple-isel.cc
> > +++ b/gcc/gimple-isel.cc
> > @@ -40,6 +40,8 @@ along with GCC; see the file COPYING3.  If not see
> >  #include "gimple-fold.h"
> >  #include "internal-fn.h"
> >  #include "fold-const.h"
> > +#include "gimple-range.h"
> > +
> >
> >  /* Expand all ARRAY_REF(VIEW_CONVERT_EXPR) gimple assignments into
> calls to
> >     internal function based on vector type of selected expansion.
> > @@ -1352,6 +1354,9 @@ pass_gimple_isel::execute (struct function *fun)
> >    gimple_stmt_iterator gsi;
> >    basic_block bb;
> >    bool cfg_changed = false;
> > +  bool created_ranger = get_range_query (fun) == get_global_range_query
> ();
> > +  if (created_ranger)
> > +    enable_ranger (fun);
> 
> We shouldn't have an active ranger across passes, do we?  I do not
> see us folding stmts here, not .WHILE_ULT anyway, so I'm missing
> the point of this (in isolation).

I'm explicitly using the on demand querying for querying the operands
of the WHILE_ULT.  I placed it here since it's cheaper than enabling and
disabling it every time in the target hook?

> 
> That said, just enable_ranger()/disable_ranger() w/o checks is OK
> with me, hopefully all the cost is on-demand.

Fair, I thought I had to guard it since enable_ranger checks for an existing
range instance.  But I suppose since other passes should have cleaned
up their instances this shouldn't be needed and indeed I don't see it
checked in other places.   Should have grepped before.

Will respin.

Thanks,
Tamar
> 
> >    FOR_EACH_BB_FN (bb, fun)
> >      {
> > @@ -1390,6 +1395,8 @@ pass_gimple_isel::execute (struct function *fun)
> >  	}
> >      }
> >
> > +  if (created_ranger)
> > +    disable_ranger (fun);
> >    return cfg_changed ? TODO_cleanup_cfg : 0;
> >  }
> >
> >
> >
> >
> 
> --
> Richard Biener <rguenther@suse.de>
> SUSE Software Solutions Germany GmbH,
> Frankenstrasse 146, 90461 Nuernberg, Germany;
> GF: Jochen Jaser, Andrew McDonald; (HRB 36809, AG Nuernberg)
  
Andrew MacLeod July 7, 2026, 12:33 p.m. UTC | #3
On 7/7/26 07:32, Richard Biener wrote:
> On Tue, 7 Jul 2026, Tamar Christina wrote:
>
>> This enabled ranger for use in isel to do some ranged based foldings.
>>
>> Not much else to write about this one :)
>>
>> Bootstrapped Regtested on aarch64-none-linux-gnu,
>> arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
>> -m32, -m64 and no issues.
>>
>> Ok for master?
>>
>> Thanks,
>> Tamar
>>
>> gcc/ChangeLog:
>>
>> 	* gimple-isel.cc (pass_gimple_isel::execute): Enable and disable ranger
>> 	on fun.
>>
>> ---
>> diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc
>> index b193e27b183e1a83d73369b629c81ea0d7db43cd..0bd3a2f732922bc939c9d5fb4a221764def6e756 100644
>> --- a/gcc/gimple-isel.cc
>> +++ b/gcc/gimple-isel.cc
>> @@ -40,6 +40,8 @@ along with GCC; see the file COPYING3.  If not see
>>   #include "gimple-fold.h"
>>   #include "internal-fn.h"
>>   #include "fold-const.h"
>> +#include "gimple-range.h"
>> +
>>   
>>   /* Expand all ARRAY_REF(VIEW_CONVERT_EXPR) gimple assignments into calls to
>>      internal function based on vector type of selected expansion.
>> @@ -1352,6 +1354,9 @@ pass_gimple_isel::execute (struct function *fun)
>>     gimple_stmt_iterator gsi;
>>     basic_block bb;
>>     bool cfg_changed = false;
>> +  bool created_ranger = get_range_query (fun) == get_global_range_query ();
>> +  if (created_ranger)
>> +    enable_ranger (fun);
> We shouldn't have an active ranger across passes, do we?  I do not
> see us folding stmts here, not .WHILE_ULT anyway, so I'm missing
> the point of this (in isolation).
>
> That said, just enable_ranger()/disable_ranger() w/o checks is OK
> with me, hopefully all the cost is on-demand.


No active rangers across passes. Any cross-pass info is through 
SSA_NAME_RANGE_INFO.   And yes, enable_ranger has very little cost until 
its actually used, and then it is on demand as needed.


Andrew
  
Richard Biener July 8, 2026, 11:23 a.m. UTC | #4
On Wed, 8 Jul 2026, Tamar Christina wrote:

> This enabled ranger for use in isel to do some ranged based foldings.
> 
> Not much else to write about this one :)
> 
> Bootstrapped Regtested on aarch64-none-linux-gnu,
> arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
> -m32, -m64 and no issues.
> 
> Ok for master?

OK.

> Thanks,
> Tamar
> 
> gcc/ChangeLog:
> 
> 	* gimple-isel.cc (pass_gimple_isel::execute): Enable and disable ranger
> 	on fun.
> 
> ---
> diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc
> index b193e27b183e1a83d73369b629c81ea0d7db43cd..46cd0f7e79cc1e99b29365a93fdf2c5f284c688b 100644
> --- a/gcc/gimple-isel.cc
> +++ b/gcc/gimple-isel.cc
> @@ -40,6 +40,8 @@ along with GCC; see the file COPYING3.  If not see
>  #include "gimple-fold.h"
>  #include "internal-fn.h"
>  #include "fold-const.h"
> +#include "gimple-range.h"
> +
>  
>  /* Expand all ARRAY_REF(VIEW_CONVERT_EXPR) gimple assignments into calls to
>     internal function based on vector type of selected expansion.
> @@ -1352,6 +1354,7 @@ pass_gimple_isel::execute (struct function *fun)
>    gimple_stmt_iterator gsi;
>    basic_block bb;
>    bool cfg_changed = false;
> +  enable_ranger (fun);
>  
>    FOR_EACH_BB_FN (bb, fun)
>      {
> @@ -1390,6 +1393,7 @@ pass_gimple_isel::execute (struct function *fun)
>  	}
>      }
>  
> +  disable_ranger (fun);
>    return cfg_changed ? TODO_cleanup_cfg : 0;
>  }
>  
> 
> 
>
  
Richard Biener July 8, 2026, 11:24 a.m. UTC | #5
On Wed, 8 Jul 2026, Richard Biener wrote:

> On Wed, 8 Jul 2026, Tamar Christina wrote:
> 
> > This enabled ranger for use in isel to do some ranged based foldings.
> > 
> > Not much else to write about this one :)
> > 
> > Bootstrapped Regtested on aarch64-none-linux-gnu,
> > arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
> > -m32, -m64 and no issues.
> > 
> > Ok for master?
> 
> OK.

Or rather, since ISEL also runs at -O0 please guard with

 if (optimize)

> > Thanks,
> > Tamar
> > 
> > gcc/ChangeLog:
> > 
> > 	* gimple-isel.cc (pass_gimple_isel::execute): Enable and disable ranger
> > 	on fun.
> > 
> > ---
> > diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc
> > index b193e27b183e1a83d73369b629c81ea0d7db43cd..46cd0f7e79cc1e99b29365a93fdf2c5f284c688b 100644
> > --- a/gcc/gimple-isel.cc
> > +++ b/gcc/gimple-isel.cc
> > @@ -40,6 +40,8 @@ along with GCC; see the file COPYING3.  If not see
> >  #include "gimple-fold.h"
> >  #include "internal-fn.h"
> >  #include "fold-const.h"
> > +#include "gimple-range.h"
> > +
> >  
> >  /* Expand all ARRAY_REF(VIEW_CONVERT_EXPR) gimple assignments into calls to
> >     internal function based on vector type of selected expansion.
> > @@ -1352,6 +1354,7 @@ pass_gimple_isel::execute (struct function *fun)
> >    gimple_stmt_iterator gsi;
> >    basic_block bb;
> >    bool cfg_changed = false;
> > +  enable_ranger (fun);
> >  
> >    FOR_EACH_BB_FN (bb, fun)
> >      {
> > @@ -1390,6 +1393,7 @@ pass_gimple_isel::execute (struct function *fun)
> >  	}
> >      }
> >  
> > +  disable_ranger (fun);
> >    return cfg_changed ? TODO_cleanup_cfg : 0;
> >  }
> >  
> > 
> > 
> > 
> 
>
  

Patch

diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc
index b193e27b183e1a83d73369b629c81ea0d7db43cd..0bd3a2f732922bc939c9d5fb4a221764def6e756 100644
--- a/gcc/gimple-isel.cc
+++ b/gcc/gimple-isel.cc
@@ -40,6 +40,8 @@  along with GCC; see the file COPYING3.  If not see
 #include "gimple-fold.h"
 #include "internal-fn.h"
 #include "fold-const.h"
+#include "gimple-range.h"
+
 
 /* Expand all ARRAY_REF(VIEW_CONVERT_EXPR) gimple assignments into calls to
    internal function based on vector type of selected expansion.
@@ -1352,6 +1354,9 @@  pass_gimple_isel::execute (struct function *fun)
   gimple_stmt_iterator gsi;
   basic_block bb;
   bool cfg_changed = false;
+  bool created_ranger = get_range_query (fun) == get_global_range_query ();
+  if (created_ranger)
+    enable_ranger (fun);
 
   FOR_EACH_BB_FN (bb, fun)
     {
@@ -1390,6 +1395,8 @@  pass_gimple_isel::execute (struct function *fun)
 	}
     }
 
+  if (created_ranger)
+    disable_ranger (fun);
   return cfg_changed ? TODO_cleanup_cfg : 0;
 }