===================================================================
@@ -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)
===================================================================
@@ -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" } } */