[PATCH 2/6] cast: simplify simplify_cast()

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

 



The casts that can't or musn't be simplified away are filtered
out in simplify_cast() but now that we have more fine-grained
cast instructions, it's much more convenient to filter them out
already at the previous step, in simplify_instruction()'s switch.

Do this by:
* removing the filtering checks in simplify_cast()
* moving the casts we don't want to simplify out of simplify_cast()
  and letting them just call dead_insn() in the upper level.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 simplify.c | 27 ++++-----------------------
 1 file changed, 4 insertions(+), 23 deletions(-)

diff --git a/simplify.c b/simplify.c
index 6c05eb04d..9d79fd7a9 100644
--- a/simplify.c
+++ b/simplify.c
@@ -958,17 +958,6 @@ static int simplify_cast(struct instruction *insn)
 		return REPEAT_CSE;
 
 	orig_type = insn->orig_type;
-	if (!orig_type)
-		return 0;
-
-	/* Keep casts with pointer on either side (not only case of OP_PTRCAST) */
-	if (is_ptr_type(orig_type) || is_ptr_type(insn->type))
-		return 0;
-
-	/* Keep float-to-int and int-to-float casts */
-	if (is_float_type(orig_type) != is_float_type(insn->type))
-		return 0;
-
 	orig_size = orig_type->bit_size;
 	size = insn->size;
 	src = insn->src;
@@ -994,17 +983,6 @@ static int simplify_cast(struct instruction *insn)
 		}
 	}
 
-	if (size == orig_size) {
-		switch (insn->opcode) {
-		//case OP_NOPCAST:	// FIXME: what to do?
-		//case OP_PTRCAST:	// FIXME: what to do?
-		case OP_FCVTF:
-			goto simplify;
-		default:
-			break;
-		}
-	}
-
 	return 0;
 
 simplify:
@@ -1227,13 +1205,16 @@ int simplify_instruction(struct instruction *insn)
 		return replace_with_pseudo(insn, insn->symbol);
 	case OP_SEXT: case OP_ZEXT:
 	case OP_TRUNC:
+		return simplify_cast(insn);
 	case OP_FCVTU: case OP_FCVTS:
 	case OP_UCVTF: case OP_SCVTF:
 	case OP_FCVTF:
 	case OP_UTPTR:
 	case OP_PTRTU:
 	case OP_PTRCAST:
-		return simplify_cast(insn);
+		if (dead_insn(insn, &insn->src, NULL, NULL))
+			return REPEAT_CSE;
+		break;
 	case OP_PHI:
 		if (dead_insn(insn, NULL, NULL, NULL)) {
 			kill_use_list(insn->phi_list);
-- 
2.17.1

--
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