llvm.org GIT mirror llvm / 169c2e7
Merging r213799: ------------------------------------------------------------------------ r213799 | grosbach | 2014-07-23 13:41:38 -0700 (Wed, 23 Jul 2014) | 5 lines X86: restrict combine to when type sizes are safe. The folding of unary operations through a vector compare and mask operation is only safe if the unary operation result is of the same size as its input. For example, it's not safe for [su]itofp from v4i32 to v4f64. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_35@214841 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 5 years ago
4 changed file(s) with 51 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
64496449 // AND(VECTOR_CMP(x,y), constant2)
64506450 // constant2 = UNARYOP(constant)
64516451
6452 // Early exit if this isn't a vector operation or if the operand of the
6453 // unary operation isn't a bitwise AND.
6452 // Early exit if this isn't a vector operation, the operand of the
6453 // unary operation isn't a bitwise AND, or if the sizes of the operations
6454 // aren't the same.
64546455 EVT VT = N->getValueType(0);
64556456 if (!VT.isVector() || N->getOperand(0)->getOpcode() != ISD::AND ||
6456 N->getOperand(0)->getOperand(0)->getOpcode() != ISD::SETCC)
6457 N->getOperand(0)->getOperand(0)->getOpcode() != ISD::SETCC ||
6458 VT.getSizeInBits() != N->getOperand(0)->getValueType(0).getSizeInBits())
64576459 return SDValue();
64586460
64596461 // Now check that the other operand of the AND is a constant splat. We could
2185321853 // AND(VECTOR_CMP(x,y), constant2)
2185421854 // constant2 = UNARYOP(constant)
2185521855
21856 // Early exit if this isn't a vector operation or if the operand of the
21857 // unary operation isn't a bitwise AND.
21856 // Early exit if this isn't a vector operation, the operand of the
21857 // unary operation isn't a bitwise AND, or if the sizes of the operations
21858 // aren't the same.
2185821859 EVT VT = N->getValueType(0);
2185921860 if (!VT.isVector() || N->getOperand(0)->getOpcode() != ISD::AND ||
21860 N->getOperand(0)->getOperand(0)->getOpcode() != ISD::SETCC)
21861 N->getOperand(0)->getOperand(0)->getOpcode() != ISD::SETCC ||
21862 VT.getSizeInBits() != N->getOperand(0)->getValueType(0).getSizeInBits())
2186121863 return SDValue();
2186221864
2186321865 // Now check that the other operand of the AND is a constant splat. We could
1010 %result = sitofp <4 x i32> %ext to <4 x float>
1111 ret <4 x float> %result
1212 }
13 ; Make sure the operation doesn't try to get folded when the sizes don't match,
14 ; as that ends up crashing later when trying to form a bitcast operation for
15 ; the folded nodes.
16 define void @foo1(<4 x float> %val, <4 x float> %test, <4 x double>* %p) nounwind {
17 ; CHECK-LABEL: foo1:
18 ; CHECK: movi.4s
19 ; CHECK: scvtf.2d
20 ; CHECK: scvtf.2d
21 %cmp = fcmp oeq <4 x float> %val, %test
22 %ext = zext <4 x i1> %cmp to <4 x i32>
23 %result = sitofp <4 x i32> %ext to <4 x double>
24 store <4 x double> %result, <4 x double>* %p
25 ret void
26 }
1616 ret <4 x float> %result
1717 }
1818
19 define void @bar(<4 x float>* noalias %result) nounwind {
19 ; Make sure the operation doesn't try to get folded when the sizes don't match,
20 ; as that ends up crashing later when trying to form a bitcast operation for
21 ; the folded nodes.
22 define void @foo1(<4 x float> %val, <4 x float> %test, <4 x double>* %p) nounwind {
2023 ; CHECK-LABEL: LCPI1_0:
24 ; CHECK-NEXT: .long 1 ## 0x1
25 ; CHECK-NEXT: .long 1 ## 0x1
26 ; CHECK-NEXT: .long 1 ## 0x1
27 ; CHECK-NEXT: .long 1 ## 0x1
28 ; CHECK-LABEL: foo1:
29 ; FIXME: The operation gets scalarized. If/when the compiler learns to better
30 ; use [V]CVTDQ2PD, this will need updated.
31 ; CHECK: cvtsi2sdq
32 ; CHECK: cvtsi2sdq
33 ; CHECK: cvtsi2sdq
34 ; CHECK: cvtsi2sdq
35 %cmp = fcmp oeq <4 x float> %val, %test
36 %ext = zext <4 x i1> %cmp to <4 x i32>
37 %result = sitofp <4 x i32> %ext to <4 x double>
38 store <4 x double> %result, <4 x double>* %p
39 ret void
40 }
41
42 ; Also test the general purpose constant folding of int->fp.
43 define void @foo2(<4 x float>* noalias %result) nounwind {
44 ; CHECK-LABEL: LCPI2_0:
2145 ; CHECK-NEXT: .long 1082130432 ## float 4.000000e+00
2246 ; CHECK-NEXT: .long 1084227584 ## float 5.000000e+00
2347 ; CHECK-NEXT: .long 1086324736 ## float 6.000000e+00
2448 ; CHECK-NEXT: .long 1088421888 ## float 7.000000e+00
25 ; CHECK-LABEL: bar:
26 ; CHECK: movaps LCPI1_0(%rip), %xmm0
49 ; CHECK-LABEL: foo2:
50 ; CHECK: movaps LCPI2_0(%rip), %xmm0
2751
2852 %val = uitofp <4 x i32> to <4 x float>
2953 store <4 x float> %val, <4 x float>* %result