*ret_nonspec_clause = nonspec_clause;
}
+/* Return true if VRP will be exectued on the function.
+ We do not want to anticipate optimizations that will not happen.
+
+ FIXME: This can be confused with -fdisable and debug counters and thus
+ it should not be used for correctness (only to make heuristics work).
+ This means that inliner should do its own optimizations of expressions
+ that it predicts to be constant so wrong code can not be triggered by
+ builtin_constant_p. */
+
+static bool
+vrp_will_run_p (struct cgraph_node *node)
+{
+ return (opt_for_fn (node->decl, optimize)
+ && !opt_for_fn (node->decl, optimize_debug)
+ && opt_for_fn (node->decl, flag_tree_vrp));
+}
+
+/* Similarly about FRE. */
+
+static bool
+fre_will_run_p (struct cgraph_node *node)
+{
+ return (opt_for_fn (node->decl, optimize)
+ && !opt_for_fn (node->decl, optimize_debug)
+ && opt_for_fn (node->decl, flag_tree_fre));
+}
/* Work out what conditions might be true at invocation of E.
Compute costs for inlined edge if INLINE_P is true.
/* If we failed to get simple constant, try value range. */
if ((!cst || TREE_CODE (cst) != INTEGER_CST)
+ && vrp_will_run_p (caller)
&& ipa_is_param_used_by_ipa_predicates (callee_pi, i))
{
value_range vr
}
/* Determine known aggregate values. */
- ipa_agg_value_set agg
- = ipa_agg_value_set_from_jfunc (caller_parms_info,
- caller, &jf->agg);
- if (agg.items.length ())
+ if (vrp_will_run_p (caller))
{
- if (!known_aggs_ptr->length ())
- vec_safe_grow_cleared (known_aggs_ptr, count);
- (*known_aggs_ptr)[i] = agg;
+ ipa_agg_value_set agg
+ = ipa_agg_value_set_from_jfunc (caller_parms_info,
+ caller, &jf->agg);
+ if (agg.items.length ())
+ {
+ if (!known_aggs_ptr->length ())
+ vec_safe_grow_cleared (known_aggs_ptr, count);
+ (*known_aggs_ptr)[i] = agg;
+ }
}
}
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Og --coverage -pthread -fdump-tree-optimized -std=c++17" } */
+using uint16_t = unsigned short;
+
+struct a {
+ uint16_t b = 0;
+};
+struct c {
+ short d;
+};
+class e {
+public:
+ void f();
+ void init_session(c);
+};
+
+auto htons = [](uint16_t s) {
+ if (__builtin_constant_p(s)) {
+ return uint16_t(uint16_t(s >> 8) | uint16_t(s << 8));
+ }
+ return uint16_t(uint16_t(s >> 8) | uint16_t(s << 8));
+};
+
+struct g {
+ e h;
+ void i(a k) {
+ h.f();
+ auto j = c();
+ j.d = htons(k.b);
+ h.init_session(j);
+ }
+};
+
+void test() {
+ g().i({});
+}
+
+/* { dg-final { scan-tree-dump-not "builtin_unreachable" "optimized"} } */