diff mbox series

combine: Don't fold away side-effects in simplify_and_const_int_1 [PR99830]

Message ID 20210410060229.GH1179226@tucnak
State New
Headers show
Series combine: Don't fold away side-effects in simplify_and_const_int_1 [PR99830] | expand

Commit Message

Jakub Jelinek April 10, 2021, 6:02 a.m. UTC
Hi!

Here is an alternate patch for the PR99830 bug.
As discussed on IRC and in the PR, the reason why a (clobber:TI (const_int 0))
has been propagated into the debug insns is that it got optimized away
during simplification from the i3 instruction pattern.

And that happened because
simplify_and_const_int_1 (SImode, varop, 255)
with varop of
(ashift:SI (subreg:SI (and:TI (clobber:TI (const_int 0 [0]))
			      (const_int 255 [0xff])) 0)
           (const_int 16 [0x10]))
was called and through nonzero_bits determined that (whatever << 16) & 255
is const0_rtx.
It is, but if there are side-effects in varop and such clobbers are
considered as such, we shouldn't optimize those away.

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

2021-04-10  Jakub Jelinek  <jakub@redhat.com>

	PR debug/99830
	* combine.c (simplify_and_const_int_1): Don't optimize varop
	away if it has side-effects.

	* gcc.dg/pr99830.c: New test.



	Jakub

Comments

Segher Boessenkool April 12, 2021, 10:53 p.m. UTC | #1
Hi!

On Sat, Apr 10, 2021 at 08:02:29AM +0200, Jakub Jelinek wrote:
> Here is an alternate patch for the PR99830 bug.
> As discussed on IRC and in the PR, the reason why a (clobber:TI (const_int 0))
> has been propagated into the debug insns is that it got optimized away
> during simplification from the i3 instruction pattern.
> 
> And that happened because
> simplify_and_const_int_1 (SImode, varop, 255)
> with varop of
> (ashift:SI (subreg:SI (and:TI (clobber:TI (const_int 0 [0]))
> 			      (const_int 255 [0xff])) 0)
>            (const_int 16 [0x10]))
> was called and through nonzero_bits determined that (whatever << 16) & 255
> is const0_rtx.
> It is, but if there are side-effects in varop and such clobbers are
> considered as such, we shouldn't optimize those away.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Okay for trunk.  Thank you!

We'll need to audit all other code doing similar things as well, or add
some assert at some strategic spot.  Something for GCC 12 :-)


Segher
diff mbox series

Patch

--- gcc/combine.c.jj	2021-04-08 17:01:37.315168182 +0200
+++ gcc/combine.c	2021-04-09 22:33:56.961264092 +0200
@@ -10153,7 +10153,7 @@  simplify_and_const_int_1 (scalar_int_mod
   constop &= nonzero;
 
   /* If we don't have any bits left, return zero.  */
-  if (constop == 0)
+  if (constop == 0 && !side_effects_p (varop))
     return const0_rtx;
 
   /* If VAROP is a NEG of something known to be zero or 1 and CONSTOP is
--- gcc/testsuite/gcc.dg/pr99830.c.jj	2021-04-08 16:39:44.243774333 +0200
+++ gcc/testsuite/gcc.dg/pr99830.c	2021-04-08 16:28:40.463175738 +0200
@@ -0,0 +1,10 @@ 
+/* PR debug/99830 */
+/* { dg-do compile { target int128 } } */
+/* { dg-options "-O2 -fno-expensive-optimizations -fno-split-wide-types -g" } */
+
+int foo (long a, __int128 b, short c, int d, unsigned e, __int128 f)
+{
+  __builtin_memmove (2 + (char *) &f, foo, 1);
+  c >>= (char) f;
+  return c;
+}