aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-07 20:26:15 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-08 02:31:18 +0100
commitb5bbdc9c3835b62c1e67bbd1b69017bb07f57823 (patch)
treec88fb0f11177072dfa8d93ab3a7a0109e1010122
parent29c405153720add05185351a13dcc68a5f39d3ff (diff)
downloadsparse-b5bbdc9c3835b62c1e67bbd1b69017bb07f57823.tar.gz
select: simplify select(x, x, 0) --> x
The dual simplification select(x, 0, x) --> 0 was already done but this one was forgotten, so add it now. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--simplify.c2
-rw-r--r--validation/optim/call-inlined.c11
-rw-r--r--validation/optim/select-self-zero.c1
3 files changed, 5 insertions, 9 deletions
diff --git a/simplify.c b/simplify.c
index 95ccd4c0..6713e8af 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1778,6 +1778,8 @@ static int simplify_select(struct instruction *insn)
}
if (cond == src2 && is_zero(src1)) // SEL(x, 0, x) --> 0
return replace_with_pseudo(insn, src1);
+ if (cond == src1 && is_zero(src2)) // SEL(x, x, 0) --> x
+ return replace_with_pseudo(insn, cond);
switch (DEF_OPCODE(def, cond)) {
case OP_SET_EQ:
diff --git a/validation/optim/call-inlined.c b/validation/optim/call-inlined.c
index f21b3294..7f5f4e89 100644
--- a/validation/optim/call-inlined.c
+++ b/validation/optim/call-inlined.c
@@ -18,13 +18,6 @@ int foo(int a, int b, int p)
* check-name: call-inlined
* check-command: test-linearize -Wno-decl $file
*
- * check-output-start
-foo:
-.L0:
- <entry-point>
- select.32 %r10 <- %arg3, %arg3, $0
- ret.32 %r10
-
-
- * check-output-end
+ * check-output-ignore
+ * check-output-returns: %arg3
*/
diff --git a/validation/optim/select-self-zero.c b/validation/optim/select-self-zero.c
index ea309894..73b3a3dc 100644
--- a/validation/optim/select-self-zero.c
+++ b/validation/optim/select-self-zero.c
@@ -1,4 +1,5 @@
int sel_self0x(int x) { return (x ? 0 : x) == 0; }
+int sel_selfx0(int x) { return (x ? x : 0) == x; }
/*
* check-name: select-self-zero