From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2731 invoked by alias); 14 Jul 2009 17:09:29 -0000 Received: (qmail 2621 invoked by uid 48); 14 Jul 2009 17:09:16 -0000 Date: Tue, 14 Jul 2009 17:09:00 -0000 Subject: [Bug c/40748] New: simple switch/case, if/else and arithmetics result in different code X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "zsojka at seznam dot cz" 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: 2009-07/txt/msg01131.txt.bz2 Tested r149624, 4.4.0 and 4.3.3 # ./gcc -v Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../configure --enable-languages=c,c++ --prefix=/mnt/svn/gcc-trunk/build/ Thread model: posix gcc version 4.5.0 20090714 (experimental) (GCC) 4.4.0 and 4.5 have better behaviour in the case of "switch" The following code: ------------------------------- unsigned f1(unsigned i) { switch (i) { case 0: return 0; case 1: return 1; case 2: return 2; case 3: return 3; default: return 4; } } unsigned f2(unsigned i) { if (i == 0) return 0; if (i == 1) return 1; if (i == 2) return 2; if (i == 3) return 3; return 4; } unsigned f3(unsigned i) { return i < 4 ? i : 4; } ------------------------------- f1(), f2() and f3() do the same, but the resulting code differs a lot. -- Summary: simple switch/case, if/else and arithmetics result in different code Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: zsojka at seznam dot cz GCC host triplet: x86_64-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40748