Re-commit r355490 "[CodeGen] Omit range checks from jump tables when lowering switche...
authorHans Wennborg <hans@hanshq.net>
Wed, 27 Mar 2019 14:10:11 +0000 (14:10 +0000)
committerHans Wennborg <hans@hanshq.net>
Wed, 27 Mar 2019 14:10:11 +0000 (14:10 +0000)
commit5c0d7a24e8e5a1aa9632832b65157e62a6d4b553
treef81f5d34581a4db00b1031856bfcd915ff9d3a1b
parent40f0162a9a99f2a4882196092eb4d43cf5ef7f12
Re-commit r355490 "[CodeGen] Omit range checks from jump tables when lowering switches with unreachable default"

Original commit by Ayonam Ray.

This commit adds a regression test for the issue discovered in the
previous commit: that the range check for the jump table can only be
omitted if the fall-through destination of the jump table is
unreachable, which isn't necessarily true just because the default of
the switch is unreachable.

This addresses the missing optimization in PR41242.

> During the lowering of a switch that would result in the generation of a
> jump table, a range check is performed before indexing into the jump
> table, for the switch value being outside the jump table range and a
> conditional branch is inserted to jump to the default block. In case the
> default block is unreachable, this conditional jump can be omitted. This
> patch implements omitting this conditional branch for unreachable
> defaults.
>
> Differential Revision: https://reviews.llvm.org/D52002
> Reviewers: Hans Wennborg, Eli Freidman, Roman Lebedev

llvm-svn: 357067
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
llvm/test/CodeGen/AArch64/switch-unreachable-default.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/pr38743.ll
llvm/test/CodeGen/X86/switch-jump-table.ll