]> granicus.if.org Git - llvm/commit
Merging r213815:
authorHans Wennborg <hans@hanshq.net>
Tue, 29 Jul 2014 23:38:58 +0000 (23:38 +0000)
committerHans Wennborg <hans@hanshq.net>
Tue, 29 Jul 2014 23:38:58 +0000 (23:38 +0000)
commitd97455ba309cfd01eede1773660e7995e04105d9
treea7d7ef53ff0ba3f0502d9ec903e6e9e66e3dd867
parent1b7ea62aa83adf7c18298cf5a8914f3d32728a15
Merging r213815:
------------------------------------------------------------------------
r213815 | mren | 2014-07-23 16:13:23 -0700 (Wed, 23 Jul 2014) | 17 lines

SimplifyCFG: fix a bug in switch to table conversion

We use gep to access the global array "switch.table", and the table index
should be treated as unsigned. When the highest bit is 1, this commit
zero-extends the index to an integer type with larger size.

For a switch on i2, we used to generate:
%switch.tableidx = sub i2 %0, -2
getelementptr inbounds [4 x i64]* @switch.table, i32 0, i2 %switch.tableidx

It is incorrect when %switch.tableidx is 2 or 3. The fix is to generate
%switch.tableidx = sub i2 %0, -2
%switch.tableidx.zext = zext i2 %switch.tableidx to i3
getelementptr inbounds [4 x i64]* @switch.table, i32 0, i3 %switch.tableidx.zext

rdar://17735071

------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_35@214251 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Utils/SimplifyCFG.cpp
test/Transforms/SimplifyCFG/switch-table-bug.ll [new file with mode: 0644]