From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 2/4] correctly count phi arguments
Date: Fri, 2 Apr 2021 22:25:56 +0200 [thread overview]
Message-ID: <20210402202558.54504-3-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20210402202558.54504-1-luc.vanoostenryck@gmail.com>
In a phi-node,pseudo_list_size() can't be used for counting its arguments
because VOIDs must be ignored.
Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
flow.c | 18 +++++++++++++++++-
validation/optim/phi-count00.c | 27 +++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)
create mode 100644 validation/optim/phi-count00.c
diff --git a/flow.c b/flow.c
index cb94fcf20834..58807432b3aa 100644
--- a/flow.c
+++ b/flow.c
@@ -189,6 +189,22 @@ out:
return false;
}
+///
+// count the true number of argument of a phi-node
+// VOID arguments must be ignored, so pseudo_list_size() can't be used for this.
+static int phi_count(struct instruction *node)
+{
+ pseudo_t phi;
+ int n = 0;
+
+ FOR_EACH_PTR(node->phi_list, phi) {
+ if (phi == VOID)
+ continue;
+ n++;
+ } END_FOR_EACH_PTR(phi);
+ return n;
+}
+
/*
* When we reach here, we have:
* - a basic block that ends in a conditional branch and
@@ -211,7 +227,7 @@ static int try_to_simplify_bb(struct basic_block *bb, struct instruction *first,
* simplify_symbol_usage()/conversion to SSA form.
* No sane simplification can be done when we have this.
*/
- bogus = bb_list_size(bb->parents) != pseudo_list_size(first->phi_list);
+ bogus = bb_list_size(bb->parents) != phi_count(first);
FOR_EACH_PTR(first->phi_list, phi) {
struct instruction *def = phi->def;
diff --git a/validation/optim/phi-count00.c b/validation/optim/phi-count00.c
new file mode 100644
index 000000000000..38db0edaea0e
--- /dev/null
+++ b/validation/optim/phi-count00.c
@@ -0,0 +1,27 @@
+inline int inl(int d, int e, int f)
+{
+ switch (d) {
+ case 0:
+ return e;
+ case 1:
+ return f;
+ default:
+ return 0;
+ }
+}
+
+void foo(int a, int b, int c)
+{
+ while (1) {
+ if (inl(a, b, c))
+ break;
+ }
+}
+
+/*
+ * check-name: phi-count00
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-ignore
+ * check-output-pattern(0,2): phisrc
+ */
--
2.31.1
next prev parent reply other threads:[~2021-04-02 20:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-02 20:25 [PATCH 0/4] fix 2 problems with phi-sources Luc Van Oostenryck
2021-04-02 20:25 ` [PATCH 1/4] additional testcase for remove_merging_phisrc() Luc Van Oostenryck
2021-04-02 20:25 ` Luc Van Oostenryck [this message]
2021-04-02 20:25 ` [PATCH 3/4] better check validity of phi-sources Luc Van Oostenryck
2021-04-02 20:25 ` [PATCH 4/4] fix remove_merging_phisrc() 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=20210402202558.54504-3-luc.vanoostenryck@gmail.com \
--to=luc.vanoostenryck@gmail.com \
--cc=linux-sparse@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).