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

Hans Wennborg hans at chromium.org
Tue Apr 16 01:38:58 PDT 2013


On Sat, Apr 13, 2013 at 5:32 PM, Jed Davis <jld at panix.com> wrote:
> 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.

This looks good to me. I've committed the patch in r179587.

Thanks,
Hans



More information about the llvm-commits mailing list