diff options
author | Matthias Braun <matze@braunis.de> | 2024-12-09 16:36:16 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-09 16:36:16 -0800 |
commit | e9c68c6d8ceca9e61d5c385faeefacef3605e265 (patch) | |
tree | 842ef483b9df8b6d2a4a63dab20293d0dd578775 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | fd57946cc4f11fe4610d3544b61041f306823f81 (diff) | |
download | llvm-e9c68c6d8ceca9e61d5c385faeefacef3605e265.zip llvm-e9c68c6d8ceca9e61d5c385faeefacef3605e265.tar.gz llvm-e9c68c6d8ceca9e61d5c385faeefacef3605e265.tar.bz2 |
[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
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
0 files changed, 0 insertions, 0 deletions