)
)
+(simplify
+ (cond @0 zero_one_valued_p@1 zero_one_valued_p@2)
+ (switch
+ /* bool0 ? bool1 : 0 -> bool0 & bool1 */
+ (if (integer_zerop (@2))
+ (bit_and (convert @0) @1))
+ /* bool0 ? 0 : bool2 -> (bool0^1) & bool2 */
+ (if (integer_zerop (@1))
+ (bit_and (bit_xor (convert @0) { build_one_cst (type); } ) @2))
+ /* bool0 ? 1 : bool2 -> bool0 | bool2 */
+ (if (integer_onep (@1))
+ (bit_ior (convert @0) @2))
+ /* bool0 ? bool1 : 1 -> (bool0^1) | bool1 */
+ (if (integer_onep (@2))
+ (bit_ior (bit_xor (convert @0) @2) @1))
+ )
+)
+
/* Optimize
# x_5 in range [cst1, cst2] where cst2 = cst1 + 1
x_5 ? cstN ? cst4 : cst3
}
-/* There should be only one if, the outer one; the inner one
- should have been changed to straight line code with the
- value of b (except that we don't fold ! (b != 0) into b
- which can be fixed in a different patch).
- Test this only when known to be !LOGICAL_OP_NON_SHORT_CIRCUIT,
- otherwise ifcombine may convert this into return a & b;. */
-/* { dg-final { scan-tree-dump-times "if" 1 "optimized" } } */
+/* There should be no if statements and be fold into just return a & b.
+ This can be done without ifcombine but in phiopt where a ? b : 0 is
+ converted into a & b. */
+/* { dg-final { scan-tree-dump-not "if" "optimized" } } */
+/* { dg-final { scan-tree-dump-times " & " 1 "optimized" } } */
return x ? __builtin_popcountll(y) : 0;
}
-/* 4 types of functions, each with 3 types and there are 2 goto each */
-/* { dg-final { scan-tree-dump-times "goto " 24 "optimized" } } */
-
+/* 3 types of functions (not including parity), each with 3 types and there are 2 goto each */
+/* { dg-final { scan-tree-dump-times "goto " 18 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "x_..D. != 0" 12 "optimized" } } */
+/* parity case will be optimized to x!=0 & parity(y) . */
+/* { dg-final { scan-tree-dump-times " & " 3 "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+_Bool f1(_Bool a, _Bool b)
+{
+ if (a)
+ return b;
+ return 0;
+}
+
+
+/* There should be no if statements and be fold into just return a & b. */
+/* { dg-final { scan-tree-dump-not "if" "optimized" } } */
+/* { dg-final { scan-tree-dump-times " & " 1 "optimized" } } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+_Bool f1(_Bool a, _Bool b)
+{
+ if (a)
+ return 1;
+ return b;
+}
+
+
+/* There should be no if statements and be fold into just return a & b. */
+/* { dg-final { scan-tree-dump-not "if" "optimized" } } */
+/* { dg-final { scan-tree-dump-times " \\\| " 1 "optimized" } } */
--- /dev/null
+/* PR tree-optimization/89263 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized-raw" } */
+
+_Bool f0(_Bool a, _Bool b)
+{
+ return a ? b : 0;
+}
+_Bool f1(_Bool a, _Bool b)
+{
+ return a ? b : 1;
+}
+_Bool t0(_Bool a, _Bool b)
+{
+ return a ? 0 : b;
+}
+_Bool t1(_Bool a, _Bool b)
+{
+ return a ? 1 : b;
+}
+
+/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */
+/* { dg-final { scan-tree-dump-times "bit_and_expr," 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "bit_ior_expr," 2 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "bit_not_expr," 2 "optimized" } } */
--- /dev/null
+/* PR tree-optimization/20083 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized-raw" } */
+
+
+int f(int i, int j, int l)
+{
+ int k = 0;
+ if (i)
+ k = 1;
+ if (j)
+ k = 1;
+ if (l)
+ k = 1;
+ return k;
+}
+int f1(int i, int j, int l)
+{
+ int k = 0;
+ if (i)
+ k = 1;
+ else if (j)
+ k = 1;
+ else if (l)
+ k = 1;
+ return k;
+}
+int f2(int i, int j, int l)
+{
+ return i||j||l;
+}
+int f3(int i, int j, int l)
+{
+ int t = i | j;
+ _Bool t1 = l != 0;
+ _Bool t2 = t ? 1 : t1;
+ return t2;
+}
+
+int f4(int i, int j, int l)
+{
+ int t = i | j;
+ _Bool t1 = l != 0;
+ _Bool t2;
+ if (t)
+ t2 = 1;
+ else
+ t2 = t1;
+ return t2;
+}
+
+/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */
+/* 2 ior for each function. */
+/* { dg-final { scan-tree-dump-times "bit_ior_expr," 10 "optimized" } } */
+/* { dg-final { scan-tree-dump-times "ne_expr," 5 "optimized" } } */
--- /dev/null
+/* PR tree-optimization/94898 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized-raw" } */
+
+
+_Bool f(int x, int y)
+{
+ if (x >= y)
+ return x - y;
+ return 0;
+}
+
+/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */
+/* { dg-final { scan-tree-dump-times "gt_expr," 1 "optimized" } } */
+/* { dg-final { scan-tree-dump-not "ne_expr," "optimized" } } */
--- /dev/null
+/* PR tree-optimization/99069 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized-raw" } */
+
+_Bool f(_Bool x, _Bool y)
+{
+ return (x ? y : 0) ? x : 0;
+}
+
+
+/* { dg-final { scan-tree-dump-not "gimple_cond " "optimized" } } */
+/* { dg-final { scan-tree-dump-times "bit_and_expr," 1 "optimized" } } */
/* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-thread2-stats -fdump-tree-optimized" } */
+/* { dg-options "-O2 -fdump-tree-thread2-stats -fdump-tree-optimized -fno-ssa-phiopt" } */
long a;
int b;
a = b;
}
+/* Disable phiopt as the threading opportunity goes away. */
/* We need to perform a non-multi-way branch FSM thread creating an
irreducible loop in thread2 to allow followup threading to
remove the call to foo (). */