All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 4/6] generate plain OP_{AND,OR} instead of OP_{AND,OR}_BOOL
Date: Wed, 12 Apr 2017 21:33:42 +0200	[thread overview]
Message-ID: <20170412193344.95935-5-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170412193344.95935-1-luc.vanoostenryck@gmail.com>

Now that OP_AND_BOOL and OP_OR_BOOL are always given boolean
operands, they are just a special case of 1 bit OP_AND & OP_OR.

To avoid to have to repeat CSE, simplification patterns, ...
better to simply generate OP_AND & OP_OR instructions instead.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c                        |  2 +-
 validation/optim/bool-context-fp.c |  8 ++++----
 validation/optim/bool-simplify.c   | 24 ++++++++++++++++++++++++
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/linearize.c b/linearize.c
index e730ab56f..e6b77ec01 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1379,7 +1379,7 @@ static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expressi
 static pseudo_t linearize_binop_bool(struct entrypoint *ep, struct expression *expr)
 {
 	pseudo_t src1, src2, dst;
-	int op = (expr->op == SPECIAL_LOGICAL_OR) ? OP_OR_BOOL : OP_AND_BOOL;
+	int op = (expr->op == SPECIAL_LOGICAL_OR) ? OP_OR : OP_AND;
 
 	src1 = linearize_expression_to_bool(ep, expr->left);
 	src2 = linearize_expression_to_bool(ep, expr->right);
diff --git a/validation/optim/bool-context-fp.c b/validation/optim/bool-context-fp.c
index 2f15fe94d..3ce1574b9 100644
--- a/validation/optim/bool-context-fp.c
+++ b/validation/optim/bool-context-fp.c
@@ -53,7 +53,7 @@ bfior:
 	setfval.32  %r19 <- 0.000000
 	fcmpune.1   %r20 <- %arg1, %r19
 	fcmpune.1   %r23 <- %arg2, %r19
-	or-bool.1   %r24 <- %r23, %r20
+	or.1        %r24 <- %r23, %r20
 	ret.1       %r24
 
 
@@ -63,7 +63,7 @@ ifior:
 	setfval.32  %r29 <- 0.000000
 	fcmpune.1   %r30 <- %arg1, %r29
 	fcmpune.1   %r33 <- %arg2, %r29
-	or-bool.1   %r34 <- %r33, %r30
+	or.1        %r34 <- %r33, %r30
 	cast.32     %r35 <- (1) %r34
 	ret.32      %r35
 
@@ -74,7 +74,7 @@ bfand:
 	setfval.32  %r38 <- 0.000000
 	fcmpune.1   %r39 <- %arg1, %r38
 	fcmpune.1   %r42 <- %arg2, %r38
-	and-bool.1  %r43 <- %r42, %r39
+	and.1       %r43 <- %r42, %r39
 	ret.1       %r43
 
 
@@ -84,7 +84,7 @@ ifand:
 	setfval.32  %r48 <- 0.000000
 	fcmpune.1   %r49 <- %arg1, %r48
 	fcmpune.1   %r52 <- %arg2, %r48
-	and-bool.1  %r53 <- %r52, %r49
+	and.1       %r53 <- %r52, %r49
 	cast.32     %r54 <- (1) %r53
 	ret.32      %r54
 
diff --git a/validation/optim/bool-simplify.c b/validation/optim/bool-simplify.c
index 2014d344c..b872764ca 100644
--- a/validation/optim/bool-simplify.c
+++ b/validation/optim/bool-simplify.c
@@ -18,6 +18,17 @@ int or_1(int a)
 	return a || 1;
 }
 
+// try again but with something true but != 1
+int and_2(int a)
+{
+	return a && 2;
+}
+
+int or_2(int a)
+{
+	return a || 2;
+}
+
 /*
  * check-name: bool-simplify
  * check-command: test-linearize -Wno-decl $file
@@ -49,5 +60,18 @@ or_1:
 	ret.32      $1
 
 
+and_2:
+.L8:
+	<entry-point>
+	setne.32    %r29 <- %arg1, $0
+	ret.32      %r29
+
+
+or_2:
+.L10:
+	<entry-point>
+	ret.32      $1
+
+
  * check-output-end
  */
-- 
2.12.0


  parent reply	other threads:[~2017-04-12 19:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-12 19:33 [PATCH 0/6] fix boolean context Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 1/6] fix boolean context for OP_AND_BOOL & OP_OR_BOOL Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 2/6] simplify intermediate casts in boolean expressions Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 3/6] avoid useless compare with zero Luc Van Oostenryck
2017-04-12 19:33 ` Luc Van Oostenryck [this message]
2017-04-12 19:33 ` [PATCH 5/6] llvm: no need to special-case OP_AND_BOOL and OP_OR_BOOL Luc Van Oostenryck
2017-04-12 19:33 ` [PATCH 6/6] remove OP_{AND,OR}_BOOL instructions Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170412193344.95935-5-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.