public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* How to represent a fallthrough condtion (with no else) in "Match and Simplify"?
@ 2024-06-12  6:56 Hanke Zhang
  2024-06-12  7:17 ` Richard Biener
  0 siblings, 1 reply; 2+ messages in thread
From: Hanke Zhang @ 2024-06-12  6:56 UTC (permalink / raw)
  To: GCC Development

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

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

end of thread, other threads:[~2024-06-12  7:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-12  6:56 How to represent a fallthrough condtion (with no else) in "Match and Simplify"? Hanke Zhang
2024-06-12  7:17 ` Richard Biener

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).