2013-08-24 04:39:19 +08:00
|
|
|
; RUN: llc < %s -mtriple=x86_64-apple-darwin -mcpu=corei7 -mattr=+sse4.1 | FileCheck %s
|
2011-09-08 16:31:31 +08:00
|
|
|
|
2013-07-19 06:47:09 +08:00
|
|
|
;CHECK-LABEL: vsel_float:
|
2014-05-17 06:47:49 +08:00
|
|
|
;CHECK: blendps
|
2011-09-08 16:31:31 +08:00
|
|
|
;CHECK: ret
|
|
|
|
define <4 x float> @vsel_float(<4 x float> %v1, <4 x float> %v2) {
|
[X86] Teach how to combine a vselect into a movss/movsd
Add target specific rules for combining vselect dag nodes into movss/movsd
when possible.
If the vector type of the vselect dag node in input is either MVT::v4i13 or
MVT::v4f32, then try to fold according to rules:
1) fold (vselect (build_vector (0, -1, -1, -1)), A, B) -> (movss A, B)
2) fold (vselect (build_vector (-1, 0, 0, 0)), A, B) -> (movss B, A)
If the vector type of the vselect dag node in input is either MVT::v2i64 or
MVT::v2f64 (and we have SSE2), then try to fold according to rules:
3) fold (vselect (build_vector (0, -1)), A, B) -> (movsd A, B)
4) fold (vselect (build_vector (-1, 0)), A, B) -> (movsd B, A)
llvm-svn: 199683
2014-01-21 03:35:22 +08:00
|
|
|
%vsel = select <4 x i1> <i1 true, i1 false, i1 true, i1 true>, <4 x float> %v1, <4 x float> %v2
|
2011-09-08 16:31:31 +08:00
|
|
|
ret <4 x float> %vsel
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-19 06:47:09 +08:00
|
|
|
;CHECK-LABEL: vsel_4xi8:
|
[x86] Revert r218588, r218589, and r218600. These patches were pursuing
a flawed direction and causing miscompiles. Read on for details.
Fundamentally, the premise of this patch series was to map
VECTOR_SHUFFLE DAG nodes into VSELECT DAG nodes for all blends because
we are going to *have* to lower to VSELECT nodes for some blends to
trigger the instruction selection patterns of variable blend
instructions. This doesn't actually work out so well.
In order to match performance with the existing VECTOR_SHUFFLE
lowering code, we would need to re-slice the blend in order to fit it
into either the integer or floating point blends available on the ISA.
When coming from VECTOR_SHUFFLE (or other vNi1 style VSELECT sources)
this works well because the X86 backend ensures that these types of
operands to VSELECT get sign extended into '-1' and '0' for true and
false, allowing us to re-slice the bits in whatever granularity without
changing semantics.
However, if the VSELECT condition comes from some other source, for
example code lowering vector comparisons, it will likely only have the
required bit set -- the high bit. We can't blindly slice up this style
of VSELECT. Reid found some code using Halide that triggers this and I'm
hopeful to eventually get a test case, but I don't need it to understand
why this is A Bad Idea.
There is another aspect that makes this approach flawed. When in
VECTOR_SHUFFLE form, we have very distilled information that represents
the *constant* blend mask. Converting back to a VSELECT form actually
can lose this information, and so I think now that it is better to treat
this as VECTOR_SHUFFLE until the very last moment and only use VSELECT
nodes for instruction selection purposes.
My plan is to:
1) Clean up and formalize the target pre-legalization DAG combine that
converts a VSELECT with a constant condition operand into
a VECTOR_SHUFFLE.
2) Remove any fancy lowering from VSELECT during *legalization* relying
entirely on the DAG combine to catch cases where we can match to an
immediate-controlled blend instruction.
One additional step that I'm not planning on but would be interested in
others' opinions on: we could add an X86ISD::VSELECT or X86ISD::BLENDV
which encodes a fully legalized VSELECT node. Then it would be easy to
write isel patterns only in terms of this to ensure VECTOR_SHUFFLE
legalization only ever forms the fully legalized construct and we can't
cycle between it and VSELECT combining.
llvm-svn: 218658
2014-09-30 10:52:28 +08:00
|
|
|
;CHECK: blendps
|
2011-09-14 22:42:15 +08:00
|
|
|
;CHECK: ret
|
|
|
|
define <4 x i8> @vsel_4xi8(<4 x i8> %v1, <4 x i8> %v2) {
|
[X86] Add extra rules for combining vselect dag nodes into movsd.
This improves the fix committed at revision 199683 adding the
following new target specific combine rules:
1) fold (v4i32: vselect <0,0,-1,-1>, A, B) ->
(v4i32 (bitcast (movsd (v2i64 (bitcast A)), (v2i64 (bitcast B))) ))
2) fold (v4f32: vselect <0,0,-1,-1>, A, B) ->
(v4f32 (bitcast (movsd (v2f64 (bitcast A)), (v2f64 (bitcast B))) ))
3) fold (v4i32: vselect <-1,-1,0,0>, A, B) ->
(v4i32 (bitcast (movsd (v2i64 (bitcast B)), (v2i64 (bitcast A))) ))
4) fold (v4f32: vselect <-1,-1,0,0>, A, B) ->
(v4f32 (bitcast (movsd (v2i64 (bitcast B)), (v2i64 (bitcast A))) ))
llvm-svn: 200324
2014-01-29 02:14:21 +08:00
|
|
|
%vsel = select <4 x i1> <i1 true, i1 true, i1 false, i1 true>, <4 x i8> %v1, <4 x i8> %v2
|
2011-09-14 22:42:15 +08:00
|
|
|
ret <4 x i8> %vsel
|
|
|
|
}
|
|
|
|
|
2013-07-19 06:47:09 +08:00
|
|
|
;CHECK-LABEL: vsel_4xi16:
|
[x86] Revert r218588, r218589, and r218600. These patches were pursuing
a flawed direction and causing miscompiles. Read on for details.
Fundamentally, the premise of this patch series was to map
VECTOR_SHUFFLE DAG nodes into VSELECT DAG nodes for all blends because
we are going to *have* to lower to VSELECT nodes for some blends to
trigger the instruction selection patterns of variable blend
instructions. This doesn't actually work out so well.
In order to match performance with the existing VECTOR_SHUFFLE
lowering code, we would need to re-slice the blend in order to fit it
into either the integer or floating point blends available on the ISA.
When coming from VECTOR_SHUFFLE (or other vNi1 style VSELECT sources)
this works well because the X86 backend ensures that these types of
operands to VSELECT get sign extended into '-1' and '0' for true and
false, allowing us to re-slice the bits in whatever granularity without
changing semantics.
However, if the VSELECT condition comes from some other source, for
example code lowering vector comparisons, it will likely only have the
required bit set -- the high bit. We can't blindly slice up this style
of VSELECT. Reid found some code using Halide that triggers this and I'm
hopeful to eventually get a test case, but I don't need it to understand
why this is A Bad Idea.
There is another aspect that makes this approach flawed. When in
VECTOR_SHUFFLE form, we have very distilled information that represents
the *constant* blend mask. Converting back to a VSELECT form actually
can lose this information, and so I think now that it is better to treat
this as VECTOR_SHUFFLE until the very last moment and only use VSELECT
nodes for instruction selection purposes.
My plan is to:
1) Clean up and formalize the target pre-legalization DAG combine that
converts a VSELECT with a constant condition operand into
a VECTOR_SHUFFLE.
2) Remove any fancy lowering from VSELECT during *legalization* relying
entirely on the DAG combine to catch cases where we can match to an
immediate-controlled blend instruction.
One additional step that I'm not planning on but would be interested in
others' opinions on: we could add an X86ISD::VSELECT or X86ISD::BLENDV
which encodes a fully legalized VSELECT node. Then it would be easy to
write isel patterns only in terms of this to ensure VECTOR_SHUFFLE
legalization only ever forms the fully legalized construct and we can't
cycle between it and VSELECT combining.
llvm-svn: 218658
2014-09-30 10:52:28 +08:00
|
|
|
;CHECK: blendps
|
2011-09-14 22:42:15 +08:00
|
|
|
;CHECK: ret
|
|
|
|
define <4 x i16> @vsel_4xi16(<4 x i16> %v1, <4 x i16> %v2) {
|
[X86] Teach how to combine a vselect into a movss/movsd
Add target specific rules for combining vselect dag nodes into movss/movsd
when possible.
If the vector type of the vselect dag node in input is either MVT::v4i13 or
MVT::v4f32, then try to fold according to rules:
1) fold (vselect (build_vector (0, -1, -1, -1)), A, B) -> (movss A, B)
2) fold (vselect (build_vector (-1, 0, 0, 0)), A, B) -> (movss B, A)
If the vector type of the vselect dag node in input is either MVT::v2i64 or
MVT::v2f64 (and we have SSE2), then try to fold according to rules:
3) fold (vselect (build_vector (0, -1)), A, B) -> (movsd A, B)
4) fold (vselect (build_vector (-1, 0)), A, B) -> (movsd B, A)
llvm-svn: 199683
2014-01-21 03:35:22 +08:00
|
|
|
%vsel = select <4 x i1> <i1 true, i1 false, i1 true, i1 true>, <4 x i16> %v1, <4 x i16> %v2
|
2011-09-14 22:42:15 +08:00
|
|
|
ret <4 x i16> %vsel
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-19 06:47:09 +08:00
|
|
|
;CHECK-LABEL: vsel_i32:
|
[x86] Revert r218588, r218589, and r218600. These patches were pursuing
a flawed direction and causing miscompiles. Read on for details.
Fundamentally, the premise of this patch series was to map
VECTOR_SHUFFLE DAG nodes into VSELECT DAG nodes for all blends because
we are going to *have* to lower to VSELECT nodes for some blends to
trigger the instruction selection patterns of variable blend
instructions. This doesn't actually work out so well.
In order to match performance with the existing VECTOR_SHUFFLE
lowering code, we would need to re-slice the blend in order to fit it
into either the integer or floating point blends available on the ISA.
When coming from VECTOR_SHUFFLE (or other vNi1 style VSELECT sources)
this works well because the X86 backend ensures that these types of
operands to VSELECT get sign extended into '-1' and '0' for true and
false, allowing us to re-slice the bits in whatever granularity without
changing semantics.
However, if the VSELECT condition comes from some other source, for
example code lowering vector comparisons, it will likely only have the
required bit set -- the high bit. We can't blindly slice up this style
of VSELECT. Reid found some code using Halide that triggers this and I'm
hopeful to eventually get a test case, but I don't need it to understand
why this is A Bad Idea.
There is another aspect that makes this approach flawed. When in
VECTOR_SHUFFLE form, we have very distilled information that represents
the *constant* blend mask. Converting back to a VSELECT form actually
can lose this information, and so I think now that it is better to treat
this as VECTOR_SHUFFLE until the very last moment and only use VSELECT
nodes for instruction selection purposes.
My plan is to:
1) Clean up and formalize the target pre-legalization DAG combine that
converts a VSELECT with a constant condition operand into
a VECTOR_SHUFFLE.
2) Remove any fancy lowering from VSELECT during *legalization* relying
entirely on the DAG combine to catch cases where we can match to an
immediate-controlled blend instruction.
One additional step that I'm not planning on but would be interested in
others' opinions on: we could add an X86ISD::VSELECT or X86ISD::BLENDV
which encodes a fully legalized VSELECT node. Then it would be easy to
write isel patterns only in terms of this to ensure VECTOR_SHUFFLE
legalization only ever forms the fully legalized construct and we can't
cycle between it and VSELECT combining.
llvm-svn: 218658
2014-09-30 10:52:28 +08:00
|
|
|
;CHECK: blendps
|
2011-09-08 16:31:31 +08:00
|
|
|
;CHECK: ret
|
|
|
|
define <4 x i32> @vsel_i32(<4 x i32> %v1, <4 x i32> %v2) {
|
[X86] Add extra rules for combining vselect dag nodes into movsd.
This improves the fix committed at revision 199683 adding the
following new target specific combine rules:
1) fold (v4i32: vselect <0,0,-1,-1>, A, B) ->
(v4i32 (bitcast (movsd (v2i64 (bitcast A)), (v2i64 (bitcast B))) ))
2) fold (v4f32: vselect <0,0,-1,-1>, A, B) ->
(v4f32 (bitcast (movsd (v2f64 (bitcast A)), (v2f64 (bitcast B))) ))
3) fold (v4i32: vselect <-1,-1,0,0>, A, B) ->
(v4i32 (bitcast (movsd (v2i64 (bitcast B)), (v2i64 (bitcast A))) ))
4) fold (v4f32: vselect <-1,-1,0,0>, A, B) ->
(v4f32 (bitcast (movsd (v2i64 (bitcast B)), (v2i64 (bitcast A))) ))
llvm-svn: 200324
2014-01-29 02:14:21 +08:00
|
|
|
%vsel = select <4 x i1> <i1 true, i1 true, i1 false, i1 true>, <4 x i32> %v1, <4 x i32> %v2
|
2011-09-08 16:31:31 +08:00
|
|
|
ret <4 x i32> %vsel
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-19 06:47:09 +08:00
|
|
|
;CHECK-LABEL: vsel_double:
|
[X86] Teach how to combine a vselect into a movss/movsd
Add target specific rules for combining vselect dag nodes into movss/movsd
when possible.
If the vector type of the vselect dag node in input is either MVT::v4i13 or
MVT::v4f32, then try to fold according to rules:
1) fold (vselect (build_vector (0, -1, -1, -1)), A, B) -> (movss A, B)
2) fold (vselect (build_vector (-1, 0, 0, 0)), A, B) -> (movss B, A)
If the vector type of the vselect dag node in input is either MVT::v2i64 or
MVT::v2f64 (and we have SSE2), then try to fold according to rules:
3) fold (vselect (build_vector (0, -1)), A, B) -> (movsd A, B)
4) fold (vselect (build_vector (-1, 0)), A, B) -> (movsd B, A)
llvm-svn: 199683
2014-01-21 03:35:22 +08:00
|
|
|
;CHECK: movsd
|
2011-09-08 16:31:31 +08:00
|
|
|
;CHECK: ret
|
|
|
|
define <4 x double> @vsel_double(<4 x double> %v1, <4 x double> %v2) {
|
|
|
|
%vsel = select <4 x i1> <i1 true, i1 false, i1 false, i1 false>, <4 x double> %v1, <4 x double> %v2
|
|
|
|
ret <4 x double> %vsel
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-19 06:47:09 +08:00
|
|
|
;CHECK-LABEL: vsel_i64:
|
[X86] Teach how to combine a vselect into a movss/movsd
Add target specific rules for combining vselect dag nodes into movss/movsd
when possible.
If the vector type of the vselect dag node in input is either MVT::v4i13 or
MVT::v4f32, then try to fold according to rules:
1) fold (vselect (build_vector (0, -1, -1, -1)), A, B) -> (movss A, B)
2) fold (vselect (build_vector (-1, 0, 0, 0)), A, B) -> (movss B, A)
If the vector type of the vselect dag node in input is either MVT::v2i64 or
MVT::v2f64 (and we have SSE2), then try to fold according to rules:
3) fold (vselect (build_vector (0, -1)), A, B) -> (movsd A, B)
4) fold (vselect (build_vector (-1, 0)), A, B) -> (movsd B, A)
llvm-svn: 199683
2014-01-21 03:35:22 +08:00
|
|
|
;CHECK: movsd
|
2011-09-08 16:31:31 +08:00
|
|
|
;CHECK: ret
|
|
|
|
define <4 x i64> @vsel_i64(<4 x i64> %v1, <4 x i64> %v2) {
|
|
|
|
%vsel = select <4 x i1> <i1 true, i1 false, i1 false, i1 false>, <4 x i64> %v1, <4 x i64> %v2
|
|
|
|
ret <4 x i64> %vsel
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-19 06:47:09 +08:00
|
|
|
;CHECK-LABEL: vsel_i8:
|
2011-09-08 16:31:31 +08:00
|
|
|
;CHECK: pblendvb
|
|
|
|
;CHECK: ret
|
|
|
|
define <16 x i8> @vsel_i8(<16 x i8> %v1, <16 x i8> %v2) {
|
|
|
|
%vsel = select <16 x i1> <i1 true, i1 false, i1 false, i1 false, i1 true, i1 false, i1 false, i1 false, i1 true, i1 false, i1 false, i1 false, i1 true, i1 false, i1 false, i1 false>, <16 x i8> %v1, <16 x i8> %v2
|
|
|
|
ret <16 x i8> %vsel
|
|
|
|
}
|
|
|
|
|
2011-09-13 03:30:40 +08:00
|
|
|
;; TEST blend + compares
|
|
|
|
; CHECK: A
|
|
|
|
define <2 x double> @A(<2 x double> %x, <2 x double> %y) {
|
2011-09-13 05:24:07 +08:00
|
|
|
; CHECK: cmplepd
|
2011-09-13 03:30:40 +08:00
|
|
|
; CHECK: blendvpd
|
|
|
|
%max_is_x = fcmp oge <2 x double> %x, %y
|
|
|
|
%max = select <2 x i1> %max_is_x, <2 x double> %x, <2 x double> %y
|
|
|
|
ret <2 x double> %max
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK: B
|
|
|
|
define <2 x double> @B(<2 x double> %x, <2 x double> %y) {
|
2011-09-18 00:49:39 +08:00
|
|
|
; CHECK: cmpnlepd
|
2011-09-13 03:30:40 +08:00
|
|
|
; CHECK: blendvpd
|
2011-09-18 00:49:39 +08:00
|
|
|
%min_is_x = fcmp ult <2 x double> %x, %y
|
|
|
|
%min = select <2 x i1> %min_is_x, <2 x double> %x, <2 x double> %y
|
|
|
|
ret <2 x double> %min
|
2011-09-13 03:30:40 +08:00
|
|
|
}
|
2011-09-08 16:31:31 +08:00
|
|
|
|
2012-04-15 23:08:09 +08:00
|
|
|
; CHECK: float_crash
|
|
|
|
define void @float_crash() nounwind {
|
|
|
|
entry:
|
|
|
|
%merge205vector_func.i = select <4 x i1> undef, <4 x double> undef, <4 x double> undef
|
|
|
|
%extract214vector_func.i = extractelement <4 x double> %merge205vector_func.i, i32 0
|
|
|
|
store double %extract214vector_func.i, double addrspace(1)* undef, align 8
|
|
|
|
ret void
|
|
|
|
}
|
2014-05-27 11:42:20 +08:00
|
|
|
|
|
|
|
; If we can figure out a blend has a constant mask, we should emit the
|
|
|
|
; blend instruction with an immediate mask
|
|
|
|
define <2 x double> @constant_blendvpd(<2 x double> %xy, <2 x double> %ab) {
|
|
|
|
; In this case, we emit a simple movss
|
|
|
|
; CHECK-LABEL: constant_blendvpd
|
|
|
|
; CHECK: movsd
|
|
|
|
; CHECK: ret
|
|
|
|
%1 = select <2 x i1> <i1 true, i1 false>, <2 x double> %xy, <2 x double> %ab
|
|
|
|
ret <2 x double> %1
|
|
|
|
}
|
|
|
|
|
|
|
|
define <4 x float> @constant_blendvps(<4 x float> %xyzw, <4 x float> %abcd) {
|
|
|
|
; CHECK-LABEL: constant_blendvps
|
|
|
|
; CHECK-NOT: mov
|
|
|
|
; CHECK: blendps $7
|
|
|
|
; CHECK: ret
|
|
|
|
%1 = select <4 x i1> <i1 false, i1 false, i1 false, i1 true>, <4 x float> %xyzw, <4 x float> %abcd
|
|
|
|
ret <4 x float> %1
|
|
|
|
}
|
|
|
|
|
|
|
|
define <16 x i8> @constant_pblendvb(<16 x i8> %xyzw, <16 x i8> %abcd) {
|
|
|
|
; CHECK-LABEL: constant_pblendvb:
|
|
|
|
; CHECK: movaps
|
|
|
|
; CHECK: pblendvb
|
|
|
|
; CHECK: ret
|
|
|
|
%1 = select <16 x i1> <i1 false, i1 false, i1 true, i1 false, i1 true, i1 true, i1 true, i1 false, i1 false, i1 false, i1 true, i1 false, i1 true, i1 true, i1 true, i1 false>, <16 x i8> %xyzw, <16 x i8> %abcd
|
|
|
|
ret <16 x i8> %1
|
|
|
|
}
|
2014-05-30 06:04:42 +08:00
|
|
|
|
2014-05-27 11:42:20 +08:00
|
|
|
declare <16 x i8> @llvm.x86.sse41.pblendvb(<16 x i8>, <16 x i8>, <16 x i8>)
|
|
|
|
declare <4 x float> @llvm.x86.sse41.blendvps(<4 x float>, <4 x float>, <4 x float>)
|
|
|
|
declare <2 x double> @llvm.x86.sse41.blendvpd(<2 x double>, <2 x double>, <2 x double>)
|
2014-05-30 06:04:42 +08:00
|
|
|
|
|
|
|
;; 2 tests for shufflevectors that optimize to blend + immediate
|
|
|
|
; CHECK-LABEL: @blend_shufflevector_4xfloat
|
2014-05-31 08:52:23 +08:00
|
|
|
; CHECK: blendps $6, %xmm1, %xmm0
|
2014-05-30 06:04:42 +08:00
|
|
|
; CHECK: ret
|
|
|
|
define <4 x float> @blend_shufflevector_4xfloat(<4 x float> %a, <4 x float> %b) {
|
|
|
|
%1 = shufflevector <4 x float> %a, <4 x float> %b, <4 x i32> <i32 0, i32 5, i32 6, i32 3>
|
|
|
|
ret <4 x float> %1
|
|
|
|
}
|
|
|
|
|
|
|
|
; CHECK-LABEL: @blend_shufflevector_8xi16
|
2014-05-31 08:52:23 +08:00
|
|
|
; CHECK: pblendw $134, %xmm1, %xmm0
|
2014-05-30 06:04:42 +08:00
|
|
|
; CHECK: ret
|
|
|
|
define <8 x i16> @blend_shufflevector_8xi16(<8 x i16> %a, <8 x i16> %b) {
|
|
|
|
%1 = shufflevector <8 x i16> %a, <8 x i16> %b, <8 x i32> <i32 0, i32 9, i32 10, i32 3, i32 4, i32 5, i32 6, i32 15>
|
|
|
|
ret <8 x i16> %1
|
|
|
|
}
|
2014-08-21 04:34:56 +08:00
|
|
|
|
|
|
|
; PR20648 - a blend of constants isn't really a blend; it's just a constant pool load.
|
|
|
|
; CHECK-LABEL: @does_not_blend
|
|
|
|
; CHECK: movaps
|
|
|
|
; CHECK-NEXT: ret
|
|
|
|
define <4 x i32> @does_not_blend() {
|
|
|
|
%select = select <4 x i1> <i1 1, i1 0, i1 0, i1 1>, <4 x i32> <i32 1, i32 1, i32 1, i32 1>, <4 x i32> <i32 2, i32 2, i32 2, i32 2>
|
|
|
|
ret <4 x i32> %select
|
|
|
|
}
|
|
|
|
|