diff mbox series

Fix PR tree-optimization/86514

Message ID 3018517.UiVXHDucIc@polaris
State New
Headers show
Series Fix PR tree-optimization/86514 | expand

Commit Message

Eric Botcazou July 16, 2018, 7:50 a.m. UTC
Hi,

this is a regression present on the mainline and 8 branch in the form of wrong 
code generated for an Ada program manipulating bit-packed boolean array types.

The problem is in the new range optimization code of the reassoc pass: from

  _64 = _63 | 4;
  _73 = _64 & 191;
  _76 = _64 >> 6;
  _77 = (boolean) _76;
  _78 = (boolean) _64;
  _79 = _77 | _78;

it deduces:

Optimizing range tests _76 +[0, 0] and _64 +[0, 0]
|...]
  _64 = _63 | 4;
  _73 = _64 & 191;
  _76 = _64 >> 6;
  _90 = _76 | _64;
  _19 = _90 != 0;
  _77 = (boolean) _76;
  _78 = (boolean) _64;
  _79 = _19;

which is not equivalent.  The proposed fix is to avoid bypassing a conversion 
to a boolean type from a type with greater precision in init_range_entry.

Tested on x86_64-suse-linux, OK for the mainline?


2018-07-16  Eric Botcazou  <ebotcazou@adacore.com>

	PR tree-optimization/86514
	* tree-ssa-reassoc.c (init_range_entry) <CASE_CONVERT>: Return for a
	conversion to a boolean type from a type with greater precision.


2018-07-16  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt73.adb: New test.

Comments

Richard Biener July 16, 2018, 8:36 a.m. UTC | #1
On Mon, Jul 16, 2018 at 9:52 AM Eric Botcazou <ebotcazou@adacore.com> wrote:
>
> Hi,
>
> this is a regression present on the mainline and 8 branch in the form of wrong
> code generated for an Ada program manipulating bit-packed boolean array types.
>
> The problem is in the new range optimization code of the reassoc pass: from
>
>   _64 = _63 | 4;
>   _73 = _64 & 191;
>   _76 = _64 >> 6;
>   _77 = (boolean) _76;
>   _78 = (boolean) _64;
>   _79 = _77 | _78;
>
> it deduces:
>
> Optimizing range tests _76 +[0, 0] and _64 +[0, 0]
> |...]
>   _64 = _63 | 4;
>   _73 = _64 & 191;
>   _76 = _64 >> 6;
>   _90 = _76 | _64;
>   _19 = _90 != 0;
>   _77 = (boolean) _76;
>   _78 = (boolean) _64;
>   _79 = _19;
>
> which is not equivalent.  The proposed fix is to avoid bypassing a conversion
> to a boolean type from a type with greater precision in init_range_entry.
>
> Tested on x86_64-suse-linux, OK for the mainline?

OK for trunk and branch.

Thanks,
Richard.

>
> 2018-07-16  Eric Botcazou  <ebotcazou@adacore.com>
>
>         PR tree-optimization/86514
>         * tree-ssa-reassoc.c (init_range_entry) <CASE_CONVERT>: Return for a
>         conversion to a boolean type from a type with greater precision.
>
>
> 2018-07-16  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * gnat.dg/opt73.adb: New test.
>
> --
> Eric Botcazou
diff mbox series

Patch

Index: tree-ssa-reassoc.c
===================================================================
--- tree-ssa-reassoc.c	(revision 262658)
+++ tree-ssa-reassoc.c	(working copy)
@@ -2168,8 +2168,13 @@  init_range_entry (struct range_entry *r,
 	  continue;
 	CASE_CONVERT:
 	  if (is_bool)
-	    goto do_default;
-	  if (TYPE_PRECISION (TREE_TYPE (arg0)) == 1)
+	    {
+	      if ((TYPE_PRECISION (exp_type) == 1
+		   || TREE_CODE (exp_type) == BOOLEAN_TYPE)
+		  && TYPE_PRECISION (TREE_TYPE (arg0)) > 1)
+		return;
+	    }
+	  else if (TYPE_PRECISION (TREE_TYPE (arg0)) == 1)
 	    {
 	      if (TYPE_UNSIGNED (TREE_TYPE (arg0)))
 		is_bool = true;