X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=ir%2Fopt%2Fjumpthreading.c;h=3e53ddb6901b8d2d073b0786794ba2a5ceda8c2e;hb=e0e9e9ace61d3ec46e4d09c7ab2c6947b17b2778;hp=055282095c645096daf2ad7014041458f94d5830;hpb=f8b8a445d2c65da173ad640978a5687761a3a620;p=libfirm diff --git a/ir/opt/jumpthreading.c b/ir/opt/jumpthreading.c index 055282095..3e53ddb69 100644 --- a/ir/opt/jumpthreading.c +++ b/ir/opt/jumpthreading.c @@ -44,7 +44,8 @@ #include "tv.h" #include "opt_confirms.h" #include "iropt_dbg.h" -#include "irtools.h" +#include "irpass.h" +#include "vrp.h" #undef AVOID_PHIB @@ -371,6 +372,27 @@ static int eval_cmp_tv(pn_Cmp pnc, tarval *tv_left, tarval *tv_right) return 1; } +/** + * returns whether the cmp evaluates to true or false according to vrp + * information , or can't be evaluated! + * 1: true, 0: false, -1: can't evaluate + * + * @param pnc the compare mode of the Compare + * @param left the left node + * @param right the right node + */ +static int eval_cmp_vrp(pn_Cmp pnc, ir_node *left, ir_node *right) +{ + pn_Cmp cmp_result = vrp_cmp(left, right); + + /* does the compare evaluate to true? */ + if (cmp_result == pn_Cmp_False) + return -1; + if ((cmp_result & pnc) != cmp_result) + return 0; + + return 1; +} /** * returns whether the cmp evaluates to true or false, or can't be evaluated! * 1: true, 0: false, -1: can't evaluate @@ -641,8 +663,15 @@ static void thread_jumps(ir_node* block, void* data) tarval *tv_right = get_Const_tarval(right); selector_evaluated = eval_cmp_tv(pnc, tv_left, tv_right); - if (selector_evaluated < 0) - return; + } + if (selector_evaluated < 0) { + /* This is only the case if the predecessor nodes are not + * constant or the comparison could not be evaluated. + * Try with VRP information now. + */ + int pnc = get_Proj_proj(selector); + + selector_evaluated = eval_cmp_vrp(pnc, left, right); } } } else if (is_Const_or_Confirm(selector)) { @@ -744,7 +773,7 @@ void opt_jumpthreading(ir_graph* irg) } /* Creates an ir_graph pass for opt_jumpthreading. */ -ir_graph_pass_t *opt_jumpthreading_pass(const char *name, int verify, int dump) +ir_graph_pass_t *opt_jumpthreading_pass(const char *name) { - return def_graph_pass(name ? name : "jumpthreading", verify, dump, opt_jumpthreading); + return def_graph_pass(name ? name : "jumpthreading", opt_jumpthreading); } /* opt_jumpthreading_pass */