--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+/* PR tree-optimization/116890 */
+
+int f(int a, int b, int c)
+{
+ int x;
+ if (c) x = a == 0;
+ else x = 0;
+ return x;
+}
+
+
+/* The if should have been removed as the the conversion from bool to int should have been factored out. */
+/* { dg-final { scan-tree-dump-not "if" "optimized" } }*/
+/* { dg-final { scan-tree-dump-times "\[^\r\n\]*_\[0-9\]* = a_\[0-9\]*.D. == 0" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "\[^\r\n\]*_\[0-9\]* = c_\[0-9\]*.D. != 0" 1 "optimized" } } */
+
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+/* PR tree-optimization/116890 */
+
+int f(_Bool a, _Bool b, int c)
+{
+ int x;
+ if (c) x = a & b;
+ else x = 0;
+ return x;
+}
+
+
+/* The if should have been removed as the the conversion from bool to int should have been factored out. */
+/* { dg-final { scan-tree-dump-not "if" "optimized" } }*/
+/* { dg-final { scan-tree-dump-times "\[^\r\n\]*_\[0-9\]* = a_\[0-9\]*.D. & b_\[0-9\]*.D." 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "\[^\r\n\]*_\[0-9\]* = c_\[0-9\]*.D. != 0" 1 "optimized" } } */
+
return g(d,e);
}
-/* There should be one ifs as one of them should be changed into
- a conditional and the other should be there still. */
-/* { dg-final { scan-tree-dump-times "if" 1 "optimized" } }*/
+/* There should be no ifs as this is converted into `(t != 0) & (c != 0)`.
+/* { dg-final { scan-tree-dump-not "if" "optimized" } }*/
/* { dg-final { scan-tree-dump-times "\[^\r\n\]*_\[0-9\]* = c_\[0-9\]*.D. != 0" 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "\[^\r\n\]*_\[0-9\]* = t_\[0-9\]*.D. != 0" 1 "optimized" } } */
if (gassign *assign = dyn_cast <gassign *> (stmt))
{
tree lhs = gimple_assign_lhs (assign);
+ tree lhst = TREE_TYPE (lhs);
enum tree_code ass_code
= gimple_assign_rhs_code (assign);
- if (ass_code != MAX_EXPR && ass_code != MIN_EXPR)
+ if (ass_code != MAX_EXPR && ass_code != MIN_EXPR
+ /* Conversions from boolean like types is ok
+ as `a?1:b` and `a?0:b` will always simplify
+ to `a & b` or `a | b`.
+ See PR 116890. */
+ && !(INTEGRAL_TYPE_P (lhst)
+ && TYPE_UNSIGNED (lhst)
+ && TYPE_PRECISION (lhst) == 1))
return NULL;
if (lhs != gimple_assign_rhs1 (arg0_def_stmt))
return NULL;