[llvm] [SelectOpt] Refactor to prepare for support more select-like operations (PR #115745)

Igor Kirillov via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 11 09:16:59 PST 2024


igogo-x86 wrote:


I have found loops with select groups containing several regular selects and select-like instructions currently unsupported. For example - https://godbolt.org/z/77Koa3hnW

```C
void test(int *a, int *b, int *x, int *y) {
   int i = 0, j = 0;
   for (int k = 0; k < 100000000; ++k) {
     a[i] + b[j] < 0 ? i++ : j--;
   }
   *x = i;
   *y = j;
}

```

Select group would look like this:
```C
  %17 = icmp sgt i32 %16, -1, !dbg !41
  %18 = lshr i32 %16, 31, !dbg !36
  %19 = add nuw nsw i32 %18, %9, !dbg !36
  %20 = sext i1 %17 to i32, !dbg !36
  %21 = add nsw i32 %8, %20, !dbg !36
```


In this loop, for `j--` we have: 

```C
  %18 = lshr i32 %16, 31, !dbg !36
  %19 = add nuw nsw i32 %18, %9, !dbg !36
```

And for `i++`:

```C
  %20 = sext i1 %17 to i32, !dbg !36
  %21 = add nsw i32 %8, %20, !dbg !36
```

`%19` doesn't have an apparent condition, making it difficult to use the `SelectLike` structure. This patch should help add support for this type of operation, and in the follow-up patch, I will add support for SExt/Shift types of select operations



https://github.com/llvm/llvm-project/pull/115745


More information about the llvm-commits mailing list