[ARM] PR 82445 - suppress 32-bit aligned ldrd/strd peepholing with -mno-unaligned-access
Peephole patterns exist in the arm backend to spot load/store operations to adjacent memory operations in order to convert them into ldrd/strd instructions. However, when we have strict alignment enforced, then we can only do this if the accesses are known to be 64-bit aligned; this is unlikely to be the case for most loads. The patch adds some alignment checking to the code that validates the addresses for use in the peephole patterns. This should also fix incorrect generation of ldrd/strd with unaligned accesses that could previously have occurred on ARMv5e where all such operations must be 64-bit aligned. I've added some new tests as well. In doing so I discovered that the ldrd/strd peephole tests could never fail since they would match the source file name in the scanned assembly as well as any instructions of the intended type. I've fixed those by tightening the scan results slightly. gcc: * config/arm/arm.c (align_ok_ldrd_strd): New function. (mem_ok_for_ldrd_strd): New parameter align. Extract the alignment of the mem into it. (gen_operands_ldrd_strd): Validate the alignment of the accesses. testsuite: * gcc.target/arm/peep-ldrd-1.c: Tighten test scan pattern. * gcc.target/arm/peep-strd-1.c: Likewise. * gcc.target/arm/peep-ldrd-2.c: New test. * gcc.target/arm/peep-strd-2.c: New test. From-SVN: r253891
This commit is contained in:
parent
925a6f3aaa
commit
ca7e162896
@ -1,3 +1,11 @@
|
|||||||
|
2017-10-19 Richard Earnshaw <rearnsha@arm.com>
|
||||||
|
|
||||||
|
PR target/82445
|
||||||
|
* config/arm/arm.c (align_ok_ldrd_strd): New function.
|
||||||
|
(mem_ok_for_ldrd_strd): New parameter align. Extract the alignment of
|
||||||
|
the mem into it.
|
||||||
|
(gen_operands_ldrd_strd): Validate the alignment of the accesses.
|
||||||
|
|
||||||
2017-10-18 Segher Boessenkool <segher@kernel.crashing.org>
|
2017-10-18 Segher Boessenkool <segher@kernel.crashing.org>
|
||||||
|
|
||||||
PR rtl-optimization/82602
|
PR rtl-optimization/82602
|
||||||
|
@ -15199,12 +15199,23 @@ operands_ok_ldrd_strd (rtx rt, rtx rt2, rtx rn, HOST_WIDE_INT offset,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return true if a 64-bit access with alignment ALIGN and with a
|
||||||
|
constant offset OFFSET from the base pointer is permitted on this
|
||||||
|
architecture. */
|
||||||
|
static bool
|
||||||
|
align_ok_ldrd_strd (HOST_WIDE_INT align, HOST_WIDE_INT offset)
|
||||||
|
{
|
||||||
|
return (unaligned_access
|
||||||
|
? (align >= BITS_PER_WORD && (offset & 3) == 0)
|
||||||
|
: (align >= 2 * BITS_PER_WORD && (offset & 7) == 0));
|
||||||
|
}
|
||||||
|
|
||||||
/* Helper for gen_operands_ldrd_strd. Returns true iff the memory
|
/* Helper for gen_operands_ldrd_strd. Returns true iff the memory
|
||||||
operand MEM's address contains an immediate offset from the base
|
operand MEM's address contains an immediate offset from the base
|
||||||
register and has no side effects, in which case it sets BASE and
|
register and has no side effects, in which case it sets BASE,
|
||||||
OFFSET accordingly. */
|
OFFSET and ALIGN accordingly. */
|
||||||
static bool
|
static bool
|
||||||
mem_ok_for_ldrd_strd (rtx mem, rtx *base, rtx *offset)
|
mem_ok_for_ldrd_strd (rtx mem, rtx *base, rtx *offset, HOST_WIDE_INT *align)
|
||||||
{
|
{
|
||||||
rtx addr;
|
rtx addr;
|
||||||
|
|
||||||
@ -15223,6 +15234,7 @@ mem_ok_for_ldrd_strd (rtx mem, rtx *base, rtx *offset)
|
|||||||
gcc_assert (MEM_P (mem));
|
gcc_assert (MEM_P (mem));
|
||||||
|
|
||||||
*offset = const0_rtx;
|
*offset = const0_rtx;
|
||||||
|
*align = MEM_ALIGN (mem);
|
||||||
|
|
||||||
addr = XEXP (mem, 0);
|
addr = XEXP (mem, 0);
|
||||||
|
|
||||||
@ -15263,7 +15275,7 @@ gen_operands_ldrd_strd (rtx *operands, bool load,
|
|||||||
bool const_store, bool commute)
|
bool const_store, bool commute)
|
||||||
{
|
{
|
||||||
int nops = 2;
|
int nops = 2;
|
||||||
HOST_WIDE_INT offsets[2], offset;
|
HOST_WIDE_INT offsets[2], offset, align[2];
|
||||||
rtx base = NULL_RTX;
|
rtx base = NULL_RTX;
|
||||||
rtx cur_base, cur_offset, tmp;
|
rtx cur_base, cur_offset, tmp;
|
||||||
int i, gap;
|
int i, gap;
|
||||||
@ -15275,7 +15287,8 @@ gen_operands_ldrd_strd (rtx *operands, bool load,
|
|||||||
registers, and the corresponding memory offsets. */
|
registers, and the corresponding memory offsets. */
|
||||||
for (i = 0; i < nops; i++)
|
for (i = 0; i < nops; i++)
|
||||||
{
|
{
|
||||||
if (!mem_ok_for_ldrd_strd (operands[nops+i], &cur_base, &cur_offset))
|
if (!mem_ok_for_ldrd_strd (operands[nops+i], &cur_base, &cur_offset,
|
||||||
|
&align[i]))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
@ -15389,6 +15402,7 @@ gen_operands_ldrd_strd (rtx *operands, bool load,
|
|||||||
/* Swap the instructions such that lower memory is accessed first. */
|
/* Swap the instructions such that lower memory is accessed first. */
|
||||||
std::swap (operands[0], operands[1]);
|
std::swap (operands[0], operands[1]);
|
||||||
std::swap (operands[2], operands[3]);
|
std::swap (operands[2], operands[3]);
|
||||||
|
std::swap (align[0], align[1]);
|
||||||
if (const_store)
|
if (const_store)
|
||||||
std::swap (operands[4], operands[5]);
|
std::swap (operands[4], operands[5]);
|
||||||
}
|
}
|
||||||
@ -15402,6 +15416,9 @@ gen_operands_ldrd_strd (rtx *operands, bool load,
|
|||||||
if (gap != 4)
|
if (gap != 4)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if (!align_ok_ldrd_strd (align[0], offset))
|
||||||
|
return false;
|
||||||
|
|
||||||
/* Make sure we generate legal instructions. */
|
/* Make sure we generate legal instructions. */
|
||||||
if (operands_ok_ldrd_strd (operands[0], operands[1], base, offset,
|
if (operands_ok_ldrd_strd (operands[0], operands[1], base, offset,
|
||||||
false, load))
|
false, load))
|
||||||
|
@ -1,3 +1,11 @@
|
|||||||
|
2017-10-19 Richard Earnshaw <rearnsha@arm.com>
|
||||||
|
|
||||||
|
PR target/82445
|
||||||
|
* gcc.target/arm/peep-ldrd-1.c: Tighten test scan pattern.
|
||||||
|
* gcc.target/arm/peep-strd-1.c: Likewise.
|
||||||
|
* gcc.target/arm/peep-ldrd-2.c: New test.
|
||||||
|
* gcc.target/arm/peep-strd-2.c: New test.
|
||||||
|
|
||||||
2017-10-18 Vladimir Makarov <vmakarov@redhat.com>
|
2017-10-18 Vladimir Makarov <vmakarov@redhat.com>
|
||||||
|
|
||||||
PR middle-end/82556
|
PR middle-end/82556
|
||||||
|
@ -8,4 +8,4 @@ int foo(int a, int b, int* p, int *q)
|
|||||||
*p = a;
|
*p = a;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
/* { dg-final { scan-assembler "ldrd" } } */
|
/* { dg-final { scan-assembler "ldrd\\t" } } */
|
||||||
|
11
gcc/testsuite/gcc.target/arm/peep-ldrd-2.c
Normal file
11
gcc/testsuite/gcc.target/arm/peep-ldrd-2.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
/* { dg-do compile } */
|
||||||
|
/* { dg-require-effective-target arm_prefer_ldrd_strd } */
|
||||||
|
/* { dg-options "-O2 -mno-unaligned-access" } */
|
||||||
|
int foo(int a, int b, int* p, int *q)
|
||||||
|
{
|
||||||
|
a = p[2] + p[3];
|
||||||
|
*q = a;
|
||||||
|
*p = a;
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
/* { dg-final { scan-assembler-not "ldrd\\t" } } */
|
@ -6,4 +6,4 @@ void foo(int a, int b, int* p)
|
|||||||
p[2] = a;
|
p[2] = a;
|
||||||
p[3] = b;
|
p[3] = b;
|
||||||
}
|
}
|
||||||
/* { dg-final { scan-assembler "strd" } } */
|
/* { dg-final { scan-assembler "strd\\t" } } */
|
||||||
|
9
gcc/testsuite/gcc.target/arm/peep-strd-2.c
Normal file
9
gcc/testsuite/gcc.target/arm/peep-strd-2.c
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/* { dg-do compile } */
|
||||||
|
/* { dg-require-effective-target arm_prefer_ldrd_strd } */
|
||||||
|
/* { dg-options "-O2 -mno-unaligned-access" } */
|
||||||
|
void foo(int a, int b, int* p)
|
||||||
|
{
|
||||||
|
p[2] = a;
|
||||||
|
p[3] = b;
|
||||||
|
}
|
||||||
|
/* { dg-final { scan-assembler-not "strd\\t" } } */
|
Loading…
Reference in New Issue
Block a user