diff mbox

[01/10] rs6000: Clobber XER[CA] in all user asm statements

Message ID 7a4b7bd73211032ecf856de06a20e14a323e08ba.1418024189.git.segher@kernel.crashing.org
State New
Headers show

Commit Message

Segher Boessenkool Dec. 8, 2014, 2:18 p.m. UTC
A lot of old user code clobbers the carry bit without telling the compiler
about it.  This used to just work, because the compiler never used the bit
outside of a single RTL instruction.  But that will change.  Let's clobber
the carry bit in every asm; this isn't very expensive.


2014-12-08  Segher Boessenkool  <segher@kernel.crashing.org>

gcc/
	PR target/64180
	* config/rs6000/rs6000.c (TARGET_MD_ASM_CLOBBERS): Define.
	(rs6000_md_asm_clobbers): New function.

---
 gcc/config/rs6000/rs6000.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

Comments

David Edelsohn Dec. 8, 2014, 2:25 p.m. UTC | #1
On Mon, Dec 8, 2014 at 9:18 AM, Segher Boessenkool
<segher@kernel.crashing.org> wrote:
> A lot of old user code clobbers the carry bit without telling the compiler
> about it.  This used to just work, because the compiler never used the bit
> outside of a single RTL instruction.  But that will change.  Let's clobber
> the carry bit in every asm; this isn't very expensive.
>
>
> 2014-12-08  Segher Boessenkool  <segher@kernel.crashing.org>
>
> gcc/
>         PR target/64180
>         * config/rs6000/rs6000.c (TARGET_MD_ASM_CLOBBERS): Define.
>         (rs6000_md_asm_clobbers): New function.

Okay.  I don't know of another option that preserves backward
compatibility.  If RTH looks at this series of patches, he may have a
better suggestion.

Thanks, David
Richard Henderson Dec. 9, 2014, 9:48 p.m. UTC | #2
On 12/08/2014 06:25 AM, David Edelsohn wrote:
> Okay.  I don't know of another option that preserves backward
> compatibility.  If RTH looks at this series of patches, he may have a
> better suggestion.

No, this looks like what I'd do.

Indeed, I added this hook back when the i386 port gained direct
support for the flags register, so it's exactly what I did.  ;-)


r~
Hans-Peter Nilsson Jan. 19, 2015, 6:53 a.m. UTC | #3
On Mon, 8 Dec 2014, Segher Boessenkool wrote:

> A lot of old user code clobbers the carry bit without telling the compiler
> about it.  This used to just work, because the compiler never used the bit
> outside of a single RTL instruction.  But that will change.  Let's clobber
> the carry bit in every asm; this isn't very expensive.

There's also the option of clobbering it only if it's not
explicitly mentioned in the asm, say with a singleton
regclass, see cris_md_asm_clobbers.

brgds, H-P
Segher Boessenkool Jan. 19, 2015, 2:59 p.m. UTC | #4
On Mon, Jan 19, 2015 at 01:53:06AM -0500, Hans-Peter Nilsson wrote:
> On Mon, 8 Dec 2014, Segher Boessenkool wrote:
> 
> > A lot of old user code clobbers the carry bit without telling the compiler
> > about it.  This used to just work, because the compiler never used the bit
> > outside of a single RTL instruction.  But that will change.  Let's clobber
> > the carry bit in every asm; this isn't very expensive.
> 
> There's also the option of clobbering it only if it's not
> explicitly mentioned in the asm, say with a singleton
> regclass, see cris_md_asm_clobbers.

It's a fixed register.  The register class we have for it complains
about inconsistent operand constraints whenever you try to use it
(since at least 4.7, and it would never have worked: the compiler
used to clobber the carry reg implicitly all over the place, so you
could never use the register class safely).

I'll remove the register class next stage1.  Thanks for bringing
it to attention.

Cheers,


Segher
diff mbox

Patch

diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index cdb9de9..e58fc81 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -1556,6 +1556,9 @@  static const struct attribute_spec rs6000_attribute_table[] =
 #undef TARGET_ASM_LOOP_ALIGN_MAX_SKIP
 #define TARGET_ASM_LOOP_ALIGN_MAX_SKIP rs6000_loop_align_max_skip
 
+#undef TARGET_MD_ASM_CLOBBERS
+#define TARGET_MD_ASM_CLOBBERS rs6000_md_asm_clobbers
+
 #undef TARGET_OPTION_OVERRIDE
 #define TARGET_OPTION_OVERRIDE rs6000_option_override
 
@@ -3146,6 +3149,19 @@  rs6000_builtin_mask_calculate (void)
 	  | ((TARGET_LONG_DOUBLE_128)	    ? RS6000_BTM_LDBL128 : 0));
 }
 
+/* Implement TARGET_MD_ASM_CLOBBERS.  All asm statements are considered
+   to clobber the XER[CA] bit because clobbering that bit without telling
+   the compiler worked just fine with versions of GCC before GCC 5, and
+   breaking a lot of older code in ways that are hard to track down is
+   not such a great idea.  */
+
+static tree
+rs6000_md_asm_clobbers (tree, tree, tree clobbers)
+{
+  tree s = build_string (strlen (reg_names[CA_REGNO]), reg_names[CA_REGNO]);
+  return tree_cons (NULL_TREE, s, clobbers);
+}
+
 /* Override command line options.  Mostly we process the processor type and
    sometimes adjust other TARGET_ options.  */