]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Alpha: Permit constant zero source for "insvmisaligndi"
authorMaciej W. Rozycki <macro@orcam.me.uk>
Wed, 25 Dec 2024 22:23:39 +0000 (22:23 +0000)
committerMaciej W. Rozycki <macro@orcam.me.uk>
Wed, 25 Dec 2024 22:23:39 +0000 (22:23 +0000)
Eliminate a redundant bitwise inclusive OR operation on the insertion of
constant zero into a bit-field, improving code produced at `-O2' from an
output sequence such as:

mov $31,$3 # Redundant!
ldq_u $1,7($16)
insqh $3,$16,$3 # Redundant!
ldq_u $2,0($16)
mskqh $1,$16,$1
mskql $2,$16,$2
bis $1,$3,$1 # Redundant!
stq_u $1,7($16)
stq_u $2,0($16)
ret $31,($26),1

to:

ldq_u $2,7($16)
ldq_u $1,0($16)
mskqh $2,$16,$2
stq_u $2,7($16)
mskql $1,$16,$1
stq_u $1,0($16)
ret $31,($26),1

for a quadword unaligned store operation.  As shown in the example this
only triggers for the high-part store (and therefore only for 2-byte,
4-byte, and 8-byte stores), because `insXl' insns are fully expressed in
terms of RTL and therefore the insertion of zero is eliminated in later
RTL passes, however corresponding `insXh' insns are unspecs only, making
them impossible to see through.

We can get this optimal right from expand though, given that our handler
for "insvmisaligndi", i.e. `alpha_expand_unaligned_store', has explicit
provisions for `const0_rtx' source.

gcc/
* config/alpha/alpha.md (insvmisaligndi): Use "reg_or_0_operand"
rather than "register_operand" for operand 3.

gcc/testsuite/
* gcc.target/alpha/stlx0.c: New file.
* gcc.target/alpha/stqx0.c: New file.
* gcc.target/alpha/stwx0.c: New file.
* gcc.target/alpha/stwx0-bwx.c: New file.

gcc/config/alpha/alpha.md
gcc/testsuite/gcc.target/alpha/stlx0.c [new file with mode: 0644]
gcc/testsuite/gcc.target/alpha/stqx0.c [new file with mode: 0644]
gcc/testsuite/gcc.target/alpha/stwx0-bwx.c [new file with mode: 0644]
gcc/testsuite/gcc.target/alpha/stwx0.c [new file with mode: 0644]

index 22ea4db057c397fee31cda90076182f823e120b3..2faa942525732ad16efe457c5af4bc205f703d9f 100644 (file)
   [(set (zero_extract:DI (match_operand:BLK 0 "memory_operand")
                         (match_operand:DI 1 "const_int_operand")
                         (match_operand:DI 2 "const_int_operand"))
-       (match_operand:DI 3 "register_operand"))]
+       (match_operand:DI 3 "reg_or_0_operand"))]
   ""
 {
   /* We can do 16, 32 and 64 bit fields, if aligned on byte boundaries.  */
diff --git a/gcc/testsuite/gcc.target/alpha/stlx0.c b/gcc/testsuite/gcc.target/alpha/stlx0.c
new file mode 100644 (file)
index 0000000..876eceb
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } } */
+
+typedef struct { int v __attribute__ ((packed)); } intx;
+
+void
+stlx0 (intx *p)
+{
+  p->v = 0;
+}
+
+/* Expect assembly such as:
+
+       ldq_u $2,3($16)
+       ldq_u $1,0($16)
+       msklh $2,$16,$2
+       stq_u $2,3($16)
+       mskll $1,$16,$1
+       stq_u $1,0($16)
+
+   without any INSLH, INSLL, or BIS instructions.  */
+
+/* { dg-final { scan-assembler-times "\\sldq_u\\s" 2 } } */
+/* { dg-final { scan-assembler-times "\\smsklh\\s" 1 } } */
+/* { dg-final { scan-assembler-times "\\smskll\\s" 1 } } */
+/* { dg-final { scan-assembler-times "\\sstq_u\\s" 2 } } */
+/* { dg-final { scan-assembler-not "\\s(?:bis|inslh|insll)\\s" } } */
diff --git a/gcc/testsuite/gcc.target/alpha/stqx0.c b/gcc/testsuite/gcc.target/alpha/stqx0.c
new file mode 100644 (file)
index 0000000..042cdf0
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } } */
+
+typedef struct { long v __attribute__ ((packed)); } longx;
+
+void
+stqx0 (longx *p)
+{
+  p->v = 0;
+}
+
+/* Expect assembly such as:
+
+       ldq_u $2,7($16)
+       ldq_u $1,0($16)
+       mskqh $2,$16,$2
+       stq_u $2,7($16)
+       mskql $1,$16,$1
+       stq_u $1,0($16)
+
+   without any INSQH, INSQL, or BIS instructions.  */
+
+/* { dg-final { scan-assembler-times "\\sldq_u\\s" 2 } } */
+/* { dg-final { scan-assembler-times "\\smskqh\\s" 1 } } */
+/* { dg-final { scan-assembler-times "\\smskql\\s" 1 } } */
+/* { dg-final { scan-assembler-times "\\sstq_u\\s" 2 } } */
+/* { dg-final { scan-assembler-not "\\s(?:bis|insqh|insql)\\s" } } */
diff --git a/gcc/testsuite/gcc.target/alpha/stwx0-bwx.c b/gcc/testsuite/gcc.target/alpha/stwx0-bwx.c
new file mode 100644 (file)
index 0000000..bba31df
--- /dev/null
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-mbwx" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } } */
+
+typedef struct { short v __attribute__ ((packed)); } shortx;
+
+void
+stwx0 (shortx *p)
+{
+  p->v = 0;
+}
+
+/* Expect assembly such as:
+
+       stb $31,0($16)
+       stb $31,1($16)
+ */
+
+/* { dg-final { scan-assembler-times "\\sstb\\s\\\$31," 2 } } */
diff --git a/gcc/testsuite/gcc.target/alpha/stwx0.c b/gcc/testsuite/gcc.target/alpha/stwx0.c
new file mode 100644 (file)
index 0000000..d60d33f
--- /dev/null
@@ -0,0 +1,28 @@
+/* { dg-do compile } */
+/* { dg-options "-mno-bwx" } */
+/* { dg-skip-if "" { *-*-* } { "-O0" } } */
+
+typedef struct { short v __attribute__ ((packed)); } shortx;
+
+void
+stwx0 (shortx *p)
+{
+  p->v = 0;
+}
+
+/* Expect assembly such as:
+
+       ldq_u $2,1($16)
+       ldq_u $1,0($16)
+       mskwh $2,$16,$2
+       stq_u $2,1($16)
+       mskwl $1,$16,$1
+       stq_u $1,0($16)
+
+   without any INSWH, INSWL, or BIS instructions.  */
+
+/* { dg-final { scan-assembler-times "\\sldq_u\\s" 2 } } */
+/* { dg-final { scan-assembler-times "\\smskwh\\s" 1 } } */
+/* { dg-final { scan-assembler-times "\\smskwl\\s" 1 } } */
+/* { dg-final { scan-assembler-times "\\sstq_u\\s" 2 } } */
+/* { dg-final { scan-assembler-not "\\s(?:bis|inswh|inswl)\\s" } } */