Issue 91569
Summary [AggressiveInstCombine] Missed optimization: a reversed chain of contiguous unsigned icmps could be merged
Labels new issue
Assignees
Reporter FLZ101
    Assuming the machine is little-endian, a reversed chain of contiguous unsigned icmps could be merged. For example, 

```c
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,

```c
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](https://github.com/dzerbino/velvet/tree/master) (a de novo genome assembler), more specificly the hot function `compareKmers()`.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to