Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-18 Thread Jeff Law via Gcc-patches
On 11/17/20 9:58 AM, Jakub Jelinek wrote: > On Tue, Nov 17, 2020 at 09:54:46AM -0700, Jeff Law wrote: >>> So, e.g. if we had __builtin_warning (dunno where Martin S. is with that), >>> we could e.g. queue a __builtin_warning and add __builtin_unreachable (or >>> other possibilities), or e.g.

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Jakub Jelinek via Gcc-patches
On Tue, Nov 17, 2020 at 06:23:51PM +0100, Philipp Tomsich wrote: > The rules for E1 << E2 are: > - if E2 is negative => undefined > - if E1 is unsigned => E1 x 2^E2, reduced module one more than the > maximum representable value > - if E1 is signed and non-negative => E1 x 2^E2, if E1 x 2^E2

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Jakub Jelinek via Gcc-patches
On Tue, Nov 17, 2020 at 09:14:31AM -0800, Jim Wilson wrote: > On Tue, Nov 17, 2020 at 8:46 AM Jakub Jelinek via Gcc-patches < > gcc-patches@gcc.gnu.org> wrote: > > > On Tue, Nov 17, 2020 at 05:29:57PM +0100, Philipp Tomsich wrote: > > > > > In other words, the change to VRP canonicalizes what a

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Philipp Tomsich
Jeff & Jakub, I went back to reread the C language standard and it turns out that the delineation between defined and undefined is not as simple as I thought that I remembered (see below). On Tue, 17 Nov 2020 at 17:54, Jeff Law wrote: > > > On 11/17/20 9:46 AM, Jakub Jelinek wrote: > > On Tue,

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Jim Wilson
On Tue, Nov 17, 2020 at 8:46 AM Jakub Jelinek via Gcc-patches < gcc-patches@gcc.gnu.org> wrote: > On Tue, Nov 17, 2020 at 05:29:57PM +0100, Philipp Tomsich wrote: > > > > In other words, the change to VRP canonicalizes what a lshift_expr > with an > > > > shift-amount outside of the type width

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Jakub Jelinek via Gcc-patches
On Tue, Nov 17, 2020 at 09:54:46AM -0700, Jeff Law wrote: > > So, e.g. if we had __builtin_warning (dunno where Martin S. is with that), > > we could e.g. queue a __builtin_warning and add __builtin_unreachable (or > > other possibilities), or e.g. during VRP just canonicalize proven always > >

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Jeff Law via Gcc-patches
On 11/17/20 9:46 AM, Jakub Jelinek wrote: > On Tue, Nov 17, 2020 at 05:29:57PM +0100, Philipp Tomsich wrote: In other words, the change to VRP canonicalizes what a lshift_expr with an shift-amount outside of the type width means... it doesn't assume anything about the original

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Jakub Jelinek via Gcc-patches
On Tue, Nov 17, 2020 at 05:29:57PM +0100, Philipp Tomsich wrote: > > > In other words, the change to VRP canonicalizes what a lshift_expr with an > > > shift-amount outside of the type width means... it doesn't assume anything > > > about the original language. > > > Do we assume that a

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Philipp Tomsich via Gcc-patches
Jeff, On Tue, 17 Nov 2020 at 16:56, Jeff Law wrote: > > Note that in his comment to patch 2/2, Jim has noted that user code for > > RISC-V may assume a truncation of the shift-operand... > What I'd suggest doing would be to leave the invalid shift count in the > IL in VRP, then extend the

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Philipp Tomsich via Gcc-patches
Jakub, On Tue, 17 Nov 2020 at 16:56, Jeff Law wrote: > > > > On 11/17/20 4:53 AM, Philipp Tomsich wrote: > > Jeff, > > > > On Tue, 17 Nov 2020 at 00:38, Jeff Law > > wrote: > > > > > > On 11/16/20 11:57 AM, Philipp Tomsich wrote: > > > From: Philipp Tomsich

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Jeff Law via Gcc-patches
On 11/17/20 4:53 AM, Philipp Tomsich wrote: > Jeff, > > On Tue, 17 Nov 2020 at 00:38, Jeff Law > wrote: > > > On 11/16/20 11:57 AM, Philipp Tomsich wrote: > > From: Philipp Tomsich mailto:p...@gnu.org>> > > > > While most shifts wider than the bitwidth

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-17 Thread Philipp Tomsich
Jeff, On Tue, 17 Nov 2020 at 00:38, Jeff Law wrote: > > On 11/16/20 11:57 AM, Philipp Tomsich wrote: > > From: Philipp Tomsich > > > > While most shifts wider than the bitwidth of a type will be caught by > > other passes, it is possible that these show up for VRP. > > Consider the following

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-16 Thread Jeff Law via Gcc-patches
On 11/16/20 11:57 AM, Philipp Tomsich wrote: > From: Philipp Tomsich > > While most shifts wider than the bitwidth of a type will be caught by > other passes, it is possible that these show up for VRP. > Consider the following example: > int func (int a, int b, int c) > { > return (a <<

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-16 Thread Philipp Tomsich
On Mon, 16 Nov 2020 at 23:38, Jim Wilson wrote: > On Mon, Nov 16, 2020 at 10:57 AM Philipp Tomsich > wrote: > >> This adds simplify_using_ranges::simplify_lshift_using_ranges to >> detect and rewrite such cases. If the intersection of meaningful >> shift amounts for the underlying type and the

Re: [PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-16 Thread Jim Wilson
On Mon, Nov 16, 2020 at 10:57 AM Philipp Tomsich wrote: > This adds simplify_using_ranges::simplify_lshift_using_ranges to > detect and rewrite such cases. If the intersection of meaningful > shift amounts for the underlying type and the value-range computed > for the shift-amount (whether an

[PATCH v1 1/2] Simplify shifts wider than the bitwidth of types

2020-11-16 Thread Philipp Tomsich
From: Philipp Tomsich While most shifts wider than the bitwidth of a type will be caught by other passes, it is possible that these show up for VRP. Consider the following example: int func (int a, int b, int c) { return (a << ((b && c) - 1)); } This adds