forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[InstCombine] Match range check pattern with SExt (llvm#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
- Loading branch information
Showing
2 changed files
with
144 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters