All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] add and use new helper: replace_with_value()
@ 2020-09-05 12:13 Luc Van Oostenryck
  2020-09-05 12:13 ` [PATCH 1/3] add helper replace_with_value() Luc Van Oostenryck
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-09-05 12:13 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

This makes things slightly more readable and is a preparatory
step for some others series.

Luc Van Oostenryck (3):
  add helper replace_with_value()
  use replace_with_value()
  replace_with_{pseudo,value}() can be tail-calls

 simplify.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] add helper replace_with_value()
  2020-09-05 12:13 [PATCH 0/3] add and use new helper: replace_with_value() Luc Van Oostenryck
@ 2020-09-05 12:13 ` Luc Van Oostenryck
  2020-09-05 12:13 ` [PATCH 2/3] use replace_with_value() Luc Van Oostenryck
  2020-09-05 12:13 ` [PATCH 3/3] replace_with_{pseudo,value}() can be tail-calls Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-09-05 12:13 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

During simplification, it's relatively common to have to replace
an instruction with pseudo corresponding to a known value.
The pseudo can be created with value_pseudo() and the replacement
can be made via replace_with_pseudo() but the combination
of the two is a bit long.

So, create an helper doing both sat once: replace_with_value().

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/simplify.c b/simplify.c
index f6b79685f439..0c75b3fadcab 100644
--- a/simplify.c
+++ b/simplify.c
@@ -465,6 +465,11 @@ static int replace_with_pseudo(struct instruction *insn, pseudo_t pseudo)
 	return REPEAT_CSE;
 }
 
+static inline int replace_with_value(struct instruction *insn, long long val)
+{
+	return replace_with_pseudo(insn, value_pseudo(val));
+}
+
 static inline int def_opcode(pseudo_t p)
 {
 	if (p->type != PSEUDO_REG)
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] use replace_with_value()
  2020-09-05 12:13 [PATCH 0/3] add and use new helper: replace_with_value() Luc Van Oostenryck
  2020-09-05 12:13 ` [PATCH 1/3] add helper replace_with_value() Luc Van Oostenryck
@ 2020-09-05 12:13 ` Luc Van Oostenryck
  2020-09-05 12:13 ` [PATCH 3/3] replace_with_{pseudo,value}() can be tail-calls Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-09-05 12:13 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

Replace existing 'replace_with_pseudo(insn, value_pseudo($N))'
by 'replace_with_value($N)'.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 simplify.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/simplify.c b/simplify.c
index 0c75b3fadcab..3c4b972ce607 100644
--- a/simplify.c
+++ b/simplify.c
@@ -838,7 +838,7 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v
 			omask = def->src2->value;
 			nmask = omask & mask;
 			if (nmask == 0)
-				return replace_with_pseudo(insn, value_pseudo(0));
+				return replace_with_value(insn, 0);
 			if (nmask == mask)
 				return replace_pseudo(insn, &insn->src1, def->src1);
 			if (nbr_users(pseudo) > 1)
@@ -874,7 +874,7 @@ static int simplify_shift(struct instruction *insn, pseudo_t pseudo, long long v
 			omask = def->src2->value;
 			nmask = omask & mask;
 			if (nmask == 0)
-				return replace_with_pseudo(insn, value_pseudo(0));
+				return replace_with_value(insn, 0);
 			if (nmask == mask)
 				return replace_pseudo(insn, &insn->src1, def->src1);
 			// do not simplify into ((A << S) & (M << S))
@@ -912,7 +912,7 @@ new_value:
 		return replace_pseudo(insn, &insn->src1, pseudo->def->src1);
 	}
 zero:
-	return replace_with_pseudo(insn, value_pseudo(0));
+	return replace_with_value(insn, 0);
 replace_mask:
 	insn->opcode = OP_AND;
 	insn->src2 = value_pseudo(mask);
@@ -1104,7 +1104,7 @@ static int simplify_constant_rightside(struct instruction *insn)
 
 	case OP_MODU: case OP_MODS:
 		if (value == 1)
-			return replace_with_pseudo(insn, value_pseudo(0));
+			return replace_with_value(insn, 0);
 		return 0;
 
 	case OP_DIVU: case OP_DIVS:
@@ -1167,14 +1167,14 @@ static int simplify_binop_same_args(struct instruction *insn, pseudo_t arg)
 			warning(insn->pos, "self-comparison always evaluates to false");
 	case OP_SUB:
 	case OP_XOR:
-		return replace_with_pseudo(insn, value_pseudo(0));
+		return replace_with_value(insn, 0);
 
 	case OP_SET_EQ:
 	case OP_SET_LE: case OP_SET_GE:
 	case OP_SET_BE: case OP_SET_AE:
 		if (Wtautological_compare)
 			warning(insn->pos, "self-comparison always evaluates to true");
-		return replace_with_pseudo(insn, value_pseudo(1));
+		return replace_with_value(insn, 1);
 
 	case OP_AND:
 	case OP_OR:
@@ -1298,7 +1298,7 @@ static int simplify_constant_unop(struct instruction *insn)
 	mask = 1ULL << (insn->size-1);
 	res &= mask | (mask-1);
 	
-	replace_with_pseudo(insn, value_pseudo(res));
+	replace_with_value(insn, res);
 	return REPEAT_CSE;
 }
 
@@ -1577,7 +1577,7 @@ static int simplify_select(struct instruction *insn)
 	if (cond == src2 && is_zero(src1)) {
 		kill_use(&insn->src1);
 		kill_use(&insn->src3);
-		replace_with_pseudo(insn, value_pseudo(0));
+		replace_with_value(insn, 0);
 		return REPEAT_CSE;
 	}
 	return 0;
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] replace_with_{pseudo,value}() can be tail-calls
  2020-09-05 12:13 [PATCH 0/3] add and use new helper: replace_with_value() Luc Van Oostenryck
  2020-09-05 12:13 ` [PATCH 1/3] add helper replace_with_value() Luc Van Oostenryck
  2020-09-05 12:13 ` [PATCH 2/3] use replace_with_value() Luc Van Oostenryck
@ 2020-09-05 12:13 ` Luc Van Oostenryck
  2 siblings, 0 replies; 4+ messages in thread
From: Luc Van Oostenryck @ 2020-09-05 12:13 UTC (permalink / raw)
  To: linux-sparse; +Cc: Luc Van Oostenryck

This avoids the need to have a separate 'return REPEAT_CSE' and
thus make the code slightly more compact and fast to read.

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

diff --git a/simplify.c b/simplify.c
index 3c4b972ce607..76c0558855a2 100644
--- a/simplify.c
+++ b/simplify.c
@@ -1153,8 +1153,7 @@ static int simplify_constant_binop(struct instruction *insn)
 	if (!res)
 		return 0;
 
-	replace_with_pseudo(insn, res);
-	return REPEAT_CSE;
+	return replace_with_pseudo(insn, res);
 }
 
 static int simplify_binop_same_args(struct instruction *insn, pseudo_t arg)
@@ -1298,8 +1297,7 @@ static int simplify_constant_unop(struct instruction *insn)
 	mask = 1ULL << (insn->size-1);
 	res &= mask | (mask-1);
 	
-	replace_with_value(insn, res);
-	return REPEAT_CSE;
+	return replace_with_value(insn, res);
 }
 
 static int simplify_unop(struct instruction *insn)
@@ -1554,8 +1552,7 @@ static int simplify_select(struct instruction *insn)
 		take = cond->value ? src1 : src2;
 		kill = cond->value ? &insn->src3 : &insn->src2;
 		kill_use(kill);
-		replace_with_pseudo(insn, take);
-		return REPEAT_CSE;
+		return replace_with_pseudo(insn, take);
 	}
 	if (constant(src1) && constant(src2)) {
 		long long val1 = src1->value;
@@ -1577,8 +1574,7 @@ static int simplify_select(struct instruction *insn)
 	if (cond == src2 && is_zero(src1)) {
 		kill_use(&insn->src1);
 		kill_use(&insn->src3);
-		replace_with_value(insn, 0);
-		return REPEAT_CSE;
+		return replace_with_value(insn, 0);
 	}
 	return 0;
 }
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-05 12:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-05 12:13 [PATCH 0/3] add and use new helper: replace_with_value() Luc Van Oostenryck
2020-09-05 12:13 ` [PATCH 1/3] add helper replace_with_value() Luc Van Oostenryck
2020-09-05 12:13 ` [PATCH 2/3] use replace_with_value() Luc Van Oostenryck
2020-09-05 12:13 ` [PATCH 3/3] replace_with_{pseudo,value}() can be tail-calls Luc Van Oostenryck

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.