+2018-08-15 Martin Liska <mliska@suse.cz>
+
+ PR tree-optimization/86925
+ * predict.c (expr_expected_value_1): When taking
+ later predictor, assign also probability.
+ Use fold_build2_initializer_loc in order to fold
+ the expression in -frounding-math.
+
2018-08-14 Allan Sandfeld Jensen <allan.jensen@qt.io>
* config/i386/i386.c (expand_vec_perm_movs): New method matching movs
if (arg == PHI_RESULT (def))
continue;
+ HOST_WIDE_INT probability2;
new_val = expr_expected_value (arg, visited, &predictor2,
- probability);
+ &probability2);
/* It is difficult to combine value predictors. Simply assume
that later predictor is weaker and take its prediction. */
if (*predictor < predictor2)
- *predictor = predictor2;
+ {
+ *predictor = predictor2;
+ *probability = probability2;
+ }
if (!new_val)
return NULL;
if (!val)
tree base = build_int_cst (integer_type_node,
REG_BR_PROB_BASE);
base = build_real_from_int_cst (t, base);
- tree r = fold_build2 (MULT_EXPR, t, prob, base);
+ tree r = fold_build2_initializer_loc (UNKNOWN_LOCATION,
+ MULT_EXPR, t, prob, base);
HOST_WIDE_INT probi
= real_to_integer (TREE_REAL_CST_PTR (r));
if (probi >= 0 && probi <= REG_BR_PROB_BASE)
+2018-08-15 Martin Liska <mliska@suse.cz>
+
+ PR tree-optimization/86925
+ * gcc.dg/predict-20.c: New test.
+ * gcc.dg/predict-21.c: New test.
+
2018-08-15 Paolo Carlini <paolo.carlini@oracle.com>
* g++.dg/init/goto3.C: Adjust for error instead of permerror.
--- /dev/null
+/* PR tree-optimization/86925 */
+
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
+
+int a, b;
+
+void
+c ()
+{
+ for (;;)
+ {
+ if (__builtin_expect (b < 0, 0))
+ break;
+ if (__builtin_expect (a, 1))
+ break;
+ }
+ int d = b < 0;
+ if (__builtin_expect (d, 0))
+ asm("");
+}
+
+/* { dg-final { scan-tree-dump-times "__builtin_expect heuristics of edge" 3 "profile_estimate"} } */
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-profile_estimate -frounding-math" } */
+
+extern int global;
+
+void foo (int base)
+{
+ for (int i = 0; __builtin_expect_with_probability (i < base, 1, 0.05f); i++)
+ global++;
+}
+
+/* { dg-final { scan-tree-dump "first match heuristics: 5.00%" "profile_estimate"} } */
+/* { dg-final { scan-tree-dump "__builtin_expect_with_probability heuristics of edge .*->.*: 5.00%" "profile_estimate"} } */