From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11872 invoked by alias); 29 Jan 2014 12:25:06 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 11798 invoked by uid 48); 29 Jan 2014 12:25:03 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/58742] pointer arithmetic simplification Date: Wed, 29 Jan 2014 12:25:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-01/txt/msg03005.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58742 --- Comment #21 from Richard Biener --- Ok, I have a patch that does the remaining (including the duplicate bug). But for the (p + sz) - p case it can only optimize the sizeof (*p) == 1 without range information - for example for __SIZE_TYPE__ fx (int *a, __SIZE_TYPE__ sz) { int *b = a + sz; return b - a; } we get fx (int * a, long unsigned int sz) { int * b; long unsigned int _2; long int _7; long int _8; long unsigned int _9; : _2 = sz_1(D) * 4; _7 = (long int) _2; _8 = _7 /[ex] 4; _9 = (long unsigned int) _8; return _9; } as result which is basically (sz * 4) /[ex] 4 as we don't know whether the multiplication by 4 overflows (well, the C language may say it doesn't but the IL does not reflect this). If we make 'sz' a signed int then VRP could later optimize this (but it doesn't currently), or forwprop could use range information. On RTL we manage to optimize the signed int input case.