Integrated: 8253191: C2: Masked byte comparisons with large masks produce wrong result on x86
Vladimir Ivanov
vlivanov at openjdk.java.net
Thu Oct 8 12:44:48 UTC 2020
On Wed, 7 Oct 2020 10:39:16 GMT, Vladimir Ivanov <vlivanov at openjdk.org> wrote:
> `testUB_mem_imm` generates erroneous code when `mask` constant is larger than `Byte.MAX_VALUE`.
>
> AD instruction in question:
> instruct testUB_mem_imm(rFlagsReg cr, memory mem, immU8 imm, immI0 zero) %{
> match(Set cr (CmpI (AndI (LoadUB mem) imm) zero));
>
> ins_encode %{ __ testb($mem$$Address, $imm$$constant); %}
>
> The following instruction sequence is problematic:
> testb $0x80,0x10(%rdi,%r9,1)
> jle 0x00000001168789a0
>
> It performs *signed* byte comparison and the immediate is interpreted as a negative value.
>
> The original code shape was as follows:
> movzbl 0x10(%rcx,%r9,1),%r9d
> test $0x80,%r9d
> jle 0x000000010a9b6a00
>
> The fix is to narrow the range of accepted mask constants and set the upper limit to `Byte.MAX_VALUE`.
>
> Testing: hs-precheckin-comp, hs-tier1, hs-tier2.
This pull request has now been integrated.
Changeset: 6d13c766
Author: Vladimir Ivanov <vlivanov at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/6d13c766
Stats: 78 lines in 2 files changed: 28 ins; 23 del; 27 mod
8253191: C2: Masked byte comparisons with large masks produce wrong result on x86
Reviewed-by: thartmann
-------------
PR: https://git.openjdk.java.net/jdk/pull/538
More information about the hotspot-compiler-dev
mailing list