Skip to content

Commit

Permalink
Darwin, Arm64 : Truncate char immediates in vector initializers to mo…
Browse files Browse the repository at this point in the history
…de size.

Darwin has signed chars, so that 8b immediates > 127 appear to be negative
which produce large positive (out of assembler range) values when inspected
by UINTVAL ().  This patch truncates the values to the bitrange of the mode
of the input.

Fixes github issue 15.
  • Loading branch information
iains committed Dec 12, 2020
1 parent a4dab49 commit 2db6c40
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions gcc/config/aarch64/aarch64.c
Original file line number Diff line number Diff line change
Expand Up @@ -20406,6 +20406,16 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width,
}

gcc_assert (CONST_INT_P (info.u.mov.value));
unsigned HOST_WIDE_INT value = UINTVAL (info.u.mov.value);

/* We have signed chars which can result in a sign-extended 8bit value
which is then emitted as an unsigned hex value, and the LLVM back end
assembler rejects that as being too big. */
if (TARGET_MACHO && (known_eq (GET_MODE_BITSIZE (info.elt_mode), 8)))
{
unsigned HOST_WIDE_INT mask = (1U << GET_MODE_BITSIZE (info.elt_mode))-1;
value &= mask;
}

if (which == AARCH64_CHECK_MOV)
{
Expand All @@ -20414,16 +20424,16 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width,
? "msl" : "lsl");
if (lane_count == 1)
snprintf (templ, sizeof (templ), "%s\t%%d0, " HOST_WIDE_INT_PRINT_HEX,
mnemonic, UINTVAL (info.u.mov.value));
mnemonic, value);
else if (info.u.mov.shift)
snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, "
HOST_WIDE_INT_PRINT_HEX ", %s %d", mnemonic, lane_count,
element_char, UINTVAL (info.u.mov.value), shift_op,
element_char, value, shift_op,
info.u.mov.shift);
else
snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, "
HOST_WIDE_INT_PRINT_HEX, mnemonic, lane_count,
element_char, UINTVAL (info.u.mov.value));
element_char, value);
}
else
{
Expand All @@ -20432,12 +20442,12 @@ aarch64_output_simd_mov_immediate (rtx const_vector, unsigned width,
if (info.u.mov.shift)
snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, #"
HOST_WIDE_INT_PRINT_DEC ", %s #%d", mnemonic, lane_count,
element_char, UINTVAL (info.u.mov.value), "lsl",
element_char, value, "lsl",
info.u.mov.shift);
else
snprintf (templ, sizeof (templ), "%s\t%%0.%d%c, #"
HOST_WIDE_INT_PRINT_DEC, mnemonic, lane_count,
element_char, UINTVAL (info.u.mov.value));
element_char, value);
}
return templ;
}
Expand Down

0 comments on commit 2db6c40

Please sign in to comment.