diff options
author | James Molloy <james.molloy@arm.com> | 2016-08-01 07:45:11 +0000 |
---|---|---|
committer | James Molloy <james.molloy@arm.com> | 2016-08-01 07:45:11 +0000 |
commit | b2e436de423aac1de4d764166317dd7ab9cbf751 (patch) | |
tree | 091b83177e1acf38e066b816a525bbe2b9b599cc /llvm/test/CodeGen/AMDGPU/si-annotate-cfg-loop-assert.ll | |
parent | 9f0546b5a9bf407b46ac96cd76a387a9bdcf28cb (diff) | |
download | bcm5719-llvm-b2e436de423aac1de4d764166317dd7ab9cbf751.tar.gz bcm5719-llvm-b2e436de423aac1de4d764166317dd7ab9cbf751.zip |
[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
Diffstat (limited to 'llvm/test/CodeGen/AMDGPU/si-annotate-cfg-loop-assert.ll')
0 files changed, 0 insertions, 0 deletions