-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[InstCombine] Simplify (add/sub (sub/add) (sub/add))
irrelevant of use-count
#105866
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b417163
[InstCombine] Add tests for reassosiating `(add/sub (sub/add) (sub/ad…
goldsteinn 73f0712
[InstCombine] Simplify `(add/sub (sub/add) (sub/add))` irrelivant of …
goldsteinn d16b8d4
Correctly guard foldAddLike for or
goldsteinn f058c17
Fixups
goldsteinn 6d62821
Make API commutatable
goldsteinn 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
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
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
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
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,207 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py | ||
; RUN: opt < %s -passes=instcombine -S | FileCheck %s | ||
|
||
declare void @use.i8(i8) | ||
define i8 @test_add_nsw(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_add_nsw( | ||
; CHECK-NEXT: [[LHS:%.*]] = add nsw i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = add nsw i8 [[X]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub nsw i8 [[Y]], [[Z]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = add nsw i8 %x, %y | ||
%rhs = add nsw i8 %x, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = sub nsw i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_add_nsw_no_prop(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_add_nsw_no_prop( | ||
; CHECK-NEXT: [[LHS:%.*]] = add nsw i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = add nuw i8 [[X]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[Y]], [[Z]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = add nsw i8 %x, %y | ||
%rhs = add nuw i8 %x, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = sub nsw i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_add(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_add( | ||
; CHECK-NEXT: [[LHS:%.*]] = add i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = add i8 [[X]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[Y]], [[Z]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = add i8 %x, %y | ||
%rhs = add i8 %x, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = sub i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_add_fail(i8 %w, i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_add_fail( | ||
; CHECK-NEXT: [[LHS:%.*]] = add i8 [[W:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = add i8 [[X:%.*]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[LHS]], [[RHS]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = add i8 %w, %y | ||
%rhs = add i8 %x, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = sub i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_add_nuw(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_add_nuw( | ||
; CHECK-NEXT: [[LHS:%.*]] = add i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = or disjoint i8 [[X]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub nuw i8 [[Y]], [[Z]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = add i8 %x, %y | ||
%rhs = or disjoint i8 %x, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = sub nuw i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_add_nuw_no_prop(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_add_nuw_no_prop( | ||
; CHECK-NEXT: [[LHS:%.*]] = add i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = or disjoint i8 [[X]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[Y]], [[Z]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = add i8 %x, %y | ||
%rhs = or disjoint i8 %x, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = sub i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_sub_nuw(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_sub_nuw( | ||
; CHECK-NEXT: [[LHS:%.*]] = sub nuw i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = sub nuw i8 [[Y]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub nuw i8 [[X]], [[Z]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = sub nuw i8 %x, %y | ||
%rhs = sub nuw i8 %y, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = add i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_sub_nuw_no_prop(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_sub_nuw_no_prop( | ||
; CHECK-NEXT: [[LHS:%.*]] = sub nuw i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = sub i8 [[Y]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[X]], [[Z]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = sub nuw i8 %x, %y | ||
%rhs = sub i8 %y, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = add nuw i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_sub_nsw(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_sub_nsw( | ||
; CHECK-NEXT: [[LHS:%.*]] = sub nsw i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = sub nsw i8 [[Y]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub nsw i8 [[X]], [[Z]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = sub nsw i8 %x, %y | ||
%rhs = sub nsw i8 %y, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = or disjoint i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_sub_nsw_no_prop(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_sub_nsw_no_prop( | ||
; CHECK-NEXT: [[LHS:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = sub nsw i8 [[Y]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[X]], [[Z]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = sub i8 %x, %y | ||
%rhs = sub nsw i8 %y, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = or disjoint i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_sub_none(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_sub_none( | ||
; CHECK-NEXT: [[LHS:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = sub i8 [[Y]], [[Z:%.*]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = sub i8 [[X]], [[Z]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = sub i8 %x, %y | ||
%rhs = sub i8 %y, %z | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = add i8 %lhs, %rhs | ||
ret i8 %r | ||
} | ||
|
||
define i8 @test_sub_none_fail(i8 %x, i8 %y, i8 %z) { | ||
; CHECK-LABEL: @test_sub_none_fail( | ||
; CHECK-NEXT: [[LHS:%.*]] = sub i8 [[X:%.*]], [[Y:%.*]] | ||
; CHECK-NEXT: [[RHS:%.*]] = sub i8 [[Z:%.*]], [[Y]] | ||
; CHECK-NEXT: call void @use.i8(i8 [[LHS]]) | ||
; CHECK-NEXT: call void @use.i8(i8 [[RHS]]) | ||
; CHECK-NEXT: [[R:%.*]] = add i8 [[LHS]], [[RHS]] | ||
; CHECK-NEXT: ret i8 [[R]] | ||
; | ||
%lhs = sub i8 %x, %y | ||
%rhs = sub i8 %z, %y | ||
call void @use.i8(i8 %lhs) | ||
call void @use.i8(i8 %rhs) | ||
%r = add i8 %lhs, %rhs | ||
ret i8 %r | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this into InstCombineAddSub.cpp. It will make it easier to move folds if necessary.