aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-07 01:09:07 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-07 12:27:49 +0100
commit84bf7462ebc80b350b0d2b35156bae04b8d5feb1 (patch)
tree03156e3b9efafed7777e0c4a82d4259206de4223
parent93bb38fdbfb16f8382954db1e02a6ff1731bd60f (diff)
downloadsparse-84bf7462ebc80b350b0d2b35156bae04b8d5feb1.tar.gz
select: simplify SEL(SEL(x, C1, C2), y, z) --> y (with C1, C2 != 0)
If the condition of a select is also a select, with constant but non-zero operands, then the result of this inner select is always true and the outer select can be replaced by its second operand. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c3
-rw-r--r--validation/optim/select-select-true-true.c1
2 files changed, 3 insertions, 1 deletions
diff --git a/simplify.c b/simplify.c
index 1fcfc691..20ea5f1b 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1793,6 +1793,7 @@ static int simplify_select(struct instruction *insn)
// SEL(SEL(x, C, 0), y, z) --> SEL(x, y, z)
// SEL(SEL(x, C, 0), C, 0) --> SEL(x, C, 0) == cond
// SEL(SEL(x, 0, C), y, z) --> SEL(x, z, y)
+ // SEL(SEL(x, C1, C2), y, z) --> y
if (!def->src3->value) {
if ((src1 == def->src2) && (src2 == def->src3))
return replace_with_pseudo(insn, cond);
@@ -1802,6 +1803,8 @@ static int simplify_select(struct instruction *insn)
switch_pseudo(insn, &insn->src2, insn, &insn->src3);
return replace_pseudo(insn, &insn->cond, def->cond);
}
+ // both values must be non-zero
+ return replace_with_pseudo(insn, src1);
}
break;
}
diff --git a/validation/optim/select-select-true-true.c b/validation/optim/select-select-true-true.c
index e6fa2c89..c0c26fdd 100644
--- a/validation/optim/select-select-true-true.c
+++ b/validation/optim/select-select-true-true.c
@@ -3,7 +3,6 @@ int foo(int p, int a, int b) { return ((p ? 42 : 43) ? a : b) == a ; }
/*
* check-name: select-select-true-true
* check-command: test-linearize -Wno-decl $file
- * check-known-to-fail
*
* check-output-ignore
* check-output-returns: 1