public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Michael Meissner <meissner@linux.ibm.com>
To: Michael Meissner <meissner@linux.ibm.com>,
	gcc-patches@gcc.gnu.org,        segher@kernel.crashing.org,
	dje.gcc@gmail.com
Subject: [PATCH, V3, #6 of 10], Fix vec_extract breakage
Date: Mon, 26 Aug 2019 21:52:00 -0000	[thread overview]
Message-ID: <20190826212012.GF11790@ibm-toto.the-meissners.org> (raw)
In-Reply-To: <20190826173320.GA7958@ibm-toto.the-meissners.org>

This patch fixes the bug I mentioned in a previous patch, i.e.

	#include <altivec.h>

	static vector double v;

	// ...

	double foo (int n)
	{
	    double x = vec_extract (v, n);
	    return x;
	}

would generate incorrect code because it only has one temporary register, and
it needs two temporary registers (one to hold the pc-relative address, and the
other to hold the index).  In the previous V3 patch #4 that added pc-relative
support, I put in an abort for this case.  This patch actually fixes it.

Originally, I solved it by just adding a predicate/condition to not allow a
pc-relative address to combine with the extract directly.  But I found the
reload pass was joining the two insns, so I added a new constraint (ep) to say
this memory insn must not involve a pc-relative address.

If you have an unused constraint pair that you would prefer instead of "ep", I
can easily switch to use that.

I built a boostrap compiler on a little endian power8 system, and there were no
regressions in running make check.  Can I check this change into the trunk once
the previous patches are checked in?

2019-08-26  Michael Meissner  <meissner@linux.ibm.com>

	* config/rs6000/constraints.md (ep constraint): New constraint.
	* config/rs6000/predicates.md (non_pcrel_mem_operand): New
	predicate.
	(reg_or_non_pcrel_operand): New predicate.
	* config/rs6000/vsx.md (vsx_extract_<mode>_var, VSX_D iterator):
	Don't allow pc-relative memory addresses.
	(vsx_extract_v4sf_var): Don't allow pc-relative memory addresses.
	(vsx_extract_<mode>_var, VSX_EXTRACT_I iterator): Don't allow
	pc-relative memory addresses.
	(vsx_extract_<mode>_<VS_scalar>mode_var): Don't allow pc-relative
	memory addresses.
	* doc/md.texi (PowerPC Constraints): Document ep constraint.

Index: gcc/config/rs6000/constraints.md
===================================================================
--- gcc/config/rs6000/constraints.md	(revision 274864)
+++ gcc/config/rs6000/constraints.md	(working copy)
@@ -210,6 +210,11 @@ several times, or that might not access
   (and (match_code "mem")
        (match_test "GET_RTX_CLASS (GET_CODE (XEXP (op, 0))) != RTX_AUTOINC")))
 
+(define_memory_constraint "ep"
+  "A memory operand that does not contain a pc-relative reference."
+  (and (match_code "mem")
+       (match_test "non_pcrel_mem_operand (op, mode)")))
+
 (define_memory_constraint "Q"
   "Memory operand that is an offset from a register (it is usually better
 to use @samp{m} or @samp{es} in @code{asm} statements)"
Index: gcc/config/rs6000/predicates.md
===================================================================
--- gcc/config/rs6000/predicates.md	(revision 274874)
+++ gcc/config/rs6000/predicates.md	(working copy)
@@ -1706,6 +1706,33 @@ (define_predicate "non_prefixed_mem_oper
 				 TRAD_INSN_DEFAULT);
 })
 
+;; Return 1 if op is a memory operand that does not contain a pc-relative
+;; address.
+(define_predicate "non_pcrel_mem_operand"
+  (match_code "mem")
+{
+  if (!memory_operand (op, mode))
+    return false;
+
+  return (!pcrel_local_address (XEXP (op, 0), Pmode)
+	  && !pcrel_ext_address (XEXP (op, 0), Pmode));
+})
+
+;; Return 1 if op is a register or a memory operand that does not contain a
+;; pc-relatve address.
+(define_predicate "reg_or_non_pcrel_operand"
+  (match_code "reg,subreg,mem")
+{
+  if (REG_P (op) || SUBREG_P (op))
+    return true;
+
+  if (!memory_operand (op, mode))
+    return false;
+
+  return (!pcrel_local_address (XEXP (op, 0), Pmode)
+	  && !pcrel_ext_address (XEXP (op, 0), Pmode));
+})
+
 ;; Match the first insn (addis) in fusing the combination of addis and loads to
 ;; GPR registers on power8.
 (define_predicate "fusion_gpr_addis"
Index: gcc/config/rs6000/vsx.md
===================================================================
--- gcc/config/rs6000/vsx.md	(revision 274874)
+++ gcc/config/rs6000/vsx.md	(working copy)
@@ -3249,9 +3249,10 @@ (define_insn "vsx_vslo_<mode>"
 ;; Variable V2DI/V2DF extract
 (define_insn_and_split "vsx_extract_<mode>_var"
   [(set (match_operand:<VS_scalar> 0 "gpc_reg_operand" "=v,wa,r")
-	(unspec:<VS_scalar> [(match_operand:VSX_D 1 "input_operand" "v,m,m")
-			     (match_operand:DI 2 "gpc_reg_operand" "r,r,r")]
-			    UNSPEC_VSX_EXTRACT))
+	(unspec:<VS_scalar>
+	 [(match_operand:VSX_D 1 "reg_or_non_pcrel_operand" "v,ep,ep")
+	  (match_operand:DI 2 "gpc_reg_operand" "r,r,r")]
+	 UNSPEC_VSX_EXTRACT))
    (clobber (match_scratch:DI 3 "=r,&b,&b"))
    (clobber (match_scratch:V2DI 4 "=&v,X,X"))]
   "VECTOR_MEM_VSX_P (<MODE>mode) && TARGET_DIRECT_MOVE_64BIT"
@@ -3319,9 +3320,10 @@ (define_insn_and_split "*vsx_extract_v4s
 ;; Variable V4SF extract
 (define_insn_and_split "vsx_extract_v4sf_var"
   [(set (match_operand:SF 0 "gpc_reg_operand" "=wa,wa,?r")
-	(unspec:SF [(match_operand:V4SF 1 "input_operand" "v,m,m")
-		    (match_operand:DI 2 "gpc_reg_operand" "r,r,r")]
-		   UNSPEC_VSX_EXTRACT))
+	(unspec:SF
+	 [(match_operand:V4SF 1 "reg_or_non_pcrel_operand" "v,ep,ep")
+	  (match_operand:DI 2 "gpc_reg_operand" "r,r,r")]
+	 UNSPEC_VSX_EXTRACT))
    (clobber (match_scratch:DI 3 "=r,&b,&b"))
    (clobber (match_scratch:V2DI 4 "=&v,X,X"))]
   "VECTOR_MEM_VSX_P (V4SFmode) && TARGET_DIRECT_MOVE_64BIT"
@@ -3682,7 +3684,7 @@ (define_insn_and_split "*vsx_extract_<mo
 (define_insn_and_split "vsx_extract_<mode>_var"
   [(set (match_operand:<VS_scalar> 0 "gpc_reg_operand" "=r,r,r")
 	(unspec:<VS_scalar>
-	 [(match_operand:VSX_EXTRACT_I 1 "input_operand" "v,v,m")
+	 [(match_operand:VSX_EXTRACT_I 1 "reg_or_non_pcrel_operand" "v,v,ep")
 	  (match_operand:DI 2 "gpc_reg_operand" "r,r,r")]
 	 UNSPEC_VSX_EXTRACT))
    (clobber (match_scratch:DI 3 "=r,r,&b"))
@@ -3702,7 +3704,7 @@ (define_insn_and_split "*vsx_extract_<mo
   [(set (match_operand:<VS_scalar> 0 "gpc_reg_operand" "=r,r,r")
 	(zero_extend:<VS_scalar>
 	 (unspec:<VSX_EXTRACT_I:VS_scalar>
-	  [(match_operand:VSX_EXTRACT_I 1 "input_operand" "v,v,m")
+	  [(match_operand:VSX_EXTRACT_I 1 "reg_or_non_pcrel_operand" "v,v,ep")
 	   (match_operand:DI 2 "gpc_reg_operand" "r,r,r")]
 	  UNSPEC_VSX_EXTRACT)))
    (clobber (match_scratch:DI 3 "=r,r,&b"))
Index: gcc/doc/md.texi
===================================================================
--- gcc/doc/md.texi	(revision 274864)
+++ gcc/doc/md.texi	(working copy)
@@ -3343,6 +3343,9 @@ Constant whose negation is a signed 16-b
 @item eI
 Signed 34-bit integer constant if prefixed instructions are supported.
 
+@item ep
+A memory operand that does not include a pc-relative address.
+
 @item G
 Floating point constant that can be loaded into a register with one
 instruction per word

-- 
Michael Meissner, IBM
IBM, M/S 2506R, 550 King Street, Littleton, MA 01460-6245, USA
email: meissner@linux.ibm.com, phone: +1 (978) 899-4797

  parent reply	other threads:[~2019-08-26 21:23 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-26 19:21 PowerPC future machine, version 3 Michael Meissner
2019-08-26 20:41 ` [PATCH V3, #1 of 10], Add basic pc-relative support Michael Meissner
2019-08-28 18:46   ` Segher Boessenkool
2019-08-28 21:48     ` Michael Meissner
2019-08-30  0:08       ` Segher Boessenkool
2019-09-06  0:18         ` Michael Meissner
2019-09-06 12:50           ` Segher Boessenkool
2019-09-09 20:28             ` Michael Meissner
2019-08-26 21:07 ` [PATCH, V3, #3 of 10], Add prefixed RTL insn attribute Michael Meissner
2019-08-30  1:58   ` Segher Boessenkool
2019-08-26 21:12 ` [PATCH, V3, #2 of 10], Improve rs6000_setup_addr_mask Michael Meissner
2019-08-29  2:59   ` Segher Boessenkool
2019-08-26 21:23 ` [PATCH, V3, #4 of 10], Add general prefixed/pcrel support Michael Meissner
2019-08-30 19:22   ` Segher Boessenkool
2019-08-31  3:08     ` Alan Modra
2019-08-31 14:13       ` Segher Boessenkool
2019-08-26 21:43 ` [PATCH, V3, #5 of 10], Make -mpcrel default on little endian Linux systems Michael Meissner
2019-08-30 19:46   ` Segher Boessenkool
2019-09-03 21:07     ` Michael Meissner
2019-09-03 22:25       ` Segher Boessenkool
2019-08-26 21:52 ` Michael Meissner [this message]
2019-09-03 19:49   ` [PATCH, V3, #6 of 10], Fix vec_extract breakage Segher Boessenkool
2019-09-05 20:48     ` Michael Meissner
2019-09-05 22:38       ` Segher Boessenkool
2019-09-06 10:26         ` Segher Boessenkool
2019-08-26 22:06 ` [PATCH, V3, #7 of 10], Implement PCREL_OPT relocation optimization Michael Meissner
2019-08-28 21:48   ` Michael Meissner
2019-09-03 22:56   ` Segher Boessenkool
2019-09-03 23:20     ` Michael Meissner
2019-09-03 23:33       ` Segher Boessenkool
2019-09-04 17:26         ` Michael Meissner
2019-09-06 12:09           ` Segher Boessenkool
2019-09-09 20:32             ` Michael Meissner
2019-09-09 20:56               ` Segher Boessenkool
2019-09-09 22:39                 ` Michael Meissner
2019-08-27  7:01 ` [PATCH, V3, #8 of 10], Miscellaneous prefixed addressing tests Michael Meissner
2019-09-03 23:17   ` Segher Boessenkool
2019-09-05 21:01     ` Michael Meissner
2019-09-05 22:57       ` Segher Boessenkool
2019-08-27  7:14 ` [PATCH, V3, #10 of #10], Pc-relative tests Michael Meissner
2019-08-27  7:55 ` [PATCH, V3, #9 of 10], Prefixed addressing tests with large offsets Michael Meissner
2019-09-03 23:22   ` Segher Boessenkool

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190826212012.GF11790@ibm-toto.the-meissners.org \
    --to=meissner@linux.ibm.com \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=segher@kernel.crashing.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).