James Molloy
b2e436de42
[SimplifyCFG] Range reduce switches
...
If a switch is sparse and all the cases (once sorted) are in arithmetic progression, we can extract the common factor out of the switch and create a dense switch. For example:
switch (i) {
case 5: ...
case 9: ...
case 13: ...
case 17: ...
}
can become:
if ( (i - 5) % 4 ) goto default;
switch ((i - 5) / 4) {
case 0: ...
case 1: ...
case 2: ...
case 3: ...
}
or even better:
switch ( ROTR(i - 5, 2) {
case 0: ...
case 1: ...
case 2: ...
case 3: ...
}
The division and remainder operations could be costly so we only do this if the factor is a power of two, and emit a right-rotate instead of a divide/remainder sequence. Dense switches can be lowered significantly better than sparse switches and can even be transformed into lookup tables.
llvm-svn: 277325
2016-08-01 07:45:11 +00:00
..
2015-11-10 18:11:37 +00:00
2015-06-19 17:39:03 +00:00
2015-11-10 19:24:31 +00:00
2015-11-11 17:24:56 +00:00
2015-02-13 14:15:48 +00:00
2014-06-09 22:42:55 +00:00
2016-03-29 04:08:57 +00:00
2015-06-17 20:52:32 +00:00
2015-03-13 18:20:45 +00:00
2016-03-28 22:12:21 +00:00
2015-02-27 21:17:42 +00:00
2015-02-27 19:29:02 +00:00
2015-06-17 20:52:32 +00:00
2015-02-27 21:17:42 +00:00
2015-02-27 21:17:42 +00:00
2015-02-27 21:17:42 +00:00
2015-06-17 20:52:32 +00:00
2015-04-16 23:24:18 +00:00
2015-02-27 21:17:42 +00:00
2016-03-29 04:08:57 +00:00
2016-04-30 00:02:36 +00:00
2015-02-27 21:17:42 +00:00
2015-04-16 23:24:18 +00:00
2015-02-27 21:17:42 +00:00
2015-06-17 20:52:32 +00:00
2015-06-17 20:52:32 +00:00
2014-07-25 21:13:35 +00:00
2016-02-12 21:01:36 +00:00
2015-02-27 19:29:02 +00:00
2016-05-06 14:25:14 +00:00
2016-04-15 15:57:41 +00:00
2015-02-27 21:17:42 +00:00
2015-02-27 21:17:42 +00:00
2016-01-10 05:48:01 +00:00
2015-02-13 11:08:40 +00:00
2016-04-26 02:06:06 +00:00
2015-04-16 23:24:18 +00:00
2015-02-27 21:17:42 +00:00
2015-06-17 20:52:32 +00:00
2016-01-05 02:37:41 +00:00
2016-06-04 23:50:03 +00:00
2015-02-27 21:17:42 +00:00
2016-03-29 04:08:57 +00:00
2016-04-21 05:09:12 +00:00
2015-02-27 21:17:42 +00:00
2016-04-15 15:57:41 +00:00
2015-02-27 21:17:42 +00:00
2016-04-25 17:23:36 +00:00
2016-05-05 15:39:18 +00:00
2016-04-25 18:20:27 +00:00
2015-10-29 03:11:49 +00:00
2015-02-27 21:17:42 +00:00
2016-02-03 23:54:25 +00:00
2016-01-10 05:48:01 +00:00
2016-06-25 08:19:55 +00:00
2015-02-27 21:17:42 +00:00
2016-05-02 19:43:22 +00:00
2015-03-13 18:20:45 +00:00
2016-02-20 01:07:45 +00:00
2016-01-27 21:53:08 +00:00
2015-12-14 22:36:57 +00:00
2015-02-27 21:17:42 +00:00
2015-10-14 00:21:05 +00:00
2015-02-27 21:17:42 +00:00
2015-02-27 21:17:42 +00:00
2016-03-28 22:12:21 +00:00
2016-03-17 15:30:52 +00:00
2016-03-28 22:12:21 +00:00
2015-02-27 21:17:42 +00:00
2015-10-21 18:22:24 +00:00
2016-05-04 15:40:57 +00:00
2014-12-15 19:07:53 +00:00
2014-12-15 19:07:53 +00:00
2016-05-18 22:41:03 +00:00
2015-11-02 17:53:51 +00:00
2015-11-02 17:53:51 +00:00
2015-11-02 17:53:51 +00:00
2015-08-07 19:30:12 +00:00
2016-08-01 07:45:11 +00:00
2015-06-17 20:52:32 +00:00
2015-02-27 19:29:02 +00:00
2014-12-23 08:26:55 +00:00
2016-01-27 02:59:41 +00:00
2016-03-26 23:30:50 +00:00
2015-02-27 21:17:42 +00:00
2015-11-18 14:50:18 +00:00
2015-12-26 07:54:32 +00:00
2016-06-24 01:59:00 +00:00
2016-03-16 23:39:37 +00:00
2016-03-16 23:22:01 +00:00
2015-09-10 17:44:47 +00:00
2016-05-20 14:53:09 +00:00
2015-01-26 19:52:32 +00:00
2014-12-04 22:19:25 +00:00
2015-02-27 21:17:42 +00:00
2015-01-26 19:52:32 +00:00
2016-06-25 08:19:55 +00:00
2016-06-25 08:19:55 +00:00
2016-04-15 15:32:12 +00:00
2015-02-27 21:17:42 +00:00
2016-02-24 10:02:16 +00:00
2016-06-25 07:37:27 +00:00
2015-04-16 23:24:18 +00:00
2016-01-05 07:42:17 +00:00