-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[InstCombine] Optimize and of overflow checks #141962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bobby-b-song
wants to merge
8
commits into
llvm:main
Choose a base branch
from
bobby-b-song:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7d6888e
Add test case for issue 141479
bobby-b-song b11691e
Added missed optimization: need optimization for further adaption
bobby-b-song 054f5bd
Merge branch 'main' into main
bobby-b-song 8f18ff0
Merge branch 'llvm:main' into main
bobby-b-song 821f62d
Update llvm/lib/Analysis/InstructionSimplify.cpp
bobby-b-song 1c6aab2
Change predicate match to expect same sign state
bobby-b-song 893bbf8
Fix formatting
bobby-b-song ba53431
Merge branch 'main' into main
bobby-b-song File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
138 changes: 138 additions & 0 deletions
138
llvm/test/Transforms/InstCombine/and-comparison-not-always-false.ll
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5 | ||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
define i1 @test_pass_et(i32 %0, i32 %1) { | ||
; CHECK-LABEL: define i1 @test_pass_et( | ||
; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) { | ||
; CHECK-NEXT: [[COMMON_RET:.*:]] | ||
; CHECK-NEXT: ret i1 false | ||
; | ||
common.ret: | ||
%2 = xor i32 %0, -1 | ||
%3 = icmp ule i32 %1, %2 | ||
%4 = xor i32 %1, -1 | ||
%5 = icmp ugt i32 %0, %4 | ||
%common.ret.op = and i1 %3, %5 | ||
ret i1 %common.ret.op | ||
} | ||
|
||
define i1 @test_pass_signed(i32 %0, i32 %1) { | ||
; CHECK-LABEL: define i1 @test_pass_signed( | ||
; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) { | ||
; CHECK-NEXT: [[COMMON_RET:.*:]] | ||
; CHECK-NEXT: ret i1 false | ||
; | ||
common.ret: | ||
%2 = xor i32 %0, -1 | ||
%3 = icmp sle i32 %1, %2 | ||
%4 = xor i32 %1, -1 | ||
%5 = icmp sgt i32 %0, %4 | ||
%common.ret.op = and i1 %3, %5 | ||
ret i1 %common.ret.op | ||
} | ||
|
||
define i1 @test_pass_tt(i32 %0, i32 %1) { | ||
; CHECK-LABEL: define i1 @test_pass_tt( | ||
; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) { | ||
; CHECK-NEXT: [[COMMON_RET:.*:]] | ||
; CHECK-NEXT: ret i1 false | ||
; | ||
common.ret: | ||
%2 = xor i32 %0, -1 | ||
%3 = icmp ult i32 %1, %2 | ||
%4 = xor i32 %1, -1 | ||
%5 = icmp ugt i32 %0, %4 | ||
%common.ret.op = and i1 %3, %5 | ||
ret i1 %common.ret.op | ||
} | ||
|
||
define i1 @test_pass_te(i32 %0, i32 %1) { | ||
; CHECK-LABEL: define i1 @test_pass_te( | ||
; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) { | ||
; CHECK-NEXT: [[COMMON_RET:.*:]] | ||
; CHECK-NEXT: ret i1 false | ||
; | ||
common.ret: | ||
%2 = xor i32 %0, -1 | ||
%3 = icmp ult i32 %1, %2 | ||
%4 = xor i32 %1, -1 | ||
%5 = icmp uge i32 %0, %4 | ||
%common.ret.op = and i1 %3, %5 | ||
ret i1 %common.ret.op | ||
} | ||
|
||
define i1 @test_nopass_ee(i32 %0, i32 %1) { | ||
; CHECK-LABEL: define i1 @test_nopass_ee( | ||
; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]]) { | ||
; CHECK-NEXT: [[COMMON_RET:.*:]] | ||
; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP0]], -1 | ||
; CHECK-NEXT: [[TMP3:%.*]] = icmp ule i32 [[TMP1]], [[TMP2]] | ||
; CHECK-NEXT: [[TMP4:%.*]] = xor i32 [[TMP1]], -1 | ||
; CHECK-NEXT: [[TMP5:%.*]] = icmp uge i32 [[TMP0]], [[TMP4]] | ||
; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = and i1 [[TMP3]], [[TMP5]] | ||
; CHECK-NEXT: ret i1 [[COMMON_RET_OP]] | ||
; | ||
common.ret: | ||
%2 = xor i32 %0, -1 | ||
%3 = icmp ule i32 %1, %2 | ||
%4 = xor i32 %1, -1 | ||
%5 = icmp uge i32 %0, %4 | ||
%common.ret.op = and i1 %3, %5 | ||
ret i1 %common.ret.op | ||
} | ||
|
||
define i1 @test_no_change_et(i32 %0, i32 %1, i32 %2) { | ||
; CHECK-LABEL: define i1 @test_no_change_et( | ||
; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]]) { | ||
; CHECK-NEXT: [[COMMON_RET:.*:]] | ||
; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[TMP0]], -1 | ||
; CHECK-NEXT: [[TMP4:%.*]] = icmp ule i32 [[TMP1]], [[TMP3]] | ||
; CHECK-NEXT: [[TMP5:%.*]] = icmp slt i32 [[TMP1]], 0 | ||
; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = and i1 [[TMP5]], [[TMP4]] | ||
; CHECK-NEXT: ret i1 [[COMMON_RET_OP]] | ||
; | ||
common.ret: | ||
%3 = xor i32 %0, -1 | ||
%4 = icmp ule i32 %1, %3 | ||
%5 = xor i32 %1, -1 | ||
%6 = icmp ugt i32 %1, %5 | ||
%common.ret.op = and i1 %6, %4 | ||
ret i1 %common.ret.op | ||
} | ||
|
||
define i1 @test_no_change_te(i32 %0, i32 %1, i32 %2) { | ||
; CHECK-LABEL: define i1 @test_no_change_te( | ||
; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]]) { | ||
; CHECK-NEXT: [[COMMON_RET:.*:]] | ||
; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[TMP0]], -1 | ||
; CHECK-NEXT: [[TMP4:%.*]] = icmp ult i32 [[TMP1]], [[TMP3]] | ||
; CHECK-NEXT: [[TMP5:%.*]] = icmp slt i32 [[TMP1]], 0 | ||
; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = and i1 [[TMP5]], [[TMP4]] | ||
; CHECK-NEXT: ret i1 [[COMMON_RET_OP]] | ||
; | ||
common.ret: | ||
%3 = xor i32 %0, -1 | ||
%4 = icmp ult i32 %1, %3 | ||
%5 = xor i32 %1, -1 | ||
%6 = icmp uge i32 %1, %5 | ||
%common.ret.op = and i1 %6, %4 | ||
ret i1 %common.ret.op | ||
} | ||
|
||
define i1 @test_no_change_tt(i32 %0, i32 %1, i32 %2) { | ||
; CHECK-LABEL: define i1 @test_no_change_tt( | ||
; CHECK-SAME: i32 [[TMP0:%.*]], i32 [[TMP1:%.*]], i32 [[TMP2:%.*]]) { | ||
; CHECK-NEXT: [[COMMON_RET:.*:]] | ||
; CHECK-NEXT: [[TMP3:%.*]] = xor i32 [[TMP0]], -1 | ||
; CHECK-NEXT: [[TMP4:%.*]] = icmp ult i32 [[TMP1]], [[TMP3]] | ||
; CHECK-NEXT: [[TMP5:%.*]] = icmp slt i32 [[TMP1]], 0 | ||
; CHECK-NEXT: [[COMMON_RET_OP:%.*]] = and i1 [[TMP5]], [[TMP4]] | ||
; CHECK-NEXT: ret i1 [[COMMON_RET_OP]] | ||
; | ||
common.ret: | ||
%3 = xor i32 %0, -1 | ||
%4 = icmp ult i32 %1, %3 | ||
%5 = xor i32 %1, -1 | ||
%6 = icmp ugt i32 %1, %5 | ||
%common.ret.op = and i1 %6, %4 | ||
ret i1 %common.ret.op | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.