summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSebastian Buchwald <Sebastian.Buchwald@kit.edu>2018-05-02 13:38:48 +0200
committerJohannes Bucher <johannes.bucher2@student.kit.edu>2019-01-31 10:15:40 +0100
commit5fda609f50bd2dc888242b9261b96faef3e742d8 (patch)
tree5c0f3829b2a9ad6662308e6d7e0fb07147928310
parent39642cf1bb9ddf737ca1294fe9be5b1a1a9a327b (diff)
Proof-of-concept local optimization
-rw-r--r--ir/opt/iropt.c47
1 files changed, 33 insertions, 14 deletions
diff --git a/ir/opt/iropt.c b/ir/opt/iropt.c
index 71e82d0..a5f1930 100644
--- a/ir/opt/iropt.c
+++ b/ir/opt/iropt.c
@@ -3060,22 +3060,41 @@ static ir_node *transform_node_Add(ir_node *n)
}
}
- if (is_Const(b) && is_Sub(a)) {
- const ir_node *sub_l = get_Sub_left(a);
- ir_tarval *ts = value_of(sub_l);
+ if (is_Const(b)) {
+ if (is_Confirm(a)) {
+ const ir_node *bound = get_Confirm_bound(a);
+ ir_tarval *tbound = value_of(bound);
- if (tarval_is_constant(ts)) {
- ir_tarval *tb = get_Const_tarval(b);
- ir_tarval *tv = tarval_add(ts, tb);
+ if (get_Confirm_relation(a) == ir_relation_less_equal && tarval_is_constant(tbound)) {
+ ir_tarval *tb = get_Const_tarval(b);
+ ir_tarval *tv = tarval_add(tbound, tb);
+ if (tarval_is_constant(tv)) {
+ ir_node *value = get_Confirm_value(a);
+ dbg_info *dbgi = get_irn_dbg_info(n);
+ ir_graph *irg = get_irn_irg(n);
+ ir_node *block = get_nodes_block(n);
+ ir_node *cnst = new_r_Const(irg, tv);
+ ir_node *add = new_rd_Add(dbgi, block, value, b);
+ return new_rd_Confirm(dbgi, block, add, cnst, ir_relation_less_equal);
+ }
+ }
+ } else if (is_Sub(a)) {
+ const ir_node *sub_l = get_Sub_left(a);
+ ir_tarval *ts = value_of(sub_l);
- if (tarval_is_constant(tv)) {
- /* (C1 - x) + C2 = (C1 + C2) - x */
- dbg_info *dbgi = get_irn_dbg_info(n);
- ir_graph *irg = get_irn_irg(n);
- ir_node *block = get_nodes_block(n);
- ir_node *cnst = new_r_Const(irg, tv);
- ir_node *sub_r = get_Sub_right(a);
- return new_rd_Sub(dbgi, block, cnst, sub_r);
+ if (tarval_is_constant(ts)) {
+ ir_tarval *tb = get_Const_tarval(b);
+ ir_tarval *tv = tarval_add(ts, tb);
+
+ if (tarval_is_constant(tv)) {
+ /* (C1 - x) + C2 = (C1 + C2) - x */
+ dbg_info *dbgi = get_irn_dbg_info(n);
+ ir_graph *irg = get_irn_irg(n);
+ ir_node *block = get_nodes_block(n);
+ ir_node *cnst = new_r_Const(irg, tv);
+ ir_node *sub_r = get_Sub_right(a);
+ return new_rd_Sub(dbgi, block, cnst, sub_r);
+ }
}
}
}