[all-commits] [llvm/llvm-project] e9c68c: [InstCombine] Match range check pattern with SExt ...

Matthias Braun via All-commits all-commits at lists.llvm.org
Mon Dec 9 16:36:37 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e9c68c6d8ceca9e61d5c385faeefacef3605e265
      https://github.com/llvm/llvm-project/commit/e9c68c6d8ceca9e61d5c385faeefacef3605e265
  Author: Matthias Braun <matze at braunis.de>
  Date:   2024-12-09 (Mon, 09 Dec 2024)

  Changed paths:
    M llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
    M llvm/test/Transforms/InstCombine/range-check.ll

  Log Message:
  -----------
  [InstCombine] Match range check pattern with SExt (#118910)

= Background

We optimize range check patterns like the following:
```
  %n_not_negative = icmp sge i32 %n, 0
  call void @llvm.assume(i1 %n_not_negative)
  %a = icmp sge i32 %x, 0
  %b = icmp slt i32 %x, %n
  %c = and i1 %a, %b
```
to a single unsigned comparison:
```
  %n_not_negative = icmp sge i32 %n, 0
  call void @llvm.assume(i1 %n_not_negative)
  %c = icmp ult i32 %x, %n
```

= Extended Pattern

This adds support for a variant of this pattern where the upper range is
compared with a sign extended value:

```
  %n_not_negative = icmp sge i64 %n, 0
  call void @llvm.assume(i1 %n_not_negative)
  %x_sext = sext i32 %x to i64
  %a = icmp sge i32 %x, 0
  %b = icmp slt i64 %x_sext, %n
  %c = and i1 %a, %b
```
is now optimized to:
```
  %n_not_negative = icmp sge i64 %n, 0
  call void @llvm.assume(i1 %n_not_negative)
  %x_sext = sext i32 %x to i64
  %c = icmp ult i64 %x_sext, %n
```

Alive2: https://alive2.llvm.org/ce/z/XVuz9L



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list