From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4308 invoked by alias); 17 Feb 2013 15:27:49 -0000 Received: (qmail 3845 invoked by uid 48); 17 Feb 2013 15:27:23 -0000 From: "olegendo at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/56365] New: Missed opportunities for smin/smax standard name patterns Date: Sun, 17 Feb 2013 15:27:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: olegendo at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 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 X-SW-Source: 2013-02/txt/msg01735.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56365 Bug #: 56365 Summary: Missed opportunities for smin/smax standard name patterns Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: olegendo@gcc.gnu.org While working on a patch for PR 55303 to add signed / unsigned clipping insns for the SH2A target, I've noticed the following (tested with -O2 on 196091 for SH and ARM cross configs): int test_03 (int a, int b) { int r = a + b; if (r > 127) r = 127; else if (r < -128) r = -128; return r; } This will utilize smin / smax standard name patterns. The following equivalent (if I'm not mistaken), however: static inline int min (int a, int b) { return a < b ? a : b; } static inline int max (int a, int b) { return a < b ? b : a; } int test_04 (int a, int b) { return max (-128, min (127, a)); } will not expand to smin / smax patterns. Another case is: int test_05 (int a) { if (127 <= a) a = 127; else if (a <= -128) a = -128; return a; } For integers this could also be done with smin / smax, but it isn't.