* [PATCH][ARM] Use std::swap instead of manually swapping
@ 2014-11-13 9:42 Kyrill Tkachov
2014-11-18 10:12 ` Ramana Radhakrishnan
0 siblings, 1 reply; 2+ messages in thread
From: Kyrill Tkachov @ 2014-11-13 9:42 UTC (permalink / raw)
To: GCC Patches, Ramana Radhakrishnan, Richard Earnshaw
[-- Attachment #1: Type: text/plain, Size: 804 bytes --]
Hi all,
Following the trend in i386 and alpha, this patch uses std::swap to
perform swapping of values in the arm backend instead of declaring
temporaries.
Tested and bootstrapped on arm-none-linux-gnueabihf.
Ok for trunk?
Thanks,
Kyrill
2014-11-13 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
* config/arm/arm.md (unaligned_loaddi): Use std::swap instead of
manual swapping implementation.
(movcond_addsi): Likewise.
* config/arm/arm.c (arm_canonicalize_comparison): Likewise.
(arm_select_dominance_cc_mode): Likewise.
(arm_reload_out_hi): Likewise.
(gen_operands_ldrd_strd): Likewise.
(output_move_double): Likewise.
(arm_print_operand_address): Likewise.
(thumb_output_move_mem_multiple): Likewise.
(SWAP_RTX): Delete.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: arm-swap.patch --]
[-- Type: text/x-patch; name=arm-swap.patch, Size: 6730 bytes --]
commit fc09724cd92a9095262913becfc70433f1b406df
Author: Kyrylo Tkachov <kyrylo.tkachov@arm.com>
Date: Wed Nov 12 15:40:49 2014 +0000
[ARM] Use std::swap
diff --git a/gcc/config/arm/arm.c b/gcc/config/arm/arm.c
index 8d163e3..34b7ffe 100644
--- a/gcc/config/arm/arm.c
+++ b/gcc/config/arm/arm.c
@@ -4700,7 +4700,6 @@ arm_canonicalize_comparison (int *code, rtx *op0, rtx *op1,
for GTU/LEU in Thumb mode. */
if (mode == DImode)
{
- rtx tem;
if (*code == GT || *code == LE
|| (!TARGET_ARM && (*code == GTU || *code == LEU)))
@@ -4740,9 +4739,7 @@ arm_canonicalize_comparison (int *code, rtx *op0, rtx *op1,
/* If that did not work, reverse the condition. */
if (!op0_preserve_value)
{
- tem = *op0;
- *op0 = *op1;
- *op1 = tem;
+ std::swap (*op0, *op1);
*code = (int)swap_condition ((enum rtx_code)*code);
}
}
@@ -15016,11 +15013,7 @@ arm_select_dominance_cc_mode (rtx x, rtx y, HOST_WIDE_INT cond_or)
return CCmode;
if (swapped)
- {
- enum rtx_code temp = cond1;
- cond1 = cond2;
- cond2 = temp;
- }
+ std::swap (cond1, cond2);
switch (cond1)
{
@@ -15529,11 +15522,7 @@ arm_reload_out_hi (rtx *operands)
/* Updating base_plus might destroy outval, see if we can
swap the scratch and base_plus. */
if (!reg_overlap_mentioned_p (scratch, outval))
- {
- rtx tmp = scratch;
- scratch = base_plus;
- base_plus = tmp;
- }
+ std::swap (scratch, base_plus);
else
{
rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2]));
@@ -15588,11 +15577,7 @@ arm_reload_out_hi (rtx *operands)
/* Updating base_plus might destroy outval, see if we
can swap the scratch and base_plus. */
if (!reg_overlap_mentioned_p (scratch, outval))
- {
- rtx tmp = scratch;
- scratch = base_plus;
- base_plus = tmp;
- }
+ std::swap (scratch, base_plus);
else
{
rtx scratch_hi = gen_rtx_REG (HImode, REGNO (operands[2]));
@@ -15825,8 +15810,6 @@ mem_ok_for_ldrd_strd (rtx mem, rtx *base, rtx *offset)
return false;
}
-#define SWAP_RTX(x,y) do { rtx tmp = x; x = y; y = tmp; } while (0)
-
/* Called from a peephole2 to replace two word-size accesses with a
single LDRD/STRD instruction. Returns true iff we can generate a
new instruction sequence. That is, both accesses use the same base
@@ -15966,10 +15949,10 @@ gen_operands_ldrd_strd (rtx *operands, bool load,
offset = offsets[1];
/* Swap the instructions such that lower memory is accessed first. */
- SWAP_RTX (operands[0], operands[1]);
- SWAP_RTX (operands[2], operands[3]);
+ std::swap (operands[0], operands[1]);
+ std::swap (operands[2], operands[3]);
if (const_store)
- SWAP_RTX (operands[4], operands[5]);
+ std::swap (operands[4], operands[5]);
}
else
{
@@ -15994,7 +15977,7 @@ gen_operands_ldrd_strd (rtx *operands, bool load,
if (load && commute)
{
/* Try reordering registers. */
- SWAP_RTX (operands[0], operands[1]);
+ std::swap (operands[0], operands[1]);
if (operands_ok_ldrd_strd (operands[0], operands[1], base, offset,
false, load))
return true;
@@ -16023,7 +16006,7 @@ gen_operands_ldrd_strd (rtx *operands, bool load,
if (operands_ok_ldrd_strd (operands[1], operands[0], base, offset,
false, false))
{
- SWAP_RTX (operands[0], operands[1]);
+ std::swap (operands[0], operands[1]);
return true;
}
@@ -16054,7 +16037,6 @@ gen_operands_ldrd_strd (rtx *operands, bool load,
return false;
}
-#undef SWAP_RTX
@@ -18200,12 +18182,9 @@ output_move_double (rtx *operands, bool emit, int *count)
if (reg_overlap_mentioned_p (operands[0],
otherops[2]))
{
- rtx tmp;
/* Swap base and index registers over to
avoid a conflict. */
- tmp = otherops[1];
- otherops[1] = otherops[2];
- otherops[2] = tmp;
+ std::swap (otherops[1], otherops[2]);
}
/* If both registers conflict, it will usually
have been fixed by a splitter. */
@@ -22265,9 +22244,7 @@ arm_print_operand_address (FILE *stream, rtx x)
/* Ensure that BASE is a register. */
/* (one of them must be). */
/* Also ensure the SP is not used as in index register. */
- rtx temp = base;
- base = index;
- index = temp;
+ std::swap (base, index);
}
switch (GET_CODE (index))
{
@@ -28247,23 +28224,11 @@ thumb_output_move_mem_multiple (int n, rtx *operands)
case 3:
if (REGNO (operands[4]) > REGNO (operands[5]))
- {
- tmp = operands[4];
- operands[4] = operands[5];
- operands[5] = tmp;
- }
+ std::swap (operands[4], operands[5]);
if (REGNO (operands[5]) > REGNO (operands[6]))
- {
- tmp = operands[5];
- operands[5] = operands[6];
- operands[6] = tmp;
- }
+ std::swap (operands[5], operands[6]);
if (REGNO (operands[4]) > REGNO (operands[5]))
- {
- tmp = operands[4];
- operands[4] = operands[5];
- operands[5] = tmp;
- }
+ std::swap (operands[4], operands[5]);
output_asm_insn ("ldmia\t%1!, {%4, %5, %6}", operands);
output_asm_insn ("stmia\t%0!, {%4, %5, %6}", operands);
diff --git a/gcc/config/arm/arm.md b/gcc/config/arm/arm.md
index a6f5527..241edc4 100644
--- a/gcc/config/arm/arm.md
+++ b/gcc/config/arm/arm.md
@@ -4224,12 +4224,8 @@ (define_insn_and_split "unaligned_loaddi"
swap the order in which the loads are emitted. */
if (reg_overlap_mentioned_p (operands[0], operands[1]))
{
- rtx tmp = operands[1];
- operands[1] = operands[3];
- operands[3] = tmp;
- tmp = operands[0];
- operands[0] = operands[2];
- operands[2] = tmp;
+ std::swap (operands[1], operands[3]);
+ std::swap (operands[0], operands[2]);
}
}
[(set_attr "arch" "t2,any")
@@ -9333,12 +9329,8 @@ (define_insn_and_split "movcond_addsi"
gcc_assert (!(mode == CCFPmode || mode == CCFPEmode));
if (REGNO (operands[2]) != REGNO (operands[0]))
rc = reverse_condition (rc);
- else
- {
- rtx tmp = operands[1];
- operands[1] = operands[2];
- operands[2] = tmp;
- }
+ else
+ std::swap (operands[1], operands[2]);
operands[6] = gen_rtx_fmt_ee (rc, VOIDmode, operands[6], const0_rtx);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH][ARM] Use std::swap instead of manually swapping
2014-11-13 9:42 [PATCH][ARM] Use std::swap instead of manually swapping Kyrill Tkachov
@ 2014-11-18 10:12 ` Ramana Radhakrishnan
0 siblings, 0 replies; 2+ messages in thread
From: Ramana Radhakrishnan @ 2014-11-18 10:12 UTC (permalink / raw)
To: Kyrill Tkachov; +Cc: GCC Patches, Ramana Radhakrishnan, Richard Earnshaw
On Thu, Nov 13, 2014 at 9:42 AM, Kyrill Tkachov <kyrylo.tkachov@arm.com> wrote:
> Hi all,
>
> Following the trend in i386 and alpha, this patch uses std::swap to perform
> swapping of values in the arm backend instead of declaring temporaries.
> Tested and bootstrapped on arm-none-linux-gnueabihf.
>
> Ok for trunk?
OK - Thanks for the cleanup.
Thanks,
Ramana
>
> Thanks,
> Kyrill
>
> 2014-11-13 Kyrylo Tkachov <kyrylo.tkachov@arm.com>
>
> * config/arm/arm.md (unaligned_loaddi): Use std::swap instead of
> manual swapping implementation.
> (movcond_addsi): Likewise.
> * config/arm/arm.c (arm_canonicalize_comparison): Likewise.
> (arm_select_dominance_cc_mode): Likewise.
> (arm_reload_out_hi): Likewise.
> (gen_operands_ldrd_strd): Likewise.
> (output_move_double): Likewise.
> (arm_print_operand_address): Likewise.
> (thumb_output_move_mem_multiple): Likewise.
> (SWAP_RTX): Delete.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-11-18 10:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-13 9:42 [PATCH][ARM] Use std::swap instead of manually swapping Kyrill Tkachov
2014-11-18 10:12 ` Ramana Radhakrishnan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).