diff mbox series

[2/9] unop: prepare simplify_unop() to handle more cases

Message ID 20201023163939.58359-3-luc.vanoostenryck@gmail.com (mailing list archive)
State Mainlined, archived
Headers show
Series basic unop simplifications | expand

Commit Message

Luc Van Oostenryck Oct. 23, 2020, 4:39 p.m. UTC
Currently, simplify_unop() can only handle the simplification of
-(-x) and ~(~x).

Prepare it to handle more cases.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/simplify.c b/simplify.c
index 6caf6cbcf918..2750a90512b8 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1451,21 +1451,27 @@  static int simplify_constant_unop(struct instruction *insn)
 
 static int simplify_unop(struct instruction *insn)
 {
+	pseudo_t src = insn->src;
+
 	if (dead_insn(insn, &insn->src1, NULL, NULL))
 		return REPEAT_CSE;
-	if (constant(insn->src1))
+	if (constant(src))
 		return simplify_constant_unop(insn);
 
 	switch (insn->opcode) {
 		struct instruction *def;
 
 	case OP_NOT:
-		if (DEF_OPCODE(def, insn->src) == OP_NOT)
+		switch (DEF_OPCODE(def, src)) {
+		case OP_NOT:		// ~(~x) --> x
 			return replace_with_pseudo(insn, def->src);
+		}
 		break;
 	case OP_NEG:
-		if (DEF_OPCODE(def, insn->src) == OP_NEG)
+		switch (DEF_OPCODE(def, src)) {
+		case OP_NEG:		// -(-x) --> x
 			return replace_with_pseudo(insn, def->src);
+		}
 		break;
 	default:
 		return 0;