[PATCH] boolean conversion of boolean value is a no-op

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

 



If an expression is already a boolean (constant) expression,
converting it to a boolean expression is a no-op.

In this case, return early, this avoids to create intermediate
code that will need to be simplified away at some later stage.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 linearize.c                      |  2 ++
 validation/optim/bool-simplify.c | 12 ++++++------
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/linearize.c b/linearize.c
index eeef0ba73..62918eef3 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1380,6 +1380,8 @@ static inline pseudo_t add_convert_to_bool(struct entrypoint *ep, pseudo_t src,
 		return VOID;
 	if (is_bool_type(type))
 		return src;
+	if (src->type == PSEUDO_VAL && (src->value == 0 || src->value == 1))
+		return src;
 	if (is_float_type(type)) {
 		zero = add_setfval(ep, type, 0.0);
 		op = map_opcode(OP_SET_NE, type);
diff --git a/validation/optim/bool-simplify.c b/validation/optim/bool-simplify.c
index b872764ca..fe8ce88b0 100644
--- a/validation/optim/bool-simplify.c
+++ b/validation/optim/bool-simplify.c
@@ -43,15 +43,15 @@ and_0:
 and_1:
 .L2:
 	<entry-point>
-	setne.32    %r11 <- %arg1, $0
-	ret.32      %r11
+	setne.32    %r9 <- %arg1, $0
+	ret.32      %r9
 
 
 or_0:
 .L4:
 	<entry-point>
-	setne.32    %r17 <- %arg1, $0
-	ret.32      %r17
+	setne.32    %r14 <- %arg1, $0
+	ret.32      %r14
 
 
 or_1:
@@ -63,8 +63,8 @@ or_1:
 and_2:
 .L8:
 	<entry-point>
-	setne.32    %r29 <- %arg1, $0
-	ret.32      %r29
+	setne.32    %r25 <- %arg1, $0
+	ret.32      %r25
 
 
 or_2:
-- 
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