summaryrefslogtreecommitdiffstats
path: root/llvm/test/CodeGen/X86/fp-une-cmp.ll
diff options
context:
space:
mode:
authorCong Hou <congh@google.com>2016-03-23 21:45:37 +0000
committerCong Hou <congh@google.com>2016-03-23 21:45:37 +0000
commit94710840fb2e1a16a75124593314b60bf13a0a3a (patch)
treea6f286a6189b458c6b7d0f8f4ee6adf5fad8c30a /llvm/test/CodeGen/X86/fp-une-cmp.ll
parent74f58d41216a330ae197d0ef74073b5f1d1aa148 (diff)
downloadbcm5719-llvm-94710840fb2e1a16a75124593314b60bf13a0a3a.tar.gz
bcm5719-llvm-94710840fb2e1a16a75124593314b60bf13a0a3a.zip
Allow X86::COND_NE_OR_P and X86::COND_NP_OR_E to be reversed.
Currently, AnalyzeBranch() fails non-equality comparison between floating points on X86 (see https://llvm.org/bugs/show_bug.cgi?id=23875). This is because this function can modify the branch by reversing the conditional jump and removing unconditional jump if there is a proper fall-through. However, in the case of non-equality comparison between floating points, this can turn the branch "unanalyzable". Consider the following case: jne.BB1 jp.BB1 jmp.BB2 .BB1: ... .BB2: ... AnalyzeBranch() will reverse "jp .BB1" to "jnp .BB2" and then "jmp .BB2" will be removed: jne.BB1 jnp.BB2 .BB1: ... .BB2: ... However, AnalyzeBranch() cannot analyze this branch anymore as there are two conditional jumps with different targets. This may disable some optimizations like block-placement: in this case the fall-through behavior is enforced even if the fall-through block is very cold, which is suboptimal. Actually this optimization is also done in block-placement pass, which means we can remove this optimization from AnalyzeBranch(). However, currently X86::COND_NE_OR_P and X86::COND_NP_OR_E are not reversible: there is no defined negation conditions for them. In order to reverse them, this patch defines two new CondCode X86::COND_E_AND_NP and X86::COND_P_AND_NE. It also defines how to synthesize instructions for them. Here only the second conditional jump is reversed. This is valid as we only need them to do this "unconditional jump removal" optimization. Differential Revision: http://reviews.llvm.org/D11393 llvm-svn: 264199
Diffstat (limited to 'llvm/test/CodeGen/X86/fp-une-cmp.ll')
-rw-r--r--llvm/test/CodeGen/X86/fp-une-cmp.ll38
1 files changed, 32 insertions, 6 deletions
diff --git a/llvm/test/CodeGen/X86/fp-une-cmp.ll b/llvm/test/CodeGen/X86/fp-une-cmp.ll
index 9fab5c4dc83..179fffca379 100644
--- a/llvm/test/CodeGen/X86/fp-une-cmp.ll
+++ b/llvm/test/CodeGen/X86/fp-une-cmp.ll
@@ -48,8 +48,6 @@ bb2:
ret double %phi
}
-; FIXME: With branch weights indicated, bb2 should be placed ahead of bb1.
-
define double @profile_metadata(double %x, double %y) {
; CHECK-LABEL: profile_metadata:
; CHECK: # BB#0: # %entry
@@ -57,11 +55,12 @@ define double @profile_metadata(double %x, double %y) {
; CHECK-NEXT: xorpd %xmm1, %xmm1
; CHECK-NEXT: ucomisd %xmm1, %xmm0
; CHECK-NEXT: jne .LBB1_1
-; CHECK-NEXT: jnp .LBB1_2
-; CHECK-NEXT: .LBB1_1: # %bb1
-; CHECK-NEXT: addsd {{.*}}(%rip), %xmm0
+; CHECK-NEXT: jp .LBB1_1
; CHECK-NEXT: .LBB1_2: # %bb2
; CHECK-NEXT: retq
+; CHECK-NEXT: .LBB1_1: # %bb1
+; CHECK-NEXT: addsd {{.*}}(%rip), %xmm0
+; CHECK-NEXT: jmp .LBB1_2
entry:
%mul = fmul double %x, %y
@@ -77,5 +76,32 @@ bb2:
ret double %phi
}
-!1 = !{!"branch_weights", i32 1, i32 1000}
+; Test if the negation of the non-equality check between floating points are
+; translated to jnp followed by jne.
+define void @foo(float %f) {
+; CHECK-LABEL: foo:
+; CHECK: # BB#0: # %entry
+; CHECK-NEXT: xorps %xmm1, %xmm1
+; CHECK-NEXT: ucomiss %xmm1, %xmm0
+; CHECK-NEXT: jne .LBB2_2
+; CHECK-NEXT: jnp .LBB2_1
+; CHECK-NEXT: .LBB2_2: # %if.then
+; CHECK-NEXT: jmp a # TAILCALL
+; CHECK-NEXT: .LBB2_1: # %if.end
+; CHECK-NEXT: retq
+entry:
+ %cmp = fcmp une float %f, 0.000000e+00
+ br i1 %cmp, label %if.then, label %if.end
+
+if.then:
+ tail call void @a()
+ br label %if.end
+
+if.end:
+ ret void
+}
+
+declare void @a()
+
+!1 = !{!"branch_weights", i32 1, i32 1000}
OpenPOWER on IntegriCloud