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.

(cherry picked from commit 9060dd0ac879a3bf2f2950ac7fa41b65072bc219)
  • Loading branch information
iains authored and catap committed May 3, 2023
1 parent fc96981 commit 914931c
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 @@ -20156,6 +20156,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 @@ -20164,16 +20174,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 @@ -20182,12 +20192,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 914931c

Please sign in to comment.