Question about enabling additional flags in Ofast

2024-07-13 Thread Hanke Zhang via Gcc
Hi, I'm attempting to enable more flags in Ofast, but I've encountered some issues. For instance, if I want to add -flto-partition=one to Ofast, here is the modification I made to opts.cc /* -Ofast adds optimizations to -O3. */ { OPT_LEVELS_FAST, OPT_ffast_math, NULL, 1 }, { OPT_LEVELS_FAST, OP

Re: Question about optimizing function pointers for direct function calls

2024-06-12 Thread Hanke Zhang via Gcc
1:57 AM Hanke Zhang wrote: > > > > Richard Biener 于2024年5月24日周五 14:39写道: > > > > > > On Fri, May 24, 2024 at 5:53 AM Hanke Zhang via Gcc > > > wrote: > > > > > > > > Hi, > > > > I got a question about optimizing function pointers for d

Re: Question about optimizing function pointers for direct function calls

2024-06-12 Thread Hanke Zhang via Gcc
Richard Biener 于2024年5月24日周五 14:39写道: > > On Fri, May 24, 2024 at 5:53 AM Hanke Zhang via Gcc wrote: > > > > Hi, > > I got a question about optimizing function pointers for direct > > function calls in C. > > > > Consider the following scenario: one of t

How to represent a fallthrough condtion (with no else) in "Match and Simplify"?

2024-06-11 Thread Hanke Zhang via Gcc
Hi, I'm trying to study "Match and Simplify" recently, and I had this sample code: int main() { int n = 1000; int *a = malloc (sizeof(int) * n); int *b = malloc (sizeof(int) * n); int *c = malloc (sizeof(int) * n); for (int i = 0; i < n; i++) { if (a[i] & b[i]) { a[i] ^= c[i];

Question about generating vpmovzxbd instruction without using the interfaces in immintrin.h

2024-05-30 Thread Hanke Zhang via Gcc
Hi, I've recently been trying to hand-write code to trigger automatic vectorization optimizations in GCC on Intel x86 machines (without using the interfaces in immintrin.h), but I'm running into a problem where I can't seem to get the concise `vpmovzxbd` or similar instructions. My requirement is

Re: Question about the SLP vectorizer failed to perform automatic vectorization in one case

2024-05-27 Thread Hanke Zhang via Gcc
Hi Biener, Thanks for your help! I have already open a bugreport here https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115252. Thanks Hanke Zhang Richard Biener 于2024年5月27日周一 21:14写道: > > On Sat, May 25, 2024 at 3:08 PM Hanke Zhang via Gcc wrote: > > > > Hi, > > I

Question about the SLP vectorizer failed to perform automatic vectorization in one case

2024-05-25 Thread Hanke Zhang via Gcc
Hi, I'm trying to studing the automatic vectorization optimization in GCC, but I found one case that SLP vectorizer failed to do such things. Here is the sample code: (also a simplification version of a function from the 625/525.x264 source code in SPEC CPU 2017) void pixel_sub_wxh(int16_t *diff,

Question about optimizing function pointers for direct function calls

2024-05-23 Thread Hanke Zhang via Gcc
Hi, I got a question about optimizing function pointers for direct function calls in C. Consider the following scenario: one of the fields of a structure is a function pointer, and all its assignments come from the same function. Can all its uses be replaced by direct calls to this function? So th

Re: How to format code in GCC style?

2024-04-30 Thread Hanke Zhang via Gcc
7;t work for me. Maybe I configured vim in some wrong way. Thanks Hanke Zhang Filip Kastl 于2024年4月30日周二 18:00写道: > > On Tue 2024-04-30 13:52:16, Hanke Zhang via Gcc wrote: > > Hi > > I'm trying to format my code in GCC style. > > > > But I don't know how t

How to format code in GCC style?

2024-04-29 Thread Hanke Zhang via Gcc
Hi I'm trying to format my code in GCC style. But I don't know how to finish it. I try `indent` and `check_GNU_style.sh` in the `contrib` directory. But none of them seem to work well. So I wondered is there any official tools to do that? Thanks Hanke Zhang

Re: Question about constructing vector types in GIMPLE pass

2024-04-08 Thread Hanke Zhang via Gcc
unction is defined in `config/i386/i386-builtins.h`. And when I try to include this header file, the error will occur during the compilation. If you know any way to solve this problem, I would be very grateful. :) Thanks Hanke Zhang Marc Glisse 于2024年4月9日周二 03:01写道: > > On Mon, 8 Apr 2024, Han

Question about constructing vector types in GIMPLE pass

2024-04-08 Thread Hanke Zhang via Gcc
Hi, I've been working on strengthening auto-vectorization on intel CPUs recently. I tried to do it in the GIMPLE pass. And I noticed that some vector types in the GIMPLE code are confusing to me. The example code is here: _1 = MEM[(const __m256i_u * {ref-all})_2]; I wondered how I could construct

How to get the default values for parameters?

2024-04-03 Thread Hanke Zhang via Gcc
Hi, I'm trying to get the default values for parameters of some functions in my GIMPLE-PASS. The example code is here: enum { edefault1 = 1, edefault2 = 2, edefault3 = 3 } void func(int p0, int p1 = edefault1, int p2 = edefault2, int p3 = edefault3) { // do other things } I want to get t

Re: How to compress the size of a field in a structure?

2024-01-13 Thread Hanke Zhang via Gcc
statements may help with it. If there are some more complex situations, we will give up this optimization. But I'm more concerned about how to accomplish this. Thanks Hanke Zhang Iain Sandoe 于2024年1月13日周六 17:15写道: > > > > > On 13 Jan 2024, at 07:45, Hanke Zhang via Gcc wrote: > &

How to compress the size of a field in a structure?

2024-01-12 Thread Hanke Zhang via Gcc
Hi, I'm attempting to compress the size of a field in a structure for memory-friendly purposes. I created an IPA pass to achieve this, but I ran into some issues as follows: // original struct Foo { long a1; int a2; }; // modified struct Foo_update { int a1; int a2; }; For the example st

Re: Question about creating global varaiable during IPA PASS.

2023-12-20 Thread Hanke Zhang via Gcc
Hi Thomas! Thanks for your reply. That's exactly what I'm missing. When I add varpool_node::finalize_decl() to my code, everything works fine! Thomas Schwinge 于2023年12月16日周六 01:15写道: > > Hi Hanke! > > On 2023-12-13T17:04:57+0800, Hanke Zhang via Gcc wrote: > > Hi, I

Question about creating global varaiable during IPA PASS.

2023-12-13 Thread Hanke Zhang via Gcc
Hi, I'm trying to create a global variable in my own PASS which located at the LATE_IPA_PASSES. (I'm using GCC 10.3.0.) And after creating it, I added the attributes like the following. // 1. create the var tree new_name = get_identifier (xx); tree new_type = build_pointer_type (xx); tree new_var

Question about creating an outermost loop

2023-11-20 Thread Hanke Zhang via Gcc
Hi, I'm working on loop tiling recently. I want to add this optimization to GCC. But I have encoutered some problems here and ask for help. For the code below as an example: for (int i = 0; i < 12; i++) { for (int j = 0; j < arr.length; j++) { // arr.length may be huge // do something with

Question about vectorization optimization during RTL-PASS

2023-11-12 Thread Hanke Zhang via Gcc
Hi, I've been working on vectorization-related optimization lately. GCC seems to have some optimization vulnerabilities. I would like to ask if it can be solved. For example, for the following program using AVX2: #include // reg->node2[i].state is an unsigned long long variable // reg->size is a

Question about the changing the default behavior of ipa-inline

2023-11-03 Thread Hanke Zhang via Gcc
Hi, I recently ran into an inline-related issue and would like to ask about it. This is about the ipa-inline. I'd like to make my function be inlined, but it trapped in the function 'want_inline_small_function_p', more specificly, in the conditional statement 'growth_positive_p (callee, e, growth)

Question about function Split with va_args

2023-11-01 Thread Hanke Zhang via Gcc
Hi I've been working on function splits recently, and I've noticed that functions with va_args arguments won't be split, so why is that? I tried to understand the comments in the source code, but I still don't get the specific reason. At the same time, if I do want to split functions with va_args

Re: Question on replacing .MASK_STORE with ternary expressions

2023-10-25 Thread Hanke Zhang via Gcc
../../gcc/tree-if-conv.cc:3549 > > Richard Biener 于2023年10月25日周三 23:40写道: > > > > > > > > > Am 25.10.2023 um 17:25 schrieb Hanke Zhang via Gcc : > > > > > > Hi, I got a gimple relative question. > > > > > > I'm trying

Re: Question on replacing .MASK_STORE with ternary expressions

2023-10-25 Thread Hanke Zhang via Gcc
3d execute ../../gcc/tree-if-conv.cc:3549 Richard Biener 于2023年10月25日周三 23:40写道: > > > > > Am 25.10.2023 um 17:25 schrieb Hanke Zhang via Gcc : > > > > Hi, I got a gimple relative question. > > > > I'm trying to replace the .MASK_STORE with a ternary expres

Question on replacing .MASK_STORE with ternary expressions

2023-10-25 Thread Hanke Zhang via Gcc
Hi, I got a gimple relative question. I'm trying to replace the .MASK_STORE with a ternary expression in pass_ifcvt like below: .MASK_STORE(addr, align, mask, value) => *addr = mask ? value : *addr; But when I do this, I'm stucked. The addr here is a SSA_NAME of course. When I try to get the val

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

2023-10-23 Thread Hanke Zhang via Gcc
ation, 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 >

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

2023-10-23 Thread Hanke Zhang via Gcc
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 Zhan

Re: Question about the pass_fre about merging if blocks.

2023-10-21 Thread Hanke Zhang via Gcc
> > >>> Richard Biener 于2023年10月20日周五 21:33写道: > >>>> > >>>>> On Fri, Oct 20, 2023 at 1:48 PM Hanke Zhang via Gcc > >>>>> wrote: > >>>>> > >>>>> Hi, I'm trying to make pass_fre work b

Re: Question about the pass_fre about merging if blocks.

2023-10-21 Thread Hanke Zhang via Gcc
Richard Biener 于2023年10月20日周五 23:27写道: > > > > > Am 20.10.2023 um 16:33 schrieb Hanke Zhang : > > > > Richard Biener 于2023年10月20日周五 21:33写道: > >> > >>> On Fri, Oct 20, 2023 at 1:48 PM Hanke Zhang via Gcc > >>> wrote: > >>&g

Re: Question about the pass_fre about merging if blocks.

2023-10-20 Thread Hanke Zhang via Gcc
Richard Biener 于2023年10月20日周五 21:33写道: > > On Fri, Oct 20, 2023 at 1:48 PM Hanke Zhang via Gcc wrote: > > > > Hi, I'm trying to make pass_fre work better for me. But I got a > > problem. Like the code below: > > > > int glob; > > > > void __at

Question about the pass_fre about merging if blocks.

2023-10-20 Thread Hanke Zhang via Gcc
Hi, I'm trying to make pass_fre work better for me. But I got a problem. Like the code below: int glob; void __attribute__((oninline)) foo() { // do nothing meaningful } int main() { if (glob) { foo(); } else { // do something that won't change glob } if (glob) { foo();

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

2023-10-17 Thread Hanke Zhang via Gcc
zations? If I want to do my own optimization, where should I put it? Put it behind the pass_iv_optimize? 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写道: > > >

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

2023-10-17 Thread Hanke Zhang via Gcc
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 exa

Check whether a function is a pure function

2023-10-17 Thread Hanke Zhang via Gcc
Hi, I'm trying to write a pass to erase some useless functions or to put it another way, detect whether a function is pure or not. (Of course I know some passes can do the clean after inline) Here is the problem I got, If a function satisfy the following points, can it be considered safe to delete

Question about gimple code during optimizing if-conversion

2023-10-13 Thread Hanke Zhang via Gcc
Hi, I'm working on optimizing if-conversion for my own business recently. I got a problem here. I tried to optimize it in such a case, for example, when a conditional statement block has only if statement and no else statement, the source C code looks like this: int* foo; // assume this has been

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

2023-10-12 Thread Hanke Zhang via Gcc
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

why not optimize static local variables

2023-10-07 Thread Hanke Zhang via Gcc
Hi, I've recently been working on static local variables in C. I would like to ask about some questions about that. For example, for the following program, void foo() { static int x = 0; x++; } int main() { foo(); } After optimization with the -O3 -flto option, the entire program will loo

Re: Question about function splitting

2023-10-04 Thread Hanke Zhang via Gcc
gcc.gnu.org/bugzilla/show_bug.cgi?id=111672 Richard Biener 于2023年10月4日周三 16:20写道: > > On Mon, Oct 2, 2023 at 7:15 PM Hanke Zhang via Gcc wrote: > > > > Martin Jambor 于2023年10月3日周二 00:34写道: > > > > > > Hello, > > > > > > On Mon, Oct 02 2023, Hanke Zha

Re: Function return value can't be infered when it's not inlined

2023-10-04 Thread Hanke Zhang via Gcc
Richard Biener 于2023年10月4日周三 16:43写道: > > On Wed, Oct 4, 2023 at 10:37 AM Richard Biener > wrote: > > > > On Tue, Oct 3, 2023 at 6:30 PM Hanke Zhang via Gcc wrote: > > > > > > Hi, I'm a little confused about the behavior of gcc when the function

Function return value can't be infered when it's not inlined

2023-10-03 Thread Hanke Zhang via Gcc
Hi, I'm a little confused about the behavior of gcc when the function is not inlined. Here is an example code: int __attribute__((noinline)) foo() { return 1; } int main() { if (foo()) { printf("foo() returned 1\n"); } else { printf("foo() returned 0\n"); } re

Re: Question about function splitting

2023-10-02 Thread Hanke Zhang via Gcc
Martin Jambor 于2023年10月3日周二 00:34写道: > > Hello, > > On Mon, Oct 02 2023, Hanke Zhang via Gcc wrote: > > Hi, I have some questions about the strategy and behavior of function > > splitting in gcc, like the following code: > > > > int glob; > > void f()

Question about function splitting

2023-10-02 Thread Hanke Zhang via Gcc
Hi, I have some questions about the strategy and behavior of function splitting in gcc, like the following code: int glob; void f() { if (glob) { printf("short path\n"); return; } // do lots of expensive things // ... } I hope it can be broken down like below, so that the whole fu

Re: Question about merging if-else blocks

2023-09-30 Thread Hanke Zhang via Gcc
Richard Biener 于2023年9月27日周三 15:30写道: > > On Wed, Sep 27, 2023 at 7:21 AM Hanke Zhang via Gcc wrote: > > > > Thanks! I understand what you mean, then can I think that if the > > function here is not an external function, but a function visible to > > the compiler a

Check whether the global variable has been modified in a function or some blocks

2023-09-29 Thread Hanke Zhang via Gcc
Hi, I have recently been working on issues related to the changing values of global variables. That is, I was trying to develop a gimple pass, which needs to check whether the value of a global variable is modified in the a function or some blocks. Some of the more tricky cases are as follows: in

Re: Question about merging if-else blocks

2023-09-26 Thread Hanke Zhang via Gcc
Thanks! I understand what you mean, then can I think that if the function here is not an external function, but a function visible to the compiler and the function doesn't modify `a`, then these two blocks can be merged? Marc Glisse 于2023年9月27日周三 12:51写道: > > On Wed, 27 Sep 2023, Hank

Question about merging if-else blocks

2023-09-26 Thread Hanke Zhang via Gcc
Hi, I have recently been working on merging if-else statement blocks, and I found a rather bizarre phenomenon that I would like to ask about. A rough explanation is that for two consecutive if-else blocks, if their if statements are exactly the same, they should be merged, like the following progra

Re: The order of loop traversal in gcc

2023-09-25 Thread Hanke Zhang via Gcc
Richard Biener 于2023年9月25日周一 13:46写道: > > > > > Am 25.09.2023 um 04:53 schrieb Hanke Zhang via Gcc : > > > > Hi, I have recently been working on loops in gcc, and I have some > > questions about the loop traversal. > > > > I use loops_list(cfun, L

The order of loop traversal in gcc

2023-09-24 Thread Hanke Zhang via Gcc
Hi, I have recently been working on loops in gcc, and I have some questions about the loop traversal. I use loops_list(cfun, LI_ONLY_INNERMOST) to traverse the loops in my pass to obtain the loop. I found that the order of traversal and the order of actual instruction execution will be different.

Loop fusion in gcc

2023-09-23 Thread Hanke Zhang via Gcc
Hi, I have been very interested in loop fusion recently. I found that both LLVM and icc have implemented this optimization. I also noticed that gcc does not seem to implement it. I would like to ask if gcc have any plans to implement this optimization? In addition, I also found that there is a fun

Re: How to enable DCE during late_ipa_passes?

2023-09-18 Thread Hanke Zhang via Gcc
Thanks! That works! Richard Biener 于2023年9月18日周一 15:56写道: > > On Mon, Sep 18, 2023 at 9:17 AM Hanke Zhang via Gcc wrote: > > > > Hi, I am currently developing a new pass in the late_ipa_passes phase, > > located behind the pass_ipa_pta and in front of the > > p

How to enable DCE during late_ipa_passes?

2023-09-18 Thread Hanke Zhang via Gcc
Hi, I am currently developing a new pass in the late_ipa_passes phase, located behind the pass_ipa_pta and in front of the pass_omp_simd_clone. I now hope that after the pass I developed, the code can be vectorized, that is, the code that can be vectorized during the pass_omp_simd_clone. But not y

Re: How to make parallelizing loops and vectorization work at the same time?

2023-09-15 Thread Hanke Zhang via Gcc
I get it. It's a `lto` problem. If I remove `-flto`, both work. Thanks for your help again! Richard Biener 于2023年9月15日周五 21:13写道: > > On Fri, Sep 15, 2023 at 3:09 PM Hanke Zhang wrote: > > > > Richard Biener 于2023年9月15日周五 19:59写道: > > > > > > > &

Re: How to make parallelizing loops and vectorization work at the same time?

2023-09-15 Thread Hanke Zhang via Gcc
Richard Biener 于2023年9月15日周五 19:59写道: > > On Fri, Sep 15, 2023 at 1:21 PM Hanke Zhang via Gcc wrote: > > > > Hi I'm trying to accelerate my program with -ftree-vectorize and > > -ftree-parallelize-loops. > > > > Here are my test results using the differ

How to make parallelizing loops and vectorization work at the same time?

2023-09-15 Thread Hanke Zhang via Gcc
Hi I'm trying to accelerate my program with -ftree-vectorize and -ftree-parallelize-loops. Here are my test results using the different options (based on gcc10.3.0 on i9-12900KF): gcc-10 test.c -O3 -flto > time: 29000 ms gcc-10 test.c -O3 -flto -mavx2 -ftree-vectorize > time: 17000 ms gcc-10 test.