]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ira: Don't create copies for earlyclobbered pairs
authorRichard Sandiford <richard.sandiford@arm.com>
Tue, 9 May 2023 06:40:41 +0000 (07:40 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 9 May 2023 06:40:41 +0000 (07:40 +0100)
This patch follows on from g:9f635bd13fe9e85872e441b6f3618947f989909a
("the previous patch").  To start by quoting that:

If an insn requires two operands to be tied, and the input operand dies
in the insn, IRA acts as though there were a copy from the input to the
output with the same execution frequency as the insn.  Allocating the
same register to the input and the output then saves the cost of a move.

If there is no such tie, but an input operand nevertheless dies
in the insn, IRA creates a similar move, but with an eighth of the
frequency.  This helps to ensure that chains of instructions reuse
registers in a natural way, rather than using arbitrarily different
registers for no reason.

This heuristic seems to work well in the vast majority of cases.
However, the problem fixed in the previous patch was that we
could create a copy for an operand pair even if, for all relevant
alternatives, the output and input register classes did not have
any registers in common.  It is then impossible for the output
operand to reuse the dying input register.

This left unfixed a further case where copies don't make sense:
there is no point trying to reuse the dying input register if,
for all relevant alternatives, the output is earlyclobbered and
the input doesn't match the output.  (Matched earlyclobbers are fine.)

Handling that case fixes several existing XFAILs and helps with
a follow-on aarch64 patch.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  A SPEC2017 run
on aarch64 showed no differences outside the noise.  Also, I tried
compiling gcc.c-torture, gcc.dg, and g++.dg for at least one target
per cpu directory, using the options -Os -fno-schedule-insns{,2}.
The results below summarise the tests that showed a difference in LOC:

Target               Tests   Good    Bad   Delta    Best   Worst  Median
======               =====   ====    ===   =====    ====   =====  ======
amdgcn-amdhsa           14      7      7       3     -18      10      -1
arm-linux-gnueabihf     16     15      1     -22      -4       2      -1
csky-elf                 6      6      0     -21      -6      -2      -4
hppa64-hp-hpux11.23      5      5      0      -7      -2      -1      -1
ia64-linux-gnu          16     16      0     -70     -15      -1      -3
m32r-elf                53      1     52      64      -2       8       1
mcore-elf                2      2      0      -8      -6      -2      -6
microblaze-elf         285    283      2    -909     -68       4      -1
mmix                     7      7      0   -2101   -2091      -1      -1
msp430-elf               1      1      0      -4      -4      -4      -4
pru-elf                  8      6      2     -12      -6       2      -2
rx-elf                  22     18      4     -40      -5       6      -2
sparc-linux-gnu         15     14      1     -40      -8       1      -2
sparc-wrs-vxworks       15     14      1     -40      -8       1      -2
visium-elf               2      1      1       0      -2       2      -2
xstormy16-elf            1      1      0      -2      -2      -2      -2

with other targets showing no sensitivity to the patch.  The only
target that seems to be negatively affected is m32r-elf; otherwise
the patch seems like an extremely minor but still clear improvement.

gcc/
* ira-conflicts.cc (can_use_same_reg_p): Skip over non-matching
earlyclobbers.

gcc/testsuite/
* gcc.target/aarch64/sve/acle/asm/asr_wide_s16.c: Remove XFAILs.
* gcc.target/aarch64/sve/acle/asm/asr_wide_s32.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/asr_wide_s8.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/bic_s32.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/bic_s64.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/bic_u32.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/bic_u64.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/lsl_wide_s16.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/lsl_wide_s32.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/lsl_wide_s8.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/lsl_wide_u16.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/lsl_wide_u32.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/lsl_wide_u8.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/lsr_wide_u16.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/lsr_wide_u32.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/lsr_wide_u8.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/scale_f32.c: Likewise.
* gcc.target/aarch64/sve/acle/asm/scale_f64.c: Likewise.

19 files changed:
gcc/ira-conflicts.cc
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/asr_wide_s16.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/asr_wide_s32.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/asr_wide_s8.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/bic_s32.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/bic_s64.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/bic_u32.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/bic_u64.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/lsl_wide_s16.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/lsl_wide_s32.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/lsl_wide_s8.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/lsl_wide_u16.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/lsl_wide_u32.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/lsl_wide_u8.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/lsr_wide_u16.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/lsr_wide_u32.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/lsr_wide_u8.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/scale_f32.c
gcc/testsuite/gcc.target/aarch64/sve/acle/asm/scale_f64.c

index 5aa080af42136b8834ead996a1585f80881f96fe..a4d93c8d734255ae7fd133eecbf474f7118eba06 100644 (file)
@@ -398,6 +398,9 @@ can_use_same_reg_p (rtx_insn *insn, int output, int input)
       if (op_alt[input].matches == output)
        return true;
 
+      if (op_alt[output].earlyclobber)
+       continue;
+
       if (ira_reg_class_intersect[op_alt[input].cl][op_alt[output].cl]
          != NO_REGS)
        return true;
index b74ae33e100f1fe198dae1184ef95e3da3e37a08..e40865fcbc4f6c4b3774d90f999022f9ab0194a8 100644 (file)
@@ -153,7 +153,7 @@ TEST_UNIFORM_ZX (asr_wide_x0_s16_z_tied1, svint16_t, uint64_t,
                 z0 = svasr_wide_z (p0, z0, x0))
 
 /*
-** asr_wide_x0_s16_z_untied: { xfail *-*-* }
+** asr_wide_x0_s16_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.h, p0/z, z1\.h
 **     asr     z0\.h, p0/m, z0\.h, \1
index 8698aef26c64d6063154a50c412e5ef742e6e773..06e4ca2a030e0058203dcebf2b59395352603009 100644 (file)
@@ -153,7 +153,7 @@ TEST_UNIFORM_ZX (asr_wide_x0_s32_z_tied1, svint32_t, uint64_t,
                 z0 = svasr_wide_z (p0, z0, x0))
 
 /*
-** asr_wide_x0_s32_z_untied: { xfail *-*-* }
+** asr_wide_x0_s32_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.s, p0/z, z1\.s
 **     asr     z0\.s, p0/m, z0\.s, \1
index 77b1669392dabf8bd8ae2fc324f3458e533720d2..1f840ca8e57eb02a40d703ad4e5d9c9783fd66fc 100644 (file)
@@ -153,7 +153,7 @@ TEST_UNIFORM_ZX (asr_wide_x0_s8_z_tied1, svint8_t, uint64_t,
                 z0 = svasr_wide_z (p0, z0, x0))
 
 /*
-** asr_wide_x0_s8_z_untied: { xfail *-*-* }
+** asr_wide_x0_s8_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.b, p0/z, z1\.b
 **     asr     z0\.b, p0/m, z0\.b, \1
index 9e388e499b84e5209f4a34fea04118799d0e85b3..e02c66947d6c25d99193a45d5329dc87916be428 100644 (file)
@@ -127,7 +127,7 @@ TEST_UNIFORM_ZX (bic_w0_s32_z_tied1, svint32_t, int32_t,
                 z0 = svbic_z (p0, z0, x0))
 
 /*
-** bic_w0_s32_z_untied: { xfail *-*-* }
+** bic_w0_s32_z_untied:
 **     mov     (z[0-9]+\.s), w0
 **     movprfx z0\.s, p0/z, z1\.s
 **     bic     z0\.s, p0/m, z0\.s, \1
index bf95368154726c5f54856472f89d3b1302be092e..57c1e535fea3fa67d485ccdc8822e6da90873c71 100644 (file)
@@ -127,7 +127,7 @@ TEST_UNIFORM_ZX (bic_x0_s64_z_tied1, svint64_t, int64_t,
                 z0 = svbic_z (p0, z0, x0))
 
 /*
-** bic_x0_s64_z_untied: { xfail *-*-* }
+** bic_x0_s64_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.d, p0/z, z1\.d
 **     bic     z0\.d, p0/m, z0\.d, \1
index b308b599b4342454424b869da4104619c14089e9..9f08ab40a8c582d49f9e4c401116d3bcdd2c0371 100644 (file)
@@ -127,7 +127,7 @@ TEST_UNIFORM_ZX (bic_w0_u32_z_tied1, svuint32_t, uint32_t,
                 z0 = svbic_z (p0, z0, x0))
 
 /*
-** bic_w0_u32_z_untied: { xfail *-*-* }
+** bic_w0_u32_z_untied:
 **     mov     (z[0-9]+\.s), w0
 **     movprfx z0\.s, p0/z, z1\.s
 **     bic     z0\.s, p0/m, z0\.s, \1
index e82db1e94fd605347adf01b4a0b286747e0ed01c..de84f3af6ff45be626a643d69409edb22cf2b737 100644 (file)
@@ -127,7 +127,7 @@ TEST_UNIFORM_ZX (bic_x0_u64_z_tied1, svuint64_t, uint64_t,
                 z0 = svbic_z (p0, z0, x0))
 
 /*
-** bic_x0_u64_z_untied: { xfail *-*-* }
+** bic_x0_u64_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.d, p0/z, z1\.d
 **     bic     z0\.d, p0/m, z0\.d, \1
index 8d63d3909848a7e90d1975d9cf2e040dbf9e2a8a..a0207726144b96ea45b708c57c11f1a01cf70805 100644 (file)
@@ -155,7 +155,7 @@ TEST_UNIFORM_ZX (lsl_wide_x0_s16_z_tied1, svint16_t, uint64_t,
                 z0 = svlsl_wide_z (p0, z0, x0))
 
 /*
-** lsl_wide_x0_s16_z_untied: { xfail *-*-* }
+** lsl_wide_x0_s16_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.h, p0/z, z1\.h
 **     lsl     z0\.h, p0/m, z0\.h, \1
index acd813df34f4ee1b42d9840f669085c8cfef07d2..bd67b7006b5c647d3e07d17ed5cce5178c716daa 100644 (file)
@@ -155,7 +155,7 @@ TEST_UNIFORM_ZX (lsl_wide_x0_s32_z_tied1, svint32_t, uint64_t,
                 z0 = svlsl_wide_z (p0, z0, x0))
 
 /*
-** lsl_wide_x0_s32_z_untied: { xfail *-*-* }
+** lsl_wide_x0_s32_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.s, p0/z, z1\.s
 **     lsl     z0\.s, p0/m, z0\.s, \1
index 17e8e8685e3fc3b6dc92c32557196e368127a10e..7eb8627041d9a7d81afe65c02cf2ee6c945fe0a1 100644 (file)
@@ -155,7 +155,7 @@ TEST_UNIFORM_ZX (lsl_wide_x0_s8_z_tied1, svint8_t, uint64_t,
                 z0 = svlsl_wide_z (p0, z0, x0))
 
 /*
-** lsl_wide_x0_s8_z_untied: { xfail *-*-* }
+** lsl_wide_x0_s8_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.b, p0/z, z1\.b
 **     lsl     z0\.b, p0/m, z0\.b, \1
index cff24a85090b976c56d0065defd667a55d0e87bd..482f8d0557ba4e8b02797e2a08b4eef3a01b0051 100644 (file)
@@ -155,7 +155,7 @@ TEST_UNIFORM_ZX (lsl_wide_x0_u16_z_tied1, svuint16_t, uint64_t,
                 z0 = svlsl_wide_z (p0, z0, x0))
 
 /*
-** lsl_wide_x0_u16_z_untied: { xfail *-*-* }
+** lsl_wide_x0_u16_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.h, p0/z, z1\.h
 **     lsl     z0\.h, p0/m, z0\.h, \1
index 7b1afab4918b4ea1f8bb94b3a141c2ed5a60361a..612897d24dfde29f9235eecfd3437f41bcf41c63 100644 (file)
@@ -155,7 +155,7 @@ TEST_UNIFORM_ZX (lsl_wide_x0_u32_z_tied1, svuint32_t, uint64_t,
                 z0 = svlsl_wide_z (p0, z0, x0))
 
 /*
-** lsl_wide_x0_u32_z_untied: { xfail *-*-* }
+** lsl_wide_x0_u32_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.s, p0/z, z1\.s
 **     lsl     z0\.s, p0/m, z0\.s, \1
index df8b1ec86b492497556987d864c1dc49aab1dc53..6ca2f9e7da22db8dd3033cd0be68265a72f70bc2 100644 (file)
@@ -155,7 +155,7 @@ TEST_UNIFORM_ZX (lsl_wide_x0_u8_z_tied1, svuint8_t, uint64_t,
                 z0 = svlsl_wide_z (p0, z0, x0))
 
 /*
-** lsl_wide_x0_u8_z_untied: { xfail *-*-* }
+** lsl_wide_x0_u8_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.b, p0/z, z1\.b
 **     lsl     z0\.b, p0/m, z0\.b, \1
index 863b51a2fc52bf1b2c440313f13fa9890227b42a..9110c5aad44670c3fa4c75f9dfade6483293f851 100644 (file)
@@ -153,7 +153,7 @@ TEST_UNIFORM_ZX (lsr_wide_x0_u16_z_tied1, svuint16_t, uint64_t,
                 z0 = svlsr_wide_z (p0, z0, x0))
 
 /*
-** lsr_wide_x0_u16_z_untied: { xfail *-*-* }
+** lsr_wide_x0_u16_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.h, p0/z, z1\.h
 **     lsr     z0\.h, p0/m, z0\.h, \1
index 73c2cf86e3307d164d5561cfd14ab9cc5ab75ff0..93af4fa49256ed923f8e5b2a99654483836b407b 100644 (file)
@@ -153,7 +153,7 @@ TEST_UNIFORM_ZX (lsr_wide_x0_u32_z_tied1, svuint32_t, uint64_t,
                 z0 = svlsr_wide_z (p0, z0, x0))
 
 /*
-** lsr_wide_x0_u32_z_untied: { xfail *-*-* }
+** lsr_wide_x0_u32_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.s, p0/z, z1\.s
 **     lsr     z0\.s, p0/m, z0\.s, \1
index fe44eabda11d96c1ca12b3a58771586b6afa359a..2f38139d40be9b5e75ae14f53194787bce2abe36 100644 (file)
@@ -153,7 +153,7 @@ TEST_UNIFORM_ZX (lsr_wide_x0_u8_z_tied1, svuint8_t, uint64_t,
                 z0 = svlsr_wide_z (p0, z0, x0))
 
 /*
-** lsr_wide_x0_u8_z_untied: { xfail *-*-* }
+** lsr_wide_x0_u8_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.b, p0/z, z1\.b
 **     lsr     z0\.b, p0/m, z0\.b, \1
index 747f8a6397bc3899ea42d462ef83d5ea96666857..12a1b1d8686be89eebe96e1a3bf53aeba50214b3 100644 (file)
@@ -127,7 +127,7 @@ TEST_UNIFORM_ZX (scale_w0_f32_z_tied1, svfloat32_t, int32_t,
                 z0 = svscale_z (p0, z0, x0))
 
 /*
-** scale_w0_f32_z_untied: { xfail *-*-* }
+** scale_w0_f32_z_untied:
 **     mov     (z[0-9]+\.s), w0
 **     movprfx z0\.s, p0/z, z1\.s
 **     fscale  z0\.s, p0/m, z0\.s, \1
index 004cbfa3eff3f9c6558267ee895147ba4733467b..f6b117185848bd658b33dd9654a91683f328fc86 100644 (file)
@@ -127,7 +127,7 @@ TEST_UNIFORM_ZX (scale_x0_f64_z_tied1, svfloat64_t, int64_t,
                 z0 = svscale_z (p0, z0, x0))
 
 /*
-** scale_x0_f64_z_untied: { xfail *-*-* }
+** scale_x0_f64_z_untied:
 **     mov     (z[0-9]+\.d), x0
 **     movprfx z0\.d, p0/z, z1\.d
 **     fscale  z0\.d, p0/m, z0\.d, \1