[llvm] r278270 - [x86, AVX] allow FP vector select folding to bitwise logic ops (PR28895)
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 10 12:00:11 PDT 2016
Author: spatel
Date: Wed Aug 10 14:00:11 2016
New Revision: 278270
URL: http://llvm.org/viewvc/llvm-project?rev=278270&view=rev
Log:
[x86, AVX] allow FP vector select folding to bitwise logic ops (PR28895)
This handles the case in:
https://llvm.org/bugs/show_bug.cgi?id=28895
...but we are not getting all of the possibilities yet.
Eg, we use 'X86::FANDN' for scalar FP select combines.
That enhancement is filed as:
https://llvm.org/bugs/show_bug.cgi?id=28925
Differential Revision: https://reviews.llvm.org/D23337
Modified:
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/test/CodeGen/X86/avx512-cvt.ll
llvm/trunk/test/CodeGen/X86/select-with-and-or.ll
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=278270&r1=278269&r2=278270&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Wed Aug 10 14:00:11 2016
@@ -26796,12 +26796,18 @@ static SDValue combineVSelectWithAllOnes
SDLoc DL(N);
const TargetLowering &TLI = DAG.getTargetLoweringInfo();
- // Condition value type must match vselect operand type.
- if (N->getOpcode() != ISD::VSELECT || CondVT != VT)
+ if (N->getOpcode() != ISD::VSELECT)
return SDValue();
- assert(Cond.getValueType().isVector() &&
- "Vector select expects a vector selector!");
+ assert(CondVT.isVector() && "Vector select expects a vector selector!");
+
+ // To use the condition operand as a bitwise mask, it must have elements that
+ // are the same size as the select elements. Ie, the condition operand must
+ // have already been promoted from the IR select condition type <N x i1>.
+ // Don't check if the types themselves are equal because that excludes
+ // vector floating-point selects.
+ if (CondVT.getScalarSizeInBits() != VT.getScalarSizeInBits())
+ return SDValue();
bool TValIsAllOnes = ISD::isBuildVectorAllOnes(LHS.getNode());
bool FValIsAllZeros = ISD::isBuildVectorAllZeros(RHS.getNode());
Modified: llvm/trunk/test/CodeGen/X86/avx512-cvt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/avx512-cvt.ll?rev=278270&r1=278269&r2=278270&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/avx512-cvt.ll (original)
+++ llvm/trunk/test/CodeGen/X86/avx512-cvt.ll Wed Aug 10 14:00:11 2016
@@ -415,9 +415,9 @@ define <4 x float> @fptrunc02(<4 x doubl
; KNL-LABEL: fptrunc02:
; KNL: ## BB#0:
; KNL-NEXT: vpslld $31, %xmm1, %xmm1
+; KNL-NEXT: vpsrad $31, %xmm1, %xmm1
; KNL-NEXT: vcvtpd2psy %ymm0, %xmm0
-; KNL-NEXT: vxorps %xmm2, %xmm2, %xmm2
-; KNL-NEXT: vblendvps %xmm1, %xmm0, %xmm2, %xmm0
+; KNL-NEXT: vpand %xmm0, %xmm1, %xmm0
; KNL-NEXT: retq
;
; SKX-LABEL: fptrunc02:
@@ -445,8 +445,7 @@ define <4 x double> @fpext01(<4 x float>
; KNL: ## BB#0:
; KNL-NEXT: vcvtps2pd %xmm0, %ymm0
; KNL-NEXT: vcmpltpd %ymm2, %ymm1, %ymm1
-; KNL-NEXT: vxorpd %ymm2, %ymm2, %ymm2
-; KNL-NEXT: vblendvpd %ymm1, %ymm0, %ymm2, %ymm0
+; KNL-NEXT: vandpd %ymm0, %ymm1, %ymm0
; KNL-NEXT: retq
;
; SKX-LABEL: fpext01:
Modified: llvm/trunk/test/CodeGen/X86/select-with-and-or.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/select-with-and-or.ll?rev=278270&r1=278269&r2=278270&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/select-with-and-or.ll (original)
+++ llvm/trunk/test/CodeGen/X86/select-with-and-or.ll Wed Aug 10 14:00:11 2016
@@ -90,8 +90,7 @@ define <2 x double> @test1f(<2 x double>
; CHECK-LABEL: test1f:
; CHECK: # BB#0:
; CHECK-NEXT: vcmpltpd %xmm0, %xmm1, %xmm0
-; CHECK-NEXT: vxorpd %xmm1, %xmm1, %xmm1
-; CHECK-NEXT: vblendvpd %xmm0, %xmm2, %xmm1, %xmm0
+; CHECK-NEXT: vandpd %xmm2, %xmm0, %xmm0
; CHECK-NEXT: retq
;
%f = fcmp ogt <2 x double> %a, %b
@@ -103,8 +102,7 @@ define <2 x double> @test2f(<2 x double>
; CHECK-LABEL: test2f:
; CHECK: # BB#0:
; CHECK-NEXT: vcmplepd %xmm0, %xmm1, %xmm0
-; CHECK-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
-; CHECK-NEXT: vblendvpd %xmm0, %xmm1, %xmm2, %xmm0
+; CHECK-NEXT: vorpd %xmm2, %xmm0, %xmm0
; CHECK-NEXT: retq
;
%f = fcmp oge <2 x double> %a, %b
@@ -115,9 +113,8 @@ define <2 x double> @test2f(<2 x double>
define <2 x double> @test3f(<2 x double> %a, <2 x double> %b, <2 x double> %c) {
; CHECK-LABEL: test3f:
; CHECK: # BB#0:
-; CHECK-NEXT: vcmpltpd %xmm1, %xmm0, %xmm0
-; CHECK-NEXT: vxorpd %xmm1, %xmm1, %xmm1
-; CHECK-NEXT: vblendvpd %xmm0, %xmm1, %xmm2, %xmm0
+; CHECK-NEXT: vcmpnltpd %xmm1, %xmm0, %xmm0
+; CHECK-NEXT: vandpd %xmm2, %xmm0, %xmm0
; CHECK-NEXT: retq
;
%f = fcmp olt <2 x double> %a, %b
@@ -128,9 +125,8 @@ define <2 x double> @test3f(<2 x double>
define <2 x double> @test4f(<2 x double> %a, <2 x double> %b, <2 x double> %c) {
; CHECK-LABEL: test4f:
; CHECK: # BB#0:
-; CHECK-NEXT: vcmplepd %xmm1, %xmm0, %xmm0
-; CHECK-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
-; CHECK-NEXT: vblendvpd %xmm0, %xmm2, %xmm1, %xmm0
+; CHECK-NEXT: vcmpnlepd %xmm1, %xmm0, %xmm0
+; CHECK-NEXT: vorpd %xmm2, %xmm0, %xmm0
; CHECK-NEXT: retq
;
%f = fcmp ole <2 x double> %a, %b
@@ -142,9 +138,6 @@ define <2 x double> @test5f(<2 x double>
; CHECK-LABEL: test5f:
; CHECK: # BB#0:
; CHECK-NEXT: vcmpnlepd %xmm1, %xmm0, %xmm0
-; CHECK-NEXT: vpcmpeqd %xmm1, %xmm1, %xmm1
-; CHECK-NEXT: vxorpd %xmm2, %xmm2, %xmm2
-; CHECK-NEXT: vblendvpd %xmm0, %xmm1, %xmm2, %xmm0
; CHECK-NEXT: retq
;
%f = fcmp ugt <2 x double> %a, %b
@@ -155,10 +148,7 @@ define <2 x double> @test5f(<2 x double>
define <2 x double> @test6f(<2 x double> %a, <2 x double> %b, <2 x double> %c) {
; CHECK-LABEL: test6f:
; CHECK: # BB#0:
-; CHECK-NEXT: vcmpnltpd %xmm0, %xmm1, %xmm0
-; CHECK-NEXT: vxorpd %xmm1, %xmm1, %xmm1
-; CHECK-NEXT: vpcmpeqd %xmm2, %xmm2, %xmm2
-; CHECK-NEXT: vblendvpd %xmm0, %xmm1, %xmm2, %xmm0
+; CHECK-NEXT: vcmpltpd %xmm0, %xmm1, %xmm0
; CHECK-NEXT: retq
;
%f = fcmp ule <2 x double> %a, %b
@@ -170,8 +160,7 @@ define <2 x double> @test7f(<2 x double>
; CHECK-LABEL: test7f:
; CHECK: # BB#0:
; CHECK-NEXT: vcmpeqpd %xmm1, %xmm0, %xmm0
-; CHECK-NEXT: vxorpd %xmm1, %xmm1, %xmm1
-; CHECK-NEXT: vblendvpd %xmm0, (%rdi), %xmm1, %xmm0
+; CHECK-NEXT: vandpd (%rdi), %xmm0, %xmm0
; CHECK-NEXT: retq
;
%f = fcmp oeq <2 x double> %a, %b
More information about the llvm-commits
mailing list