Re: Riscv code generation

2023-10-26 Thread Benny Lyne Amorsen
Jacob Navia via Gcc  writes:

> We have 2 loads, and 1 operation + a store. 4 instructions compared to
> 46 operations for the « gcc way » (16 loads of a byte, 14 x 2 OR
> operations and 8 shifts to split the result and 8 stores of a byte
> each.

The sample code seems to have a couple of errors; I fixed it up and put
it on godbolt: https://godbolt.org/z/obbr7K7dx

Let me know if the fixups were wrong. The issue should probably be
reported on Bugzilla as a missed-optimization bug.


/Benny




Re: the elimination of if blocks in GCC during if-conversion and vectorization

2023-10-26 Thread Richard Biener via Gcc
On Mon, Oct 23, 2023 at 2:56 PM Hanke Zhang  wrote:
>
> Richard Biener  于2023年10月23日周一 20:32写道:
> >
> > On Mon, Oct 23, 2023 at 12:50 PM Hanke Zhang  wrote:
> > >
> > > Hi Richard:
> > >
> > > Thanks for your advice. But when I try a simpler example like the one
> > > below before looking at the code, GCC still does nothing.
> > >
> > > int main() {
> > > int width;
> > > scanf("%d", &width);
> > > int sum = 0;
> > > for (int i = 0; i < width; i++) sum += i;
> > > printf("%d\n", sum);
> > > }
> > >
> > > I tried O3 and LTO, but still the same. So I'd like to ask why, or am
> > > I doing something wrong?
> >
> > -fdump-tree-sccp-details-scev reveals
> >
> > (set_scalar_evolution
> >   instantiated_below = 5
> >   (scalar = sum_9)
> >   (scalar_evolution = {0, +, {1, +, 1}_1}_1))
> > )
> > (chrec_apply
> >   (varying_loop = 1)
> >   (chrec = {0, +, {1, +, 1}_1}_1)
> >   (x = (unsigned int) width.0_12 + 4294967295)
> >   (res = scev_not_known))
> >
> > so we don't know how to apply a variable number of iterations to
> > the affine expression {0, +, {1, +, 1}_1}_1, that is, we do not
> > know how to compute the final value of the reduction.
> >
> > For a constant, say width == 100 we do:
> >
> > (set_scalar_evolution
> >   instantiated_below = 2
> >   (scalar = sum_6)
> >   (scalar_evolution = {0, +, {1, +, 1}_1}_1))
> > )
> > (chrec_apply
> >   (varying_loop = 1)
> >   (chrec = {0, +, {1, +, 1}_1}_1)
> >   (x = 99)
> >   (res = 4950))
>
> Yeah, I also found this result in previous experiments. But what
> confuses me is that if the 'width' can't be inferred to INTEGER_CST,
> there's nothing we can do, right?
>
> Because in my case, the variables corresponding to 'width' are almost
> all undetermined values, such as 'width = rand()'. That said, I can
> hardly get any optimizations in my cases, right?

I think the result would be (width * (width - 1)) / 2, chrec_apply is where
"pattern matching" of known series is done.

Richard.

>
> Thanks
> Hanke Zhang
>
>
> >
> > Richard.
> >
> > >
> > > Thanks
> > > Hanke Zhang
> > >
> > > Richard Biener  于2023年10月19日周四 20:00写道:
> > > >
> > > > On Tue, Oct 17, 2023 at 2:39 PM Hanke Zhang  
> > > > wrote:
> > > > >
> > > > > Hi Richard
> > > > > I get it, thank you again.
> > > > >
> > > > > And I got another problem, so I'd like ask it by the way. Can the left
> > > > > shift of the induction variable in a loop be optimized as a constant?
> > > > > Like the code below:
> > > > >
> > > > > int ans = 0;
> > > > > int width = rand() % 16;
> > > > > for (int j = 0; j < width; j++)
> > > > >   ans += 1 << (j + width)
> > > > >
> > > > > into:
> > > > >
> > > > > int width = rand() % 16;
> > > > > ans = (1 << (2 * width) - (1 << width));
> > > > >
> > > > > I came across a more complex version of that and found that gcc
> > > > > doesn't seem to handle it, so wanted to write a pass myself to
> > > > > optimize it.
> > > > >
> > > > > I got two questions here. Does GCC have such optimizations? If I want
> > > > > to do my own optimization, where should I put it? Put it behind the
> > > > > pass_iv_optimize?
> > > >
> > > > GCC has the final value replacement pass (pass_scev_cprop) doing these
> > > > kind of transforms.  Since 'ans' does not have an affine evolution this
> > > > case would need to be pattern matched (there are some existing pattern
> > > > matchings in the pass).
> > > >
> > > > > Thanks
> > > > > Hanke Zhang
> > > > >
> > > > > Richard Biener  于2023年10月17日周二 20:00写道:
> > > > > >
> > > > > > On Tue, Oct 17, 2023 at 1:54 PM Hanke Zhang  
> > > > > > wrote:
> > > > > > >
> > > > > > > Richard Biener  于2023年10月17日周二 
> > > > > > > 17:26写道:
> > > > > > > >
> > > > > > > > On Thu, Oct 12, 2023 at 2:18 PM Hanke Zhang via Gcc 
> > > > > > > >  wrote:
> > > > > > > > >
> > > > > > > > > Hi, I'm recently working on vectorization of GCC. I'm stuck 
> > > > > > > > > in a small
> > > > > > > > > problem and would like to ask for advice.
> > > > > > > > >
> > > > > > > > > For example, for the following code:
> > > > > > > > >
> > > > > > > > > int main() {
> > > > > > > > >   int size = 1000;
> > > > > > > > >   int *foo = malloc(sizeof(int) * size);
> > > > > > > > >   int c1 = rand(), t1 = rand();
> > > > > > > > >
> > > > > > > > >   for (int i = 0; i < size; i++) {
> > > > > > > > > if (foo[i] & c1) {
> > > > > > > > >   foo[i] = t1;
> > > > > > > > > }
> > > > > > > > >   }
> > > > > > > > >
> > > > > > > > >   // prevents the loop above from being optimized
> > > > > > > > >   for (int i = 0; i < size; i++) {
> > > > > > > > > printf("%d", foo[i]);
> > > > > > > > >   }
> > > > > > > > > }
> > > > > > > > >
> > > > > > > > > First of all, the if statement block in the loop will be 
> > > > > > > > > converted to
> > > > > > > > > a MASK_STORE through if-conversion optimization. But after
> > > > > > > > > tree-vector, it will still become a branched form. The part 
> > > > > > > > > of the
> > > > > > > > > final disassembly structur

Install page misses Bison prerequisite

2023-10-26 Thread Simon Sobisch via Gcc
https://gcc.gnu.org/install/prerequisites.html has a bunch of tools 
under "Tools/packages necessary for modifying GCC", but GNU Bison is 
missing.


I found it interesting to see that some files like under intl say
   1 /* A Bison parser, made from plural.y
   2by GNU bison 1.35.  */

Not sure if that would still be able to be processed with that version 
(but it definitely has some bison3 adjustments).



Back to the issue at hand: please add Bison to the list referenced 
above, including its minimal version.


Kind regards,
Simon


Re: Install page misses Bison prerequisite

2023-10-26 Thread Andrew Pinski via Gcc
Looks like it was removed on accident here:
https://gcc.gnu.org/git/?p=gcc.git;a=blobdiff;f=gcc/doc/install.texi;h=3bf2305c8d14181bfb61d112ab3e1c0c2f605322;hp=5735f054317e08b2c5b629adfe72a308459b8bd9;hb=e8645a4001a8d117dd336ea75942aac49101af49;hpb=3825be8c96775cf8e6fcb5eef04455f07717a5ea

But it is not required to build gcc rather only if you are modifying gcc.

Thanks,
Andrew

On Thu, Oct 26, 2023, 11:01 Simon Sobisch via Gcc  wrote:

> https://gcc.gnu.org/install/prerequisites.html has a bunch of tools
> under "Tools/packages necessary for modifying GCC", but GNU Bison is
> missing.
>
> I found it interesting to see that some files like under intl say
> 1 /* A Bison parser, made from plural.y
> 2by GNU bison 1.35.  */
>
> Not sure if that would still be able to be processed with that version
> (but it definitely has some bison3 adjustments).
>
>
> Back to the issue at hand: please add Bison to the list referenced
> above, including its minimal version.
>
> Kind regards,
> Simon
>


Re: Install page misses Bison prerequisite

2023-10-26 Thread Andrew Pinski via Gcc
On Thu, Oct 26, 2023 at 11:01 AM Simon Sobisch via Gcc  wrote:
>
> https://gcc.gnu.org/install/prerequisites.html has a bunch of tools
> under "Tools/packages necessary for modifying GCC", but GNU Bison is
> missing.
>
> I found it interesting to see that some files like under intl say
> 1 /* A Bison parser, made from plural.y
> 2by GNU bison 1.35.  */
>
> Not sure if that would still be able to be processed with that version
> (but it definitely has some bison3 adjustments).
>
>
> Back to the issue at hand: please add Bison to the list referenced
> above, including its minimal version.

Oh also intl is not used on GNU/Linux hosts and is the process of
being updated to the latest upstream version so the requirement might
be changing.
https://gcc.gnu.org/pipermail/gcc-patches/2023-October/632170.html

Thanks,
Andrew

>
> Kind regards,
> Simon


gcc-11-20231026 is now available

2023-10-26 Thread GCC Administrator via Gcc
Snapshot gcc-11-20231026 is now available on
  https://gcc.gnu.org/pub/gcc/snapshots/11-20231026/
and on various mirrors, see http://gcc.gnu.org/mirrors.html for details.

This snapshot has been generated from the GCC 11 git branch
with the following options: git://gcc.gnu.org/git/gcc.git branch 
releases/gcc-11 revision e250d27ba520652264e58c8a81f53615619bb29b

You'll find:

 gcc-11-20231026.tar.xz   Complete GCC

  SHA256=5640ce98f0dbde2043c6993f69542f124d9b65d02406ff1e2fbb76eb2d43d556
  SHA1=f11ddebe8d374e7161779a8e70fefd41eab50c71

Diffs from 11-20231019 are available in the diffs/ subdirectory.

When a particular snapshot is ready for public consumption the LATEST-11
link is updated and a message is sent to the gcc list.  Please do not use
a snapshot before it has been announced that way.