Re: Handle POINTER_PLUS_EXPR in jump functions
> > > > > > 2020-10-15 Jakub Jelinek > > > > > > * gcc.dg/ipa/modref-1.c: Remove space between param offset: and number > > > in scan-ipa-dump. > > > (b): Declare return type to void. > > > (main): Declare return type to int. Change c to array of 3 chars. > > > * gcc.dg/tree-ssa/modref-4.c: Remove space between param offset: and > > > number in scan-ipa-dump. Use modref1 instead of modref2. > > > (b): Declare return type to void. > > > (main): Declare return type to int. Change c to array of 3 chars. > > Sorry for that - I had fixed versions of the testcases but must have > > mixed the up. I will look at the reutrn 0 case. > > Note that even if it optimized as much as it ever could, return 0 is not the > correct value, while c[0] is unmodified and the optimization > correctly proves that it isn't and optimizes it into 0, c[2] is modified - > it is changed from 0 to 1. Perhaps you meant c[4]={0,1,0,0}; and check > if c[0]+c[3] is optimized into 0? Yep, I was trying to check that both offset and size are correctly determined. I applied the folowing: * gcc.dg/tree-ssa/modref-4.c: Fix return test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c b/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c index 97fe5307a1c..3ac217bafb8 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c @@ -15,9 +15,9 @@ void b(char *ptr) int main() { - char c[3]={0,1,0}; + char c[4]={0,1,2,0}; b(c); - return c[0]+c[2]; + return c[0]+c[3]; } /* Check that both param offsets are determined correctly and the computation is optimized out. */
Re: Handle POINTER_PLUS_EXPR in jump functions
On Thu, Oct 15, 2020 at 02:39:26PM +0200, Jan Hubicka wrote: > > Both of these tests FAIL everywhere: > > FAIL: gcc.dg/ipa/modref-1.c (test for excess errors) > > FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 1" > > FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 2" > > FAIL: gcc.dg/tree-ssa/modref-4.c (test for excess errors) > > FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "param offset: 1" > > UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "param > > offset: 2" > > UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "return 0" > > > > I've tried to fix most of things, but > > FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "return 0" > > remains (it isn't even optimized in optimized dump). > > > > Committed to trunk as obvious anyway, but please tweak the modref-4.c > > test according to what you meant. > > > > 2020-10-15 Jakub Jelinek > > > > * gcc.dg/ipa/modref-1.c: Remove space between param offset: and number > > in scan-ipa-dump. > > (b): Declare return type to void. > > (main): Declare return type to int. Change c to array of 3 chars. > > * gcc.dg/tree-ssa/modref-4.c: Remove space between param offset: and > > number in scan-ipa-dump. Use modref1 instead of modref2. > > (b): Declare return type to void. > > (main): Declare return type to int. Change c to array of 3 chars. > Sorry for that - I had fixed versions of the testcases but must have > mixed the up. I will look at the reutrn 0 case. Note that even if it optimized as much as it ever could, return 0 is not the correct value, while c[0] is unmodified and the optimization correctly proves that it isn't and optimizes it into 0, c[2] is modified - it is changed from 0 to 1. Perhaps you meant c[4]={0,1,0,0}; and check if c[0]+c[3] is optimized into 0? Jakub
Re: Handle POINTER_PLUS_EXPR in jump functions
> On Wed, Oct 14, 2020 at 03:40:33PM +0200, Jan Hubicka wrote: > > this patch adds logic to handle POINTER_PLUS_EXPR in compute_parm_map > > that I originally did not since I tought that all such adjustments are > > done by ancestor function. > > > > Bootstrapped/regtested x86_64-linux, will commit it shortly. > > Honza > > > > gcc/ChangeLog: > > > > 2020-10-14 Jan Hubicka > > > > * ipa-modref.c (compute_parm_map): Handle POINTER_PLUS_EXPR in > > PASSTHROUGH. > > > > gcc/testsuite/ChangeLog: > > > > 2020-10-14 Jan Hubicka > > > > * gcc.dg/ipa/modref-1.c: New test. > > * gcc.dg/tree-ssa/modref-4.c: New test. > > Both of these tests FAIL everywhere: > FAIL: gcc.dg/ipa/modref-1.c (test for excess errors) > FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 1" > FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 2" > FAIL: gcc.dg/tree-ssa/modref-4.c (test for excess errors) > FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "param offset: 1" > UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "param offset: > 2" > UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "return 0" > > I've tried to fix most of things, but > FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "return 0" > remains (it isn't even optimized in optimized dump). > > Committed to trunk as obvious anyway, but please tweak the modref-4.c > test according to what you meant. > > 2020-10-15 Jakub Jelinek > > * gcc.dg/ipa/modref-1.c: Remove space between param offset: and number > in scan-ipa-dump. > (b): Declare return type to void. > (main): Declare return type to int. Change c to array of 3 chars. > * gcc.dg/tree-ssa/modref-4.c: Remove space between param offset: and > number in scan-ipa-dump. Use modref1 instead of modref2. > (b): Declare return type to void. > (main): Declare return type to int. Change c to array of 3 chars. Sorry for that - I had fixed versions of the testcases but must have mixed the up. I will look at the reutrn 0 case. Honza
Re: Handle POINTER_PLUS_EXPR in jump functions
On Wed, Oct 14, 2020 at 03:40:33PM +0200, Jan Hubicka wrote: > this patch adds logic to handle POINTER_PLUS_EXPR in compute_parm_map > that I originally did not since I tought that all such adjustments are > done by ancestor function. > > Bootstrapped/regtested x86_64-linux, will commit it shortly. > Honza > > gcc/ChangeLog: > > 2020-10-14 Jan Hubicka > > * ipa-modref.c (compute_parm_map): Handle POINTER_PLUS_EXPR in > PASSTHROUGH. > > gcc/testsuite/ChangeLog: > > 2020-10-14 Jan Hubicka > > * gcc.dg/ipa/modref-1.c: New test. > * gcc.dg/tree-ssa/modref-4.c: New test. Both of these tests FAIL everywhere: FAIL: gcc.dg/ipa/modref-1.c (test for excess errors) FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 1" FAIL: gcc.dg/ipa/modref-1.c scan-ipa-dump modref "param offset: 2" FAIL: gcc.dg/tree-ssa/modref-4.c (test for excess errors) FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "param offset: 1" UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "param offset: 2" UNRESOLVED: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref2 "return 0" I've tried to fix most of things, but FAIL: gcc.dg/tree-ssa/modref-4.c scan-tree-dump modref1 "return 0" remains (it isn't even optimized in optimized dump). Committed to trunk as obvious anyway, but please tweak the modref-4.c test according to what you meant. 2020-10-15 Jakub Jelinek * gcc.dg/ipa/modref-1.c: Remove space between param offset: and number in scan-ipa-dump. (b): Declare return type to void. (main): Declare return type to int. Change c to array of 3 chars. * gcc.dg/tree-ssa/modref-4.c: Remove space between param offset: and number in scan-ipa-dump. Use modref1 instead of modref2. (b): Declare return type to void. (main): Declare return type to int. Change c to array of 3 chars. --- gcc/testsuite/gcc.dg/ipa/modref-1.c.jj 2020-10-14 17:03:00.302245922 +0200 +++ gcc/testsuite/gcc.dg/ipa/modref-1.c 2020-10-15 10:13:43.044535887 +0200 @@ -8,16 +8,17 @@ void a(char *ptr, char *ptr2) } __attribute__((noinline)) -b(char *ptr) +void b(char *ptr) { a(ptr+1,&ptr[2]); } -main() + +int main() { - char c[2]={0,1,0}; + char c[3]={0,1,0}; b(c); return c[0]+c[2]; } /* Check that both param offsets are determined correctly. */ -/* { dg-final { scan-ipa-dump "param offset: 1" "modref" } } */ -/* { dg-final { scan-ipa-dump "param offset: 2" "modref" } } */ +/* { dg-final { scan-ipa-dump "param offset:1" "modref" } } */ +/* { dg-final { scan-ipa-dump "param offset:2" "modref" } } */ --- gcc/testsuite/gcc.dg/tree-ssa/modref-4.c.jj 2020-10-14 17:03:00.333245482 +0200 +++ gcc/testsuite/gcc.dg/tree-ssa/modref-4.c2020-10-15 10:12:14.039825998 +0200 @@ -8,18 +8,19 @@ void a(char *ptr, char *ptr2) } __attribute__((noinline)) -b(char *ptr) +void b(char *ptr) { a(ptr+1,&ptr[2]); } -main() + +int main() { - char c[2]={0,1,0}; + char c[3]={0,1,0}; b(c); return c[0]+c[2]; } /* Check that both param offsets are determined correctly and the computation is optimized out. */ -/* { dg-final { scan-tree-dump "param offset: 1" "modref1" } } */ -/* { dg-final { scan-tree-dump "param offset: 2" "modref2" } } */ -/* { dg-final { scan-tree-dump "return 0" "modref2" } } */ +/* { dg-final { scan-tree-dump "param offset:1" "modref1" } } */ +/* { dg-final { scan-tree-dump "param offset:2" "modref1" } } */ +/* { dg-final { scan-tree-dump "return 0" "modref1" } } */ Jakub
Handle POINTER_PLUS_EXPR in jump functions
Hi, this patch adds logic to handle POINTER_PLUS_EXPR in compute_parm_map that I originally did not since I tought that all such adjustments are done by ancestor function. Bootstrapped/regtested x86_64-linux, will commit it shortly. Honza gcc/ChangeLog: 2020-10-14 Jan Hubicka * ipa-modref.c (compute_parm_map): Handle POINTER_PLUS_EXPR in PASSTHROUGH. gcc/testsuite/ChangeLog: 2020-10-14 Jan Hubicka * gcc.dg/ipa/modref-1.c: New test. * gcc.dg/tree-ssa/modref-4.c: New test. diff --git a/gcc/ipa-modref.c b/gcc/ipa-modref.c index a6dfe1fc401..8e6a87643ec 100644 --- a/gcc/ipa-modref.c +++ b/gcc/ipa-modref.c @@ -1682,9 +1682,18 @@ compute_parm_map (cgraph_edge *callee_edge, vec *parm_map) { (*parm_map)[i].parm_index = ipa_get_jf_pass_through_formal_id (jf); - (*parm_map)[i].parm_offset_known - = ipa_get_jf_pass_through_operation (jf) == NOP_EXPR; - (*parm_map)[i].parm_offset = 0; + if (ipa_get_jf_pass_through_operation (jf) == NOP_EXPR) + { + (*parm_map)[i].parm_offset_known = true; + (*parm_map)[i].parm_offset = 0; + } + else if (ipa_get_jf_pass_through_operation (jf) + == POINTER_PLUS_EXPR + && ptrdiff_tree_p (ipa_get_jf_pass_through_operand (jf), + &(*parm_map)[i].parm_offset)) + (*parm_map)[i].parm_offset_known = true; + else + (*parm_map)[i].parm_offset_known = false; continue; } if (jf && jf->type == IPA_JF_ANCESTOR) diff --git a/gcc/testsuite/gcc.dg/ipa/modref-1.c b/gcc/testsuite/gcc.dg/ipa/modref-1.c new file mode 100644 index 000..46eb78ccebf --- /dev/null +++ b/gcc/testsuite/gcc.dg/ipa/modref-1.c @@ -0,0 +1,23 @@ +/* { dg-options "-O2 -fdump-ipa-modref" } */ +/* { dg-do compile } */ +__attribute__((noinline)) +void a(char *ptr, char *ptr2) +{ + (*ptr)++; + (*ptr2)++; +} + +__attribute__((noinline)) +b(char *ptr) +{ + a(ptr+1,&ptr[2]); +} +main() +{ + char c[2]={0,1,0}; + b(c); + return c[0]+c[2]; +} +/* Check that both param offsets are determined correctly. */ +/* { dg-final { scan-ipa-dump "param offset: 1" "modref" } } */ +/* { dg-final { scan-ipa-dump "param offset: 2" "modref" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c b/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c new file mode 100644 index 000..776f46ed687 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/modref-4.c @@ -0,0 +1,25 @@ +/* { dg-options "-O2 -fdump-tree-modref1" } */ +/* { dg-do compile } */ +__attribute__((noinline)) +void a(char *ptr, char *ptr2) +{ + (*ptr)++; + (*ptr2)++; +} + +__attribute__((noinline)) +b(char *ptr) +{ + a(ptr+1,&ptr[2]); +} +main() +{ + char c[2]={0,1,0}; + b(c); + return c[0]+c[2]; +} +/* Check that both param offsets are determined correctly and the computation + is optimized out. */ +/* { dg-final { scan-tree-dump "param offset: 1" "modref1" } } */ +/* { dg-final { scan-tree-dump "param offset: 2" "modref2" } } */ +/* { dg-final { scan-tree-dump "return 0" "modref2" } } */