[WebAssembly] Do not omit range checks for i64 switches
authorThomas Lively <tlively@google.com>
Sat, 4 Jul 2020 00:15:39 +0000 (17:15 -0700)
committerThomas Lively <tlively@google.com>
Sat, 4 Jul 2020 00:15:39 +0000 (17:15 -0700)
commit8df30d988e9e595fa9883706198aec23b2e6d227
tree6055031aaf44f8fdc475e701b6918f6634dff219
parent1c6e2eceeb1fe9faa9f7e95424e2a7f1b1d0fb9a
[WebAssembly] Do not omit range checks for i64 switches

Summary:
Since the br_table instruction takes an i32, switches over i64s (and
larger integers) must use the i32.wrap_i64 instruction to truncate the
table index. This truncation makes numbers just over 2^32
indistinguishable from small numbers, so it was a miscompilation to
omit the range check preceding these br_tables. This change fixes the
problem by skipping the "fixing" of the br_table when the range check
is an i64 instruction.

Fixes PR46447.

Reviewers: aheejin, dschuff, kripken

Reviewed By: kripken

Subscribers: sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D83017
llvm/lib/Target/WebAssembly/WebAssemblyFixBrTableDefaults.cpp
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
llvm/test/CodeGen/WebAssembly/switch.ll