[PATCH] simplifycfg: Fix integer overflow converting switch into icmp

Jed Davis jld at panix.com
Sat Apr 13 09:32:38 PDT 2013


If a switch instruction has a case for every possible value of its type,
with the same successor, SimplifyCFG would replace it with an icmp ult,
but the computation of the bound overflows in that case, which inverts
the test.  This patch fixes that.

Context: I ran into this while using switch at type i1, in a change I'm
working on for the Rust compiler.  Obviously a simple br instruction
would suffice for that, but I was trying to minimize changes to Rust's
core pattern-matching code.  In any case, this is (as far as I know) a
valid instruction.

I don't know if this change is "the right way" to fix this, but it
passes the test case I added, and doesn't affect code that doesn't have
this kind of degenerate switch.

--Jed

-------------- next part --------------
A non-text attachment was scrubbed...
Name: llvm-simplifycfg-overflow-2013041300.diff
Type: text/patch
Size: 1886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130413/1570d0a3/attachment.bin>


More information about the llvm-commits mailing list