This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

middle-end/9707: Unnecessary range test in switches with less than 4 cases


>Number:         9707
>Category:       middle-end
>Synopsis:       Unnecessary range test in switches with less than 4 cases
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          pessimizes-code
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 14 16:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Tamás Gergely
>Release:        gcc version 3.3 20030210 (prerelease)
>Organization:
>Environment:
BUILD & HOST: Linux 2.4.20 i686 unknown
TARGET: arm-unknown-elf
>Description:
When a switch has less than 4 cases gcc tests for the middle-case-value and makes an additional less-greater check instead of immediately evaluating the other case-values. If there are more case branches in the switch, this kind of checking would speed up the search of the corresponding case branch (but those switches are solved with jump-tables anyway). But for only a few case branches, the direct equality checks would be better.
>How-To-Repeat:
arm-elf-gcc -S -g0 -Os -o 01_3d.s ./01_3d.i

//01_3d.i

# 1 "01_3d.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "01_3d.c"
unsigned int g;
int main ()
{
  int r;
  switch (r) {
    case 1:
             g=11;
        break;
    case 2:
             g=12;
        break;
    case 3:
             g=13;
        break;
    default:
             g=20;
        break;
  }
  return 0;
}
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/x-gzip; name="switch.tar.gz"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="switch.tar.gz"

H4sIAAgbTT4AA+2YXW/aMBSGuQ0S/+GIbhJIJPMHHyus06RedBfTdjHtappQSA6Z1SRmjlPWTfvv
s01KUb+lCaZKfi6Iffwex8GcFwyhc55GorVPCCVkPCYtQgidjIb2Suhwc7WMOG+RyZhxRobcxikl
bNQCstdVNdSVjhVAK0OlZXG/Ls4xOcR6DswRUOgS9yFIup22675Z1CLXoSjfbiOJLIq4TCEXJW6j
12l1WYmsxBREqSGbddr2WsSihF6/0/7daYMbUTPbqtZCJ9+hp/rgRgCSuEKg001nS3ZC6ew6tlAY
n892EtgdCeyhBH5HAr8nIcVlXOf6dgYjd2b8sS8Kda1KsArT/99b+yQ2e1jt+R4P1j8ldmxT/3w0
Zq7++dDX/yEIoqXIMdip5SDS+FPba5ybog6YbWa5XMR5YEvaKS5X6DoDeLmsy0QLaeI2YAomeAex
yio4ATKAlakJNMbhOksVF2ibTuR68xIxxWa8rrCax6UsLwtZm1Yzi1Mb5zk3BZaJSqOCKr5AwFwU
oow1ppGRJMUqUHwAR2yjV9BMvZTKLEPmMqvRDBXyAn8EihkltdKF6UUfjm0r06b1encueiPB9hdG
RM2ijHS6q+U3tNxKKJluwiVuwsxlHttoniqXaVTNfQJl3oUj+8CVVk7/1U1NvjXjq2RgnsxNbO1v
Z4/sJC6ylioNMtuqxK+rXYrCq62zTh5kAxgOgLutFSmWOuienZ5OoXf28UsfeMSBEcIJowR6ZgcV
5mgMtN99JqbmeTKu7ueFTMVS4J6+CB71/yHd/v4jfGz0bDwh3v8Pgff/a/9/2PVvy7zhe5475gCT
Frjfezx2/ieTUeP/lE+YO/8z7v3/ILyXa9DSGOsKY3vafWG8uwgxX4ZZkkD4GcKMQPipglBCc1aE
6BU5wL9GHo/H4/F4PB6Px+PxeDwej8fj+Rf+AoRk6ToAKAAA


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]