diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2013-08-04 12:05:16 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2013-08-04 12:05:16 +0000 |
commit | 75311b7b4dbb284e7539c0c62331387f3c4cd1ec (patch) | |
tree | d44a1ce6a1fcb67f4cb4286ffd5e2ecbde8a2fa9 /test | |
parent | f3e3417e652420a2880fe1efa98ff11936f082e1 (diff) | |
download | external_llvm-75311b7b4dbb284e7539c0c62331387f3c4cd1ec.zip external_llvm-75311b7b4dbb284e7539c0c62331387f3c4cd1ec.tar.gz external_llvm-75311b7b4dbb284e7539c0c62331387f3c4cd1ec.tar.bz2 |
X86: Turn fp selects into mask operations.
double test(double a, double b, double c, double d) { return a<b ? c : d; }
before:
_test:
ucomisd %xmm0, %xmm1
ja LBB0_2
movaps %xmm3, %xmm2
LBB0_2:
movaps %xmm2, %xmm0
after:
_test:
cmpltsd %xmm1, %xmm0
andpd %xmm0, %xmm2
andnpd %xmm3, %xmm0
orpd %xmm2, %xmm0
Small speedup on Benchmarks/SmallPT
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@187706 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/CodeGen/X86/compare-inf.ll | 98 | ||||
-rw-r--r-- | test/CodeGen/X86/fp-select-cmp-and.ll | 185 | ||||
-rw-r--r-- | test/CodeGen/X86/sse-minmax.ll | 55 |
3 files changed, 290 insertions, 48 deletions
diff --git a/test/CodeGen/X86/compare-inf.ll b/test/CodeGen/X86/compare-inf.ll index d592fc1..5eb0135 100644 --- a/test/CodeGen/X86/compare-inf.ll +++ b/test/CodeGen/X86/compare-inf.ll @@ -3,74 +3,124 @@ ; Convert oeq and une to ole/oge/ule/uge when comparing with infinity ; and negative infinity, because those are more efficient on x86. +declare void @f() nounwind + ; CHECK-LABEL: oeq_inff: ; CHECK: ucomiss ; CHECK: jb -define float @oeq_inff(float %x, float %y) nounwind readonly { +define void @oeq_inff(float %x) nounwind { %t0 = fcmp oeq float %x, 0x7FF0000000000000 - %t1 = select i1 %t0, float 1.0, float %y - ret float %t1 + br i1 %t0, label %true, label %false + +true: + call void @f() nounwind + br label %false + +false: + ret void } ; CHECK-LABEL: oeq_inf: ; CHECK: ucomisd ; CHECK: jb -define double @oeq_inf(double %x, double %y) nounwind readonly { +define void @oeq_inf(double %x) nounwind { %t0 = fcmp oeq double %x, 0x7FF0000000000000 - %t1 = select i1 %t0, double 1.0, double %y - ret double %t1 + br i1 %t0, label %true, label %false + +true: + call void @f() nounwind + br label %false + +false: + ret void } ; CHECK-LABEL: une_inff: ; CHECK: ucomiss ; CHECK: jae -define float @une_inff(float %x, float %y) nounwind readonly { +define void @une_inff(float %x) nounwind { %t0 = fcmp une float %x, 0x7FF0000000000000 - %t1 = select i1 %t0, float 1.0, float %y - ret float %t1 + br i1 %t0, label %true, label %false + +true: + call void @f() nounwind + br label %false + +false: + ret void } ; CHECK-LABEL: une_inf: ; CHECK: ucomisd ; CHECK: jae -define double @une_inf(double %x, double %y) nounwind readonly { +define void @une_inf(double %x) nounwind { %t0 = fcmp une double %x, 0x7FF0000000000000 - %t1 = select i1 %t0, double 1.0, double %y - ret double %t1 + br i1 %t0, label %true, label %false + +true: + call void @f() nounwind + br label %false + +false: + ret void } ; CHECK-LABEL: oeq_neg_inff: ; CHECK: ucomiss ; CHECK: jb -define float @oeq_neg_inff(float %x, float %y) nounwind readonly { +define void @oeq_neg_inff(float %x) nounwind { %t0 = fcmp oeq float %x, 0xFFF0000000000000 - %t1 = select i1 %t0, float 1.0, float %y - ret float %t1 + br i1 %t0, label %true, label %false + +true: + call void @f() nounwind + br label %false + +false: + ret void } ; CHECK-LABEL: oeq_neg_inf: ; CHECK: ucomisd ; CHECK: jb -define double @oeq_neg_inf(double %x, double %y) nounwind readonly { +define void @oeq_neg_inf(double %x) nounwind { %t0 = fcmp oeq double %x, 0xFFF0000000000000 - %t1 = select i1 %t0, double 1.0, double %y - ret double %t1 + br i1 %t0, label %true, label %false + +true: + call void @f() nounwind + br label %false + +false: + ret void } ; CHECK-LABEL: une_neg_inff: ; CHECK: ucomiss ; CHECK: jae -define float @une_neg_inff(float %x, float %y) nounwind readonly { +define void @une_neg_inff(float %x) nounwind { %t0 = fcmp une float %x, 0xFFF0000000000000 - %t1 = select i1 %t0, float 1.0, float %y - ret float %t1 + br i1 %t0, label %true, label %false + +true: + call void @f() nounwind + br label %false + +false: + ret void } ; CHECK-LABEL: une_neg_inf: ; CHECK: ucomisd ; CHECK: jae -define double @une_neg_inf(double %x, double %y) nounwind readonly { +define void @une_neg_inf(double %x) nounwind { %t0 = fcmp une double %x, 0xFFF0000000000000 - %t1 = select i1 %t0, double 1.0, double %y - ret double %t1 + br i1 %t0, label %true, label %false + +true: + call void @f() nounwind + br label %false + +false: + ret void } diff --git a/test/CodeGen/X86/fp-select-cmp-and.ll b/test/CodeGen/X86/fp-select-cmp-and.ll new file mode 100644 index 0000000..cc76b43 --- /dev/null +++ b/test/CodeGen/X86/fp-select-cmp-and.ll @@ -0,0 +1,185 @@ +; RUN: llc < %s -march=x86-64 -mtriple=x86_64-apple-darwin -mcpu=nehalem | FileCheck %s + +define double @test1(double %a, double %b, double %eps) { + %cmp = fcmp olt double %a, %eps + %cond = select i1 %cmp, double %b, double 0.000000e+00 + ret double %cond + +; CHECK-LABEL: @test1 +; CHECK: cmpltsd %xmm2, %xmm0 +; CHECK-NEXT: andpd %xmm1, %xmm0 +} + +define double @test2(double %a, double %b, double %eps) { + %cmp = fcmp ole double %a, %eps + %cond = select i1 %cmp, double %b, double 0.000000e+00 + ret double %cond + +; CHECK-LABEL: @test2 +; CHECK: cmplesd %xmm2, %xmm0 +; CHECK-NEXT: andpd %xmm1, %xmm0 +} + +define double @test3(double %a, double %b, double %eps) { + %cmp = fcmp ogt double %a, %eps + %cond = select i1 %cmp, double %b, double 0.000000e+00 + ret double %cond + +; CHECK-LABEL: @test3 +; CHECK: cmpltsd %xmm0, %xmm2 +; CHECK-NEXT: andpd %xmm1, %xmm2 +} + +define double @test4(double %a, double %b, double %eps) { + %cmp = fcmp oge double %a, %eps + %cond = select i1 %cmp, double %b, double 0.000000e+00 + ret double %cond + +; CHECK-LABEL: @test4 +; CHECK: cmplesd %xmm0, %xmm2 +; CHECK-NEXT: andpd %xmm1, %xmm2 +} + +define double @test5(double %a, double %b, double %eps) { + %cmp = fcmp olt double %a, %eps + %cond = select i1 %cmp, double 0.000000e+00, double %b + ret double %cond + +; CHECK-LABEL: @test5 +; CHECK: cmpltsd %xmm2, %xmm0 +; CHECK-NEXT: andnpd %xmm1, %xmm0 +} + +define double @test6(double %a, double %b, double %eps) { + %cmp = fcmp ole double %a, %eps + %cond = select i1 %cmp, double 0.000000e+00, double %b + ret double %cond + +; CHECK-LABEL: @test6 +; CHECK: cmplesd %xmm2, %xmm0 +; CHECK-NEXT: andnpd %xmm1, %xmm0 +} + +define double @test7(double %a, double %b, double %eps) { + %cmp = fcmp ogt double %a, %eps + %cond = select i1 %cmp, double 0.000000e+00, double %b + ret double %cond + +; CHECK-LABEL: @test7 +; CHECK: cmpltsd %xmm0, %xmm2 +; CHECK-NEXT: andnpd %xmm1, %xmm2 +} + +define double @test8(double %a, double %b, double %eps) { + %cmp = fcmp oge double %a, %eps + %cond = select i1 %cmp, double 0.000000e+00, double %b + ret double %cond + +; CHECK-LABEL: @test8 +; CHECK: cmplesd %xmm0, %xmm2 +; CHECK-NEXT: andnpd %xmm1, %xmm2 +} + +define float @test9(float %a, float %b, float %eps) { + %cmp = fcmp olt float %a, %eps + %cond = select i1 %cmp, float %b, float 0.000000e+00 + ret float %cond + +; CHECK-LABEL: @test9 +; CHECK: cmpltss %xmm2, %xmm0 +; CHECK-NEXT: andps %xmm1, %xmm0 +} + +define float @test10(float %a, float %b, float %eps) { + %cmp = fcmp ole float %a, %eps + %cond = select i1 %cmp, float %b, float 0.000000e+00 + ret float %cond + +; CHECK-LABEL: @test10 +; CHECK: cmpless %xmm2, %xmm0 +; CHECK-NEXT: andps %xmm1, %xmm0 +} + +define float @test11(float %a, float %b, float %eps) { + %cmp = fcmp ogt float %a, %eps + %cond = select i1 %cmp, float %b, float 0.000000e+00 + ret float %cond + +; CHECK-LABEL: @test11 +; CHECK: cmpltss %xmm0, %xmm2 +; CHECK-NEXT: andps %xmm1, %xmm2 +} + +define float @test12(float %a, float %b, float %eps) { + %cmp = fcmp oge float %a, %eps + %cond = select i1 %cmp, float %b, float 0.000000e+00 + ret float %cond + +; CHECK-LABEL: @test12 +; CHECK: cmpless %xmm0, %xmm2 +; CHECK-NEXT: andps %xmm1, %xmm2 +} + +define float @test13(float %a, float %b, float %eps) { + %cmp = fcmp olt float %a, %eps + %cond = select i1 %cmp, float 0.000000e+00, float %b + ret float %cond + +; CHECK-LABEL: @test13 +; CHECK: cmpltss %xmm2, %xmm0 +; CHECK-NEXT: andnps %xmm1, %xmm0 +} + +define float @test14(float %a, float %b, float %eps) { + %cmp = fcmp ole float %a, %eps + %cond = select i1 %cmp, float 0.000000e+00, float %b + ret float %cond + +; CHECK-LABEL: @test14 +; CHECK: cmpless %xmm2, %xmm0 +; CHECK-NEXT: andnps %xmm1, %xmm0 +} + +define float @test15(float %a, float %b, float %eps) { + %cmp = fcmp ogt float %a, %eps + %cond = select i1 %cmp, float 0.000000e+00, float %b + ret float %cond + +; CHECK-LABEL: @test15 +; CHECK: cmpltss %xmm0, %xmm2 +; CHECK-NEXT: andnps %xmm1, %xmm2 +} + +define float @test16(float %a, float %b, float %eps) { + %cmp = fcmp oge float %a, %eps + %cond = select i1 %cmp, float 0.000000e+00, float %b + ret float %cond + +; CHECK-LABEL: @test16 +; CHECK: cmpless %xmm0, %xmm2 +; CHECK-NEXT: andnps %xmm1, %xmm2 +} + +define float @test17(float %a, float %b, float %c, float %eps) { + %cmp = fcmp oge float %a, %eps + %cond = select i1 %cmp, float %c, float %b + ret float %cond + +; CHECK-LABEL: @test17 +; CHECK: cmpless %xmm0, %xmm3 +; CHECK-NEXT: andps %xmm3, %xmm2 +; CHECK-NEXT: andnps %xmm1, %xmm3 +; CHECK-NEXT: orps %xmm2, %xmm3 +} + +define double @test18(double %a, double %b, double %c, double %eps) { + %cmp = fcmp oge double %a, %eps + %cond = select i1 %cmp, double %c, double %b + ret double %cond + +; CHECK-LABEL: @test18 +; CHECK: cmplesd %xmm0, %xmm3 +; CHECK-NEXT: andpd %xmm3, %xmm2 +; CHECK-NEXT: andnpd %xmm1, %xmm3 +; CHECK-NEXT: orpd %xmm2, %xmm3 +} diff --git a/test/CodeGen/X86/sse-minmax.ll b/test/CodeGen/X86/sse-minmax.ll index 5fa0ca3..5122c44 100644 --- a/test/CodeGen/X86/sse-minmax.ll +++ b/test/CodeGen/X86/sse-minmax.ll @@ -77,7 +77,7 @@ define double @olt_inverse(double %x, double %y) nounwind { } ; CHECK-LABEL: oge: -; CHECK-NEXT: ucomisd %xmm1, %xmm0 +; CHECK: cmplesd %xmm0 ; UNSAFE-LABEL: oge: ; UNSAFE-NEXT: maxsd %xmm1, %xmm0 ; UNSAFE-NEXT: ret @@ -91,7 +91,7 @@ define double @oge(double %x, double %y) nounwind { } ; CHECK-LABEL: ole: -; CHECK-NEXT: ucomisd %xmm0, %xmm1 +; CHECK: cmplesd %xmm1 ; UNSAFE-LABEL: ole: ; UNSAFE-NEXT: minsd %xmm1, %xmm0 ; FINITE-LABEL: ole: @@ -103,7 +103,7 @@ define double @ole(double %x, double %y) nounwind { } ; CHECK-LABEL: oge_inverse: -; CHECK-NEXT: ucomisd %xmm1, %xmm0 +; CHECK: cmplesd %xmm0 ; UNSAFE-LABEL: oge_inverse: ; UNSAFE-NEXT: minsd %xmm1, %xmm0 ; UNSAFE-NEXT: ret @@ -118,7 +118,7 @@ define double @oge_inverse(double %x, double %y) nounwind { } ; CHECK-LABEL: ole_inverse: -; CHECK-NEXT: ucomisd %xmm0, %xmm1 +; CHECK: cmplesd %xmm1 ; UNSAFE-LABEL: ole_inverse: ; UNSAFE-NEXT: maxsd %xmm1, %xmm0 ; UNSAFE-NEXT: ret @@ -213,7 +213,8 @@ define double @olt_inverse_x(double %x) nounwind { } ; CHECK-LABEL: oge_x: -; CHECK: ucomisd %xmm1, %xmm0 +; CHECK: cmplesd %xmm +; CHECK-NEXT: andpd ; UNSAFE-LABEL: oge_x: ; UNSAFE-NEXT: xorp{{[sd]}} %xmm1, %xmm1 ; UNSAFE-NEXT: maxsd %xmm0, %xmm1 @@ -230,7 +231,8 @@ define double @oge_x(double %x) nounwind { } ; CHECK-LABEL: ole_x: -; CHECK: ucomisd %xmm0, %xmm1 +; CHECK: cmplesd %xmm +; CHECK-NEXT: andpd ; UNSAFE-LABEL: ole_x: ; UNSAFE-NEXT: xorp{{[sd]}} %xmm1, %xmm1 ; UNSAFE-NEXT: minsd %xmm0, %xmm1 @@ -247,7 +249,8 @@ define double @ole_x(double %x) nounwind { } ; CHECK-LABEL: oge_inverse_x: -; CHECK: ucomisd %xmm +; CHECK: cmplesd %xmm +; CHECK-NEXT: andnpd ; UNSAFE-LABEL: oge_inverse_x: ; UNSAFE-NEXT: xorp{{[sd]}} %xmm1, %xmm1 ; UNSAFE-NEXT: minsd %xmm0, %xmm1 @@ -265,7 +268,7 @@ define double @oge_inverse_x(double %x) nounwind { } ; CHECK-LABEL: ole_inverse_x: -; CHECK: ucomisd %xmm +; CHECK: cmplesd %xmm ; UNSAFE-LABEL: ole_inverse_x: ; UNSAFE-NEXT: xorp{{[sd]}} %xmm1, %xmm1 ; UNSAFE-NEXT: maxsd %xmm0, %xmm1 @@ -283,7 +286,7 @@ define double @ole_inverse_x(double %x) nounwind { } ; CHECK-LABEL: ugt: -; CHECK: ucomisd %xmm0, %xmm1 +; CHECK: cmpnlesd %xmm1 ; UNSAFE-LABEL: ugt: ; UNSAFE-NEXT: maxsd %xmm1, %xmm0 ; UNSAFE-NEXT: ret @@ -297,7 +300,7 @@ define double @ugt(double %x, double %y) nounwind { } ; CHECK-LABEL: ult: -; CHECK: ucomisd %xmm1, %xmm0 +; CHECK: cmpnlesd %xmm0 ; UNSAFE-LABEL: ult: ; UNSAFE-NEXT: minsd %xmm1, %xmm0 ; UNSAFE-NEXT: ret @@ -311,7 +314,7 @@ define double @ult(double %x, double %y) nounwind { } ; CHECK-LABEL: ugt_inverse: -; CHECK: ucomisd %xmm0, %xmm1 +; CHECK: cmpnlesd %xmm1 ; UNSAFE-LABEL: ugt_inverse: ; UNSAFE-NEXT: minsd %xmm1, %xmm0 ; UNSAFE-NEXT: ret @@ -326,7 +329,7 @@ define double @ugt_inverse(double %x, double %y) nounwind { } ; CHECK-LABEL: ult_inverse: -; CHECK: ucomisd %xmm1, %xmm0 +; CHECK: cmpnlesd %xmm0 ; UNSAFE-LABEL: ult_inverse: ; UNSAFE-NEXT: maxsd %xmm1, %xmm0 ; UNSAFE-NEXT: ret @@ -405,7 +408,8 @@ define double @ule_inverse(double %x, double %y) nounwind { } ; CHECK-LABEL: ugt_x: -; CHECK: ucomisd %xmm0, %xmm1 +; CHECK: cmpnlesd %xmm +; CHECK-NEXT: andpd ; UNSAFE-LABEL: ugt_x: ; UNSAFE-NEXT: xorp{{[sd]}} %xmm1, %xmm1 ; UNSAFE-NEXT: maxsd %xmm0, %xmm1 @@ -422,7 +426,8 @@ define double @ugt_x(double %x) nounwind { } ; CHECK-LABEL: ult_x: -; CHECK: ucomisd %xmm1, %xmm0 +; CHECK: cmpnlesd %xmm +; CHECK-NEXT: andpd ; UNSAFE-LABEL: ult_x: ; UNSAFE-NEXT: xorp{{[sd]}} %xmm1, %xmm1 ; UNSAFE-NEXT: minsd %xmm0, %xmm1 @@ -439,7 +444,8 @@ define double @ult_x(double %x) nounwind { } ; CHECK-LABEL: ugt_inverse_x: -; CHECK: ucomisd %xmm +; CHECK: cmpnlesd %xmm +; CHECK-NEXT: andnpd ; UNSAFE-LABEL: ugt_inverse_x: ; UNSAFE-NEXT: xorp{{[sd]}} %xmm1, %xmm1 ; UNSAFE-NEXT: minsd %xmm0, %xmm1 @@ -457,7 +463,8 @@ define double @ugt_inverse_x(double %x) nounwind { } ; CHECK-LABEL: ult_inverse_x: -; CHECK: ucomisd %xmm +; CHECK: cmpnlesd %xmm +; CHECK-NEXT: andnpd ; UNSAFE-LABEL: ult_inverse_x: ; UNSAFE-NEXT: xorp{{[sd]}} %xmm1, %xmm1 ; UNSAFE-NEXT: maxsd %xmm0, %xmm1 @@ -623,7 +630,7 @@ define double @olt_inverse_y(double %x) nounwind { } ; CHECK-LABEL: oge_y: -; CHECK: ucomisd %xmm1, %xmm0 +; CHECK: cmplesd %xmm0 ; UNSAFE-LABEL: oge_y: ; UNSAFE-NEXT: maxsd {{[^,]*}}, %xmm0 ; UNSAFE-NEXT: ret @@ -637,7 +644,7 @@ define double @oge_y(double %x) nounwind { } ; CHECK-LABEL: ole_y: -; CHECK: ucomisd %xmm0, %xmm1 +; CHECK: cmplesd %xmm ; UNSAFE-LABEL: ole_y: ; UNSAFE-NEXT: minsd {{[^,]*}}, %xmm0 ; UNSAFE-NEXT: ret @@ -651,7 +658,7 @@ define double @ole_y(double %x) nounwind { } ; CHECK-LABEL: oge_inverse_y: -; CHECK: ucomisd %xmm +; CHECK: cmplesd %xmm0 ; UNSAFE-LABEL: oge_inverse_y: ; UNSAFE-NEXT: minsd {{[^,]*}}, %xmm0 ; UNSAFE-NEXT: ret @@ -667,7 +674,7 @@ define double @oge_inverse_y(double %x) nounwind { } ; CHECK-LABEL: ole_inverse_y: -; CHECK: ucomisd %xmm +; CHECK: cmplesd %xmm ; UNSAFE-LABEL: ole_inverse_y: ; UNSAFE-NEXT: maxsd {{[^,]*}}, %xmm0 ; UNSAFE-NEXT: ret @@ -683,7 +690,7 @@ define double @ole_inverse_y(double %x) nounwind { } ; CHECK-LABEL: ugt_y: -; CHECK: ucomisd %xmm0, %xmm1 +; CHECK: cmpnlesd %xmm ; UNSAFE-LABEL: ugt_y: ; UNSAFE-NEXT: maxsd {{[^,]*}}, %xmm0 ; UNSAFE-NEXT: ret @@ -697,7 +704,7 @@ define double @ugt_y(double %x) nounwind { } ; CHECK-LABEL: ult_y: -; CHECK: ucomisd %xmm1, %xmm0 +; CHECK: cmpnlesd %xmm0 ; UNSAFE-LABEL: ult_y: ; UNSAFE-NEXT: minsd {{[^,]*}}, %xmm0 ; UNSAFE-NEXT: ret @@ -711,7 +718,7 @@ define double @ult_y(double %x) nounwind { } ; CHECK-LABEL: ugt_inverse_y: -; CHECK: ucomisd %xmm +; CHECK: cmpnlesd %xmm ; UNSAFE-LABEL: ugt_inverse_y: ; UNSAFE-NEXT: minsd {{[^,]*}}, %xmm0 ; UNSAFE-NEXT: ret @@ -727,7 +734,7 @@ define double @ugt_inverse_y(double %x) nounwind { } ; CHECK-LABEL: ult_inverse_y: -; CHECK: ucomisd %xmm +; CHECK: cmpnlesd %xmm ; UNSAFE-LABEL: ult_inverse_y: ; UNSAFE-NEXT: maxsd {{[^,]*}}, %xmm0 ; UNSAFE-NEXT: ret |