public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hanke Zhang <hkzhang455@gmail.com>
To: GCC Development <gcc@gcc.gnu.org>
Subject: How to represent a fallthrough condtion (with no else) in "Match and Simplify"?
Date: Wed, 12 Jun 2024 14:56:10 +0800	[thread overview]
Message-ID: <CAM_DAs9txRyeAWbAoXkehRiG6-zYmN9WbBmEBUQ5iN-c1wgfXw@mail.gmail.com> (raw)

Hi,

I'm trying to study "Match and Simplify" recently, and I had this sample code:

int main() {
  int n = 1000;
  int *a = malloc (sizeof(int) * n);
  int *b = malloc (sizeof(int) * n);
  int *c = malloc (sizeof(int) * n);
  for (int i = 0; i < n; i++) {
    if (a[i] & b[i]) {
      a[i] ^= c[i];
    }
  }
}

But this code cannot be vectorized very well. I hope it can become like this:

int main() {
  int n = 1000;
  int *a = malloc (sizeof(int) * n);
  int *b = malloc (sizeof(int) * n);
  int *c = malloc (sizeof(int) * n);
  for (int i = 0; i < n; i++) {
    int cond = ((a[i] & b[i]) == 1);
    unsigned int mask = cond ? -1 : 0;
    a[i] ^= (c[i] & mask);
  }
}


This can finally result in concise and efficient vectorized
instructions. But I want to know if this can be achieved through
"Match and Simplify"? Because when I tried to write the pattern, I
found that the condtional statement here seemed not to be matched
well, as there is not an else block.

Or is this not possible with "Match and Simplify"? Is it possible to
implement it in if-conversion?

Thanks
Hanke Zhang

             reply	other threads:[~2024-06-12  6:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-12  6:56 Hanke Zhang [this message]
2024-06-12  7:17 ` Richard Biener

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=CAM_DAs9txRyeAWbAoXkehRiG6-zYmN9WbBmEBUQ5iN-c1wgfXw@mail.gmail.com \
    --to=hkzhang455@gmail.com \
    --cc=gcc@gcc.gnu.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 read-only IMAP folder(s) and NNTP newsgroup(s).