Patchwork Improve simplify_subreg

login
register
mail settings
Submitter Jakub Jelinek
Date May 2, 2013, 5:38 p.m.
Message ID <20130502173816.GY28963@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/241045/
State New
Headers show

Comments

Jakub Jelinek - May 2, 2013, 5:38 p.m.
Hi!

When working on PR57130, I've wondered why we don't simplify it much earlier
and end up with creating such weirdness.

The following patch fixes that, by using nonzero_bits to see if all the low
bits must be zero and in that case just return zero.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2013-05-02  Jakub Jelinek  <jakub@redhat.com>

	* simplify-rtx.c (simplify_truncation): If nonzero_bits
	on op shows all bits zero in mode, return zero.


	Jakub
Richard Sandiford - May 2, 2013, 5:53 p.m.
Jakub Jelinek <jakub@redhat.com> writes:
> Hi!
>
> When working on PR57130, I've wondered why we don't simplify it much earlier
> and end up with creating such weirdness.
>
> The following patch fixes that, by using nonzero_bits to see if all the low
> bits must be zero and in that case just return zero.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2013-05-02  Jakub Jelinek  <jakub@redhat.com>
>
> 	* simplify-rtx.c (simplify_truncation): If nonzero_bits
> 	on op shows all bits zero in mode, return zero.

I'm probably wrong, but just in case: it looks like this might
fall foul of:

/* Try to simplify a MODE truncation of OP, which has OP_MODE.
   Only handle cases where the truncated value is inherently an rvalue.

If op is a register, it might be being used as an lvalue instead of an rvalue.
We don't want to simplify (subreg (reg ..)) to (const_int 0) in that case.

It should be OK to put this under the TRUNCATE case in
simplify_unary_operation_1, but I don't know if that'd be good
enough for your testcase.

Thanks,
Richard

Patch

--- gcc/simplify-rtx.c.jj	2013-04-03 15:46:45.000000000 +0200
+++ gcc/simplify-rtx.c	2013-05-02 11:16:18.202043607 +0200
@@ -774,6 +774,11 @@  simplify_truncation (enum machine_mode m
     return simplify_gen_unary (TRUNCATE, mode, XEXP (op, 0),
 			       GET_MODE (XEXP (op, 0)));
 
+  /* If op is known to have all lower bits zero, the result is zero.  */
+  if (HWI_COMPUTABLE_MODE_P (op_mode)
+      && (nonzero_bits (op, op_mode) & GET_MODE_MASK (mode)) == 0)
+    return CONST0_RTX (mode);
+
   return NULL_RTX;
 }