Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AggressiveInstCombine] Missed optimization: a reversed chain of contiguous unsigned icmps could be merged #91569

Open
FLZ101 opened this issue May 9, 2024 · 1 comment

Comments

@FLZ101
Copy link
Contributor

FLZ101 commented May 9, 2024

Assuming the machine is little-endian, a reversed chain of contiguous unsigned icmps could be merged. For example,

struct Foo {
  unsigned short n;
  unsigned char o;
  unsigned char p;
};

int compare(struct Foo *f1, struct Foo *f2) {
 if (f1->p > f2->p)
   return 1;
 if (f1->p < f2->p)
   return -1;

  if (f1->o > f2->o)
    return 1;
  if (f1->o < f2->o)
    return -1;

  if (f1->n > f2->n)
    return 1;
  if (f1->n < f2->n)
    return -1;

  return 0;
}

the function compare() could be transformed as below,

int compare(struct Foo *f1, struct Foo *f2) {
  unsigned int a = *(unsigned int *)&(f1->n);
  unsigned int b = *(unsigned int *)&(f2->n);
  return a > b ? 1 : a < b ?  -1 : 0;
}

This kind of pattern is found in velvet (a de novo genome assembler), more specificly the hot function compareKmers().

@wangbyby
Copy link

Seems too high level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants