-
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
Changes from 1 commit
1f963ab
6c1c962
00cf8d5
0443575
bdaceab
9566c29
1841f70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| extern void subroutine_foo(void); | ||
|
||
| extern void subroutine_bar(void); | ||
|
|
||
| void func_a(int x, int y) { | ||
| if (x == 0 || y == 0) | ||
| subroutine_foo(); | ||
| else | ||
| subroutine_bar(); | ||
| } | ||
|
|
||
| void func_b(int x, int y) { | ||
| if (x == 0) | ||
| subroutine_foo(); | ||
| else if (y == 0) | ||
| subroutine_foo(); | ||
| else | ||
| subroutine_bar(); | ||
| } | ||
|
|
||
| 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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (style) rename issue-160612.ll -> pr160612.ll (pr stands for problem report not pull request) |
||
| ; 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 | ||
| } | ||
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?