* Relax VIEW_CONVERT_EXPR - CONVERT_EXPR combination
@ 2017-05-21 21:56 Marc Glisse
2017-05-24 10:17 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: Marc Glisse @ 2017-05-21 21:56 UTC (permalink / raw)
To: gcc-patches
[-- Attachment #1: Type: TEXT/PLAIN, Size: 553 bytes --]
Hello,
SRA uses char when scalarizing bool, and we end up with
_6 = u_1(D) == 0.0;
_7 = (unsigned char) _6;
_3 = VIEW_CONVERT_EXPR<_Bool>(_7);
which we currently do not simplify. I am not completely sure what happens
with types whose precision does not cover their size, I hope this is safe.
Bootstrap+testsuite on powerpc64le-unknown-linux-gnu.
2017-05-22 Marc Glisse <marc.glisse@inria.fr>
gcc/
* match.pd (view_convert (convert@0 @1)): Handle zero-extension.
gcc/testsuite/
* gcc.dg/tree-ssa/vce-1.c: New file.
--
Marc Glisse
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: TEXT/x-diff; name=vce.patch, Size: 2201 bytes --]
Index: match.pd
===================================================================
--- match.pd (revision 248312)
+++ match.pd (working copy)
@@ -1798,27 +1798,30 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* For integral conversions with the same precision or pointer
conversions use a NOP_EXPR instead. */
(simplify
(view_convert @0)
(if ((INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type))
&& (INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0)))
&& TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (@0)))
(convert @0)))
-/* Strip inner integral conversions that do not change precision or size. */
+/* Strip inner integral conversions that do not change precision or size, or
+ zero-extend while keeping the same size (for bool-to-char). */
(simplify
(view_convert (convert@0 @1))
(if ((INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0)))
&& (INTEGRAL_TYPE_P (TREE_TYPE (@1)) || POINTER_TYPE_P (TREE_TYPE (@1)))
- && (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
- && (TYPE_SIZE (TREE_TYPE (@0)) == TYPE_SIZE (TREE_TYPE (@1))))
+ && TYPE_SIZE (TREE_TYPE (@0)) == TYPE_SIZE (TREE_TYPE (@1))
+ && (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1))
+ || (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (TREE_TYPE (@1))
+ && TYPE_UNSIGNED (TREE_TYPE (@1)))))
(view_convert @1)))
/* Re-association barriers around constants and other re-association
barriers can be removed. */
(simplify
(paren CONSTANT_CLASS_P@0)
@0)
(simplify
(paren (paren@1 @0))
@1)
Index: testsuite/gcc.dg/tree-ssa/vce-1.c
===================================================================
--- testsuite/gcc.dg/tree-ssa/vce-1.c (nonexistent)
+++ testsuite/gcc.dg/tree-ssa/vce-1.c (working copy)
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+typedef struct { _Bool b; } A;
+_Bool f(double u){
+ A a;
+ if(u==0)
+ a.b=1;
+ else
+ a.b=0;
+ return a.b;
+}
+
+/* { dg-final { scan-tree-dump-not "VIEW_CONVERT_EXPR" "optimized" } } */
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Relax VIEW_CONVERT_EXPR - CONVERT_EXPR combination
2017-05-21 21:56 Relax VIEW_CONVERT_EXPR - CONVERT_EXPR combination Marc Glisse
@ 2017-05-24 10:17 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2017-05-24 10:17 UTC (permalink / raw)
To: Marc Glisse; +Cc: GCC Patches
On Sun, May 21, 2017 at 11:21 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> Hello,
>
> SRA uses char when scalarizing bool, and we end up with
>
> _6 = u_1(D) == 0.0;
> _7 = (unsigned char) _6;
> _3 = VIEW_CONVERT_EXPR<_Bool>(_7);
>
> which we currently do not simplify. I am not completely sure what happens
> with types whose precision does not cover their size, I hope this is safe.
Hmm, if zero-extension is safe so should sign-extension, no? Because
if size != precision then both can actually change bits outside of the
precision?
I realize zero-extension is "safer" in some sense as the extended value
is the same for all precisions.
Thus OK.
thanks,
Richard.
> Bootstrap+testsuite on powerpc64le-unknown-linux-gnu.
>
> 2017-05-22 Marc Glisse <marc.glisse@inria.fr>
>
> gcc/
> * match.pd (view_convert (convert@0 @1)): Handle zero-extension.
>
> gcc/testsuite/
> * gcc.dg/tree-ssa/vce-1.c: New file.
>
> --
> Marc Glisse
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-05-24 8:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-21 21:56 Relax VIEW_CONVERT_EXPR - CONVERT_EXPR combination Marc Glisse
2017-05-24 10:17 ` Richard Biener
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).