[PATCH 04/10] simplify 'x ^ ~0' to '~x'

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

 



This is yet anohter simple identity with the potential to trigger
more simplifications.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 simplify.c                       | 8 +++++++-
 validation/optim/bits-not-zero.c | 8 ++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/simplify.c b/simplify.c
index 09cbe16dc..c88ea5c33 100644
--- a/simplify.c
+++ b/simplify.c
@@ -634,6 +634,13 @@ static int simplify_constant_rightside(struct instruction *insn)
 			return replace_with_pseudo(insn, insn->src2);
 		goto case_neutral_zero;
 
+	case OP_XOR:
+		if ((value & bits) == bits) {
+			insn->opcode = OP_NOT;
+			return REPEAT_CSE;
+		}
+		goto case_neutral_zero;
+
 	case OP_SUB:
 		if (value) {
 			insn->opcode = OP_ADD;
@@ -642,7 +649,6 @@ static int simplify_constant_rightside(struct instruction *insn)
 		}
 	/* Fall through */
 	case OP_ADD:
-	case OP_XOR:
 	case OP_SHL:
 	case OP_LSR:
 	case_neutral_zero:
diff --git a/validation/optim/bits-not-zero.c b/validation/optim/bits-not-zero.c
index ce74705e8..189fe3311 100644
--- a/validation/optim/bits-not-zero.c
+++ b/validation/optim/bits-not-zero.c
@@ -1,5 +1,6 @@
 int  or_not0(int a) { return a | ~0; }
 int and_not0(int a) { return a & ~0; }
+int xor_not0(int a) { return a ^ ~0; }
 
 /*
  * check-name: bool-not-zero
@@ -18,5 +19,12 @@ and_not0:
 	ret.32      %arg1
 
 
+xor_not0:
+.L4:
+	<entry-point>
+	not.32      %r8 <- %arg1
+	ret.32      %r8
+
+
  * check-output-end
  */
-- 
2.18.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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