-
Notifications
You must be signed in to change notification settings - Fork 15k
[X86] logical AND and OR in if-conditionals can turn to multiple branch instructions #162041
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1f963ab
added optimization
manik-muk 6c1c962
addressed pr commments
manik-muk 00cf8d5
Merge branch 'main' into reduceBranches
manik-muk 0443575
Merge branch 'main' into reduceBranches
manik-muk bdaceab
reverted clang formatting to just my changes
manik-muk 9566c29
Merge branch 'main' into reduceBranches
manik-muk 1841f70
Merge branch 'main' into reduceBranches
RKSimon 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
| ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -O2 | FileCheck %s | ||
|
|
||
| ; Test for issue #160612: OR conditions in branches should use multiple branches | ||
| ; instead of materializing booleans with SETCC when no special optimizations apply. | ||
|
|
||
| declare void @subroutine_foo() | ||
| declare void @subroutine_bar() | ||
|
|
||
| ; Original issue: (x == 0 || y == 0) was generating SETCC + TEST + BRANCH | ||
| ; instead of using two conditional branches directly. | ||
| define void @func_a(i32 noundef %x, i32 noundef %y) { | ||
| ; CHECK-LABEL: func_a: | ||
| ; CHECK: # %bb.0: # %entry | ||
| ; CHECK-NEXT: testl %edi, %edi | ||
| ; CHECK-NEXT: je subroutine_foo@PLT # TAILCALL | ||
| ; CHECK-NEXT: # %bb.1: # %entry | ||
| ; CHECK-NEXT: testl %esi, %esi | ||
| ; CHECK-NEXT: jne subroutine_bar@PLT # TAILCALL | ||
| ; CHECK-NEXT: # %bb.2: # %if.then | ||
| ; CHECK-NEXT: jmp subroutine_foo@PLT # TAILCALL | ||
| entry: | ||
| %cmp = icmp eq i32 %x, 0 | ||
| %cmp1 = icmp eq i32 %y, 0 | ||
| %or.cond = or i1 %cmp, %cmp1 | ||
| br i1 %or.cond, label %if.then, label %if.else | ||
|
|
||
| if.then: | ||
| tail call void @subroutine_foo() | ||
| br label %if.end | ||
|
|
||
| if.else: | ||
| tail call void @subroutine_bar() | ||
| br label %if.end | ||
|
|
||
| if.end: | ||
| ret void | ||
| } | ||
|
|
||
| ; Reference implementation that already generated optimal code. | ||
| ; This should continue to generate the same optimal code. | ||
| define void @func_b(i32 noundef %x, i32 noundef %y) { | ||
| ; CHECK-LABEL: func_b: | ||
| ; CHECK: # %bb.0: # %entry | ||
| ; CHECK-NEXT: testl %edi, %edi | ||
| ; CHECK-NEXT: je subroutine_foo@PLT # TAILCALL | ||
| ; CHECK-NEXT: # %bb.1: # %if.else | ||
| ; CHECK-NEXT: testl %esi, %esi | ||
| ; CHECK-NEXT: je subroutine_foo@PLT # TAILCALL | ||
| ; CHECK-NEXT: # %bb.2: # %if.else3 | ||
| ; CHECK-NEXT: jmp subroutine_bar@PLT # TAILCALL | ||
| entry: | ||
| %cmp = icmp eq i32 %x, 0 | ||
| br i1 %cmp, label %if.then, label %if.else | ||
|
|
||
| if.then: | ||
| tail call void @subroutine_foo() | ||
| br label %if.end4 | ||
|
|
||
| if.else: | ||
| %cmp1 = icmp eq i32 %y, 0 | ||
| br i1 %cmp1, label %if.then2, label %if.else3 | ||
|
|
||
| if.then2: | ||
| tail call void @subroutine_foo() | ||
| br label %if.end4 | ||
|
|
||
| if.else3: | ||
| tail call void @subroutine_bar() | ||
| br label %if.end4 | ||
|
|
||
| if.end4: | ||
| ret void | ||
| } |
Oops, something went wrong.
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.
Can we use a match here like the previous check?