In this patch earlier to improve switch behavior: https://gcc.gnu.org/ml/gcc-patches/2018-07/msg01957.html
I noticed that the compiler wasn't generating the LWAX instruction. I tracked this down to the "extendsi<mode>2" insn using the "Y" constraint when it can optimize a load + sign extend into a single load with sign extend. The "Y" constraint is for DS-form offsettable addresses, and does not allow indexed addresses (i.e. X-form loads). This patch adds the "Z" constraint as well, which allows indexed addresses. I have down trunk builds with/without this patch and there were no regressions. Can I apply this patch to the trunk? Can I backport this patch to GCC 7 and GCC 8 as well with a suitable delay to catch any problems? [gcc] 2018-08-20 Michael Meissner <meiss...@linux.ibm.com> PR target/87033 * config/rs6000/rs6000.md (extendsi<mode>2): Change constraints from 'Y' to 'YZ' to enable the LWAX instruction to be generated for indexed loads. [gcc/testsuite] 2018-08-20 Michael Meissner <meiss...@linux.ibm.com> PR target/87033 * gcc.target/powerpc/pr87033.c: New test. -- Michael Meissner, IBM IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA email: meiss...@linux.ibm.com, phone: +1 (978) 899-4797
Index: gcc/config/rs6000/rs6000.md =================================================================== --- gcc/config/rs6000/rs6000.md (revision 263672) +++ gcc/config/rs6000/rs6000.md (working copy) @@ -988,7 +988,7 @@ (define_insn "extendsi<mode>2" "=r, r, wl, wu, wj, wK, wH, wr") (sign_extend:EXTSI (match_operand:SI 1 "lwa_operand" - "Y, r, Z, Z, r, wK, wH, ?wIwH")))] + "YZ, r, Z, Z, r, wK, wH, ?wIwH")))] "" "@ lwa%U1%X1 %0,%1 Index: gcc/testsuite/gcc.target/powerpc/pr87033.c =================================================================== --- gcc/testsuite/gcc.target/powerpc/pr87033.c (nonexistent) +++ gcc/testsuite/gcc.target/powerpc/pr87033.c (working copy) @@ -0,0 +1,11 @@ +/* { dg-do compile { target { powerpc*-*-* && lp64 } } } */ +/* { dg-options "-O2" } */ + +/* Insure that a LWAX is generated instead of ADD + LWA. */ +long func (int *p, unsigned long n) +{ + return p[n]; +} + +/* { dg-final { scan-assembler {\mlwax\M} } } */ +/* { dg-final { scan-assembler-not {\mlwa\M} } } */