aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-09-28 01:11:50 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-10-20 22:35:43 +0200
commitee607141242f7ac140a58b4869bf7b7909419629 (patch)
treea2a8ce7149f668b6fb06f85e6613aed2977a82c0
parent4afcbe027c4f0571568ac00c7a7e086589001c9d (diff)
downloadsparse-ee607141242f7ac140a58b4869bf7b7909419629.tar.gz
sub: simplify C - (y + D) --> eval(C-D) - y
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c18
-rw-r--r--validation/optim/simplify-cte-sub-addr.c1
2 files changed, 18 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index aa0357d9..b97354bc 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1157,6 +1157,22 @@ static int simplify_constant_rightside(struct instruction *insn)
return 0;
}
+static int simplify_const_leftsub(struct instruction *insn, struct instruction *def)
+{
+ unsigned size = insn->size;
+ pseudo_t src1 = insn->src1;
+
+ switch (def->opcode) {
+ case OP_ADD:
+ if (constant(def->src2)) { // C - (y + D) --> eval(C-D) - y
+ insn->src1 = eval_op(OP_SUB, size, src1, def->src2);
+ return replace_pseudo(insn, &insn->src2, def->src1);
+ }
+ break;
+ }
+ return 0;
+}
+
static int simplify_constant_leftside(struct instruction *insn)
{
long long value = insn->src1->value;
@@ -1177,6 +1193,8 @@ static int simplify_constant_leftside(struct instruction *insn)
case OP_SUB:
if (!value) // (0 - x) --> -x
return replace_with_unop(insn, OP_NEG, insn->src2);
+ if (insn->src2->type == PSEUDO_REG)
+ return simplify_const_leftsub(insn, insn->src2->def);
break;
}
return 0;
diff --git a/validation/optim/simplify-cte-sub-addr.c b/validation/optim/simplify-cte-sub-addr.c
index 81f5b345..bf36c8a0 100644
--- a/validation/optim/simplify-cte-sub-addr.c
+++ b/validation/optim/simplify-cte-sub-addr.c
@@ -3,7 +3,6 @@ int cte_sub_addr(int x) { return 2 - (x + 1); }
/*
* check-name: simplify-cte-sub-addr
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-contains: sub\\..*\\$1, %arg1