* [PATCH] Fix PR88301
@ 2018-12-03 13:37 Richard Biener
2018-12-04 13:14 ` Christophe Lyon
0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2018-12-03 13:37 UTC (permalink / raw)
To: gcc-patches
This fixes a missed optimization in EVRP by teaching the code
figuring out conditional asserts about conversions that preserve
the converted value.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk
sofar.
Richard.
2018-12-03 Richard Biener <rguenther@suse.de>
PR tree-optimization/88301
* tree-vrp.c (register_edge_assert_for_2): Handle conversions
that do not change the value by registering the same assert
for the operand.
* gcc.dg/tree-ssa/evrp13.c: New testcase.
Index: gcc/tree-vrp.c
===================================================================
--- gcc/tree-vrp.c (revision 266733)
+++ gcc/tree-vrp.c (working copy)
@@ -2966,6 +2966,23 @@ register_edge_assert_for_2 (tree name, e
add_assert_info (asserts, name2, tmp, new_comp_code, new_val);
}
+ /* If we have a conversion that doesn't change the value of the source
+ simply register the same assert for it. */
+ if (CONVERT_EXPR_CODE_P (rhs_code))
+ {
+ wide_int rmin, rmax;
+ tree rhs1 = gimple_assign_rhs1 (def_stmt);
+ if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
+ && int_fits_type_p (val, TREE_TYPE (rhs1))
+ && ((TYPE_PRECISION (TREE_TYPE (name))
+ > TYPE_PRECISION (TREE_TYPE (rhs1)))
+ || (get_range_info (rhs1, &rmin, &rmax) == VR_RANGE
+ && wi::fits_to_tree_p (rmin, TREE_TYPE (name))
+ && wi::fits_to_tree_p (rmax, TREE_TYPE (name)))))
+ add_assert_info (asserts, rhs1, rhs1,
+ comp_code, fold_convert (TREE_TYPE (rhs1), val));
+ }
+
/* Add asserts for NAME cmp CST and NAME being defined as
NAME = NAME2 & CST2.
Index: gcc/testsuite/gcc.dg/tree-ssa/evrp13.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/evrp13.c (revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/evrp13.c (working copy)
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-evrp" } */
+
+#define ADD_NW(A,B) (__extension__({ __typeof(A+B) R; if(__builtin_add_overflow(A,B,&R)) __builtin_unreachable(); R ;}))
+_Bool a_b2(unsigned A, unsigned B) { return ADD_NW(A,B) >= B; }
+
+/* { dg-final { scan-tree-dump "return 1;" "evrp" } } */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR88301
2018-12-03 13:37 [PATCH] Fix PR88301 Richard Biener
@ 2018-12-04 13:14 ` Christophe Lyon
2018-12-04 13:17 ` Richard Biener
0 siblings, 1 reply; 4+ messages in thread
From: Christophe Lyon @ 2018-12-04 13:14 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc Patches
Hi Richard,
On Mon, 3 Dec 2018 at 14:37, Richard Biener <rguenther@suse.de> wrote:
>
>
> This fixes a missed optimization in EVRP by teaching the code
> figuring out conditional asserts about conversions that preserve
> the converted value.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk
> sofar.
>
> Richard.
>
> 2018-12-03 Richard Biener <rguenther@suse.de>
>
> PR tree-optimization/88301
> * tree-vrp.c (register_edge_assert_for_2): Handle conversions
> that do not change the value by registering the same assert
> for the operand.
>
> * gcc.dg/tree-ssa/evrp13.c: New testcase.
>
I noticed a regression in g++ on aarch64, and git bisect indicates
this commits is the culprit.
g++.dg/warn/Wstringop-overflow-1.C -std=c++14 (test for warnings, line 14)
g++.dg/warn/Wstringop-overflow-1.C -std=c++14 (test for excess errors)
g++.dg/warn/Wstringop-overflow-1.C -std=c++17 (test for warnings, line 14)
g++.dg/warn/Wstringop-overflow-1.C -std=c++17 (test for excess errors)
g++.dg/warn/Wstringop-overflow-1.C -std=c++98 (test for warnings, line 14)
g++.dg/warn/Wstringop-overflow-1.C -std=c++98 (test for excess errors)
g++.log says:
Excess errors:
/gcc/testsuite/g++.dg/warn/Wstringop-overflow-1.C:14:21: warning:
'char* __builtin_strncpy(char*, const char*, long unsigned int)'
writing between 6 and 2147483647 bytes into a region of size 5
overflows the destination [-Wstringop-overflow=]
Christophe
> Index: gcc/tree-vrp.c
> ===================================================================
> --- gcc/tree-vrp.c (revision 266733)
> +++ gcc/tree-vrp.c (working copy)
> @@ -2966,6 +2966,23 @@ register_edge_assert_for_2 (tree name, e
> add_assert_info (asserts, name2, tmp, new_comp_code, new_val);
> }
>
> + /* If we have a conversion that doesn't change the value of the source
> + simply register the same assert for it. */
> + if (CONVERT_EXPR_CODE_P (rhs_code))
> + {
> + wide_int rmin, rmax;
> + tree rhs1 = gimple_assign_rhs1 (def_stmt);
> + if (INTEGRAL_TYPE_P (TREE_TYPE (rhs1))
> + && int_fits_type_p (val, TREE_TYPE (rhs1))
> + && ((TYPE_PRECISION (TREE_TYPE (name))
> + > TYPE_PRECISION (TREE_TYPE (rhs1)))
> + || (get_range_info (rhs1, &rmin, &rmax) == VR_RANGE
> + && wi::fits_to_tree_p (rmin, TREE_TYPE (name))
> + && wi::fits_to_tree_p (rmax, TREE_TYPE (name)))))
> + add_assert_info (asserts, rhs1, rhs1,
> + comp_code, fold_convert (TREE_TYPE (rhs1), val));
> + }
> +
> /* Add asserts for NAME cmp CST and NAME being defined as
> NAME = NAME2 & CST2.
>
> Index: gcc/testsuite/gcc.dg/tree-ssa/evrp13.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/tree-ssa/evrp13.c (revision 0)
> +++ gcc/testsuite/gcc.dg/tree-ssa/evrp13.c (working copy)
> @@ -0,0 +1,7 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fdump-tree-evrp" } */
> +
> +#define ADD_NW(A,B) (__extension__({ __typeof(A+B) R; if(__builtin_add_overflow(A,B,&R)) __builtin_unreachable(); R ;}))
> +_Bool a_b2(unsigned A, unsigned B) { return ADD_NW(A,B) >= B; }
> +
> +/* { dg-final { scan-tree-dump "return 1;" "evrp" } } */
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR88301
2018-12-04 13:14 ` Christophe Lyon
@ 2018-12-04 13:17 ` Richard Biener
2018-12-05 15:08 ` Christophe Lyon
0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2018-12-04 13:17 UTC (permalink / raw)
To: Christophe Lyon; +Cc: gcc Patches
On Tue, 4 Dec 2018, Christophe Lyon wrote:
> Hi Richard,
> On Mon, 3 Dec 2018 at 14:37, Richard Biener <rguenther@suse.de> wrote:
> >
> >
> > This fixes a missed optimization in EVRP by teaching the code
> > figuring out conditional asserts about conversions that preserve
> > the converted value.
> >
> > Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk
> > sofar.
> >
> > Richard.
> >
> > 2018-12-03 Richard Biener <rguenther@suse.de>
> >
> > PR tree-optimization/88301
> > * tree-vrp.c (register_edge_assert_for_2): Handle conversions
> > that do not change the value by registering the same assert
> > for the operand.
> >
> > * gcc.dg/tree-ssa/evrp13.c: New testcase.
> >
>
> I noticed a regression in g++ on aarch64, and git bisect indicates
> this commits is the culprit.
> g++.dg/warn/Wstringop-overflow-1.C -std=c++14 (test for warnings, line 14)
> g++.dg/warn/Wstringop-overflow-1.C -std=c++14 (test for excess errors)
> g++.dg/warn/Wstringop-overflow-1.C -std=c++17 (test for warnings, line 14)
> g++.dg/warn/Wstringop-overflow-1.C -std=c++17 (test for excess errors)
> g++.dg/warn/Wstringop-overflow-1.C -std=c++98 (test for warnings, line 14)
> g++.dg/warn/Wstringop-overflow-1.C -std=c++98 (test for excess errors)
>
> g++.log says:
> Excess errors:
> /gcc/testsuite/g++.dg/warn/Wstringop-overflow-1.C:14:21: warning:
> 'char* __builtin_strncpy(char*, const char*, long unsigned int)'
> writing between 6 and 2147483647 bytes into a region of size 5
> overflows the destination [-Wstringop-overflow=]
Yes, sorry. r266773 should have fixed this.
Richard.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fix PR88301
2018-12-04 13:17 ` Richard Biener
@ 2018-12-05 15:08 ` Christophe Lyon
0 siblings, 0 replies; 4+ messages in thread
From: Christophe Lyon @ 2018-12-05 15:08 UTC (permalink / raw)
To: Richard Biener; +Cc: gcc Patches
On Tue, 4 Dec 2018 at 14:17, Richard Biener <rguenther@suse.de> wrote:
>
> On Tue, 4 Dec 2018, Christophe Lyon wrote:
>
> > Hi Richard,
> > On Mon, 3 Dec 2018 at 14:37, Richard Biener <rguenther@suse.de> wrote:
> > >
> > >
> > > This fixes a missed optimization in EVRP by teaching the code
> > > figuring out conditional asserts about conversions that preserve
> > > the converted value.
> > >
> > > Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk
> > > sofar.
> > >
> > > Richard.
> > >
> > > 2018-12-03 Richard Biener <rguenther@suse.de>
> > >
> > > PR tree-optimization/88301
> > > * tree-vrp.c (register_edge_assert_for_2): Handle conversions
> > > that do not change the value by registering the same assert
> > > for the operand.
> > >
> > > * gcc.dg/tree-ssa/evrp13.c: New testcase.
> > >
> >
> > I noticed a regression in g++ on aarch64, and git bisect indicates
> > this commits is the culprit.
> > g++.dg/warn/Wstringop-overflow-1.C -std=c++14 (test for warnings, line 14)
> > g++.dg/warn/Wstringop-overflow-1.C -std=c++14 (test for excess errors)
> > g++.dg/warn/Wstringop-overflow-1.C -std=c++17 (test for warnings, line 14)
> > g++.dg/warn/Wstringop-overflow-1.C -std=c++17 (test for excess errors)
> > g++.dg/warn/Wstringop-overflow-1.C -std=c++98 (test for warnings, line 14)
> > g++.dg/warn/Wstringop-overflow-1.C -std=c++98 (test for excess errors)
> >
> > g++.log says:
> > Excess errors:
> > /gcc/testsuite/g++.dg/warn/Wstringop-overflow-1.C:14:21: warning:
> > 'char* __builtin_strncpy(char*, const char*, long unsigned int)'
> > writing between 6 and 2147483647 bytes into a region of size 5
> > overflows the destination [-Wstringop-overflow=]
>
> Yes, sorry. r266773 should have fixed this.
>
Indeed, thanks.
> Richard.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-12-05 15:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-03 13:37 [PATCH] Fix PR88301 Richard Biener
2018-12-04 13:14 ` Christophe Lyon
2018-12-04 13:17 ` Richard Biener
2018-12-05 15:08 ` Christophe Lyon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).