[PATCH 4/5] select: simplify SEL(SEL(x, C1, C2), y, z) --> y (with C1, C2 != 0)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 simplify.c                                 | 3 +++
 validation/optim/select-select-true-true.c | 1 -
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/simplify.c b/simplify.c
index 1fcfc691579a..20ea5f1be71a 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 e6fa2c89febb..c0c26fdd199a 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
-- 
2.29.2




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux