Add a test for the MachineCopyPropagation change landed in r238518.
[oota-llvm.git] / test / CodeGen / X86 / machine-cp.ll
1 ; RUN: llc -mtriple=x86_64-apple-macosx -mcpu=nocona -verify-machineinstrs < %s | FileCheck %s
2
3 ; After tail duplication, two copies in an early exit BB can be cancelled out.
4 ; rdar://10640363
5 define i32 @t1(i32 %a, i32 %b) nounwind  {
6 entry:
7 ; CHECK-LABEL: t1:
8 ; CHECK: je [[LABEL:.*BB.*]]
9   %cmp1 = icmp eq i32 %b, 0
10   br i1 %cmp1, label %while.end, label %while.body
11
12 ; CHECK: [[LABEL]]:
13 ; CHECK-NOT: mov
14 ; CHECK: ret
15
16 while.body:                                       ; preds = %entry, %while.body
17   %a.addr.03 = phi i32 [ %b.addr.02, %while.body ], [ %a, %entry ]
18   %b.addr.02 = phi i32 [ %rem, %while.body ], [ %b, %entry ]
19   %rem = srem i32 %a.addr.03, %b.addr.02
20   %cmp = icmp eq i32 %rem, 0
21   br i1 %cmp, label %while.end, label %while.body
22
23 while.end:                                        ; preds = %while.body, %entry
24   %a.addr.0.lcssa = phi i32 [ %a, %entry ], [ %b.addr.02, %while.body ]
25   ret i32 %a.addr.0.lcssa
26 }
27
28 ; Two movdqa (from phi-elimination) in the entry BB cancels out.
29 ; rdar://10428165
30 define <8 x i16> @t2(<8 x i16> %T0, <8 x i16> %T1) nounwind readnone {
31 entry:
32 ; CHECK-LABEL: t2:
33 ; CHECK-NOT: movdqa
34   %tmp8 = shufflevector <8 x i16> %T0, <8 x i16> %T1, <8 x i32> < i32 undef, i32 undef, i32 7, i32 2, i32 8, i32 undef, i32 undef , i32 undef >
35   ret <8 x i16> %tmp8
36 }
37
38 define i32 @t3(i64 %a, i64 %b) nounwind  {
39 entry:
40 ; CHECK-LABEL: t3:
41 ; CHECK: je [[LABEL:.*BB.*]]
42   %cmp1 = icmp eq i64 %b, 0
43   br i1 %cmp1, label %while.end, label %while.body
44
45 ; CHECK: [[LABEL]]:
46 ; CHECK-NOT: mov
47 ; CHECK: ret
48
49 while.body:                                       ; preds = %entry, %while.body
50   %a.addr.03 = phi i64 [ %b.addr.02, %while.body ], [ %a, %entry ]
51   %b.addr.02 = phi i64 [ %rem, %while.body ], [ %b, %entry ]
52   %rem = srem i64 %a.addr.03, %b.addr.02
53   %cmp = icmp eq i64 %rem, 0
54   br i1 %cmp, label %while.end, label %while.body
55
56 while.end:                                        ; preds = %while.body, %entry
57   %a.addr.0.lcssa = phi i64 [ %a, %entry ], [ %b.addr.02, %while.body ]
58   %t = trunc i64 %a.addr.0.lcssa to i32
59   ret i32 %t
60 }
61
62 ; Check that copy propagation does not kill thing like:
63 ; dst = copy src <-- do not kill that.
64 ; ... = op1 dst<undef>
65 ; ... = op2 dst <-- this is used here.
66 ;
67 ; CHECK-LABEL: foo:
68 ; CHECK: psllw $7,
69 ; CHECK: psllw $7,
70 ; CHECK-NEXT: pand
71 ; CHECK-NEXT: pcmpgtb 
72 ; CHECK-NEXT: pand %xmm{{[0-9]+}}, [[SRC:%xmm[0-9]+]]
73 ; Machine propagation used to delete the first copy as the
74 ; first few uses were <undef>.
75 ; CHECK-NEXT: movdqa [[SRC]], [[CPY1:%xmm[0-9]+]]
76 ; CHECK-NEXT: movdqa [[SRC]], [[CPY2:%xmm[0-9]+]]
77 ; CHECK-NEXT: punpckhbw [[SRC]],
78 ; Check that CPY1 is not redefined.
79 ; CHECK-NOT: , [[CPY1]]
80 ; undef use, we do not care.
81 ; CHECK: punpcklwd [[CPY1]],
82 ; Check that CPY1 is not redefined.
83 ; CHECK-NOT: , [[CPY1]]
84 ; CHECK: punpcklbw [[CPY2]], [[CPY2]]
85 ; CHECK-NEXT: punpckhwd [[CPY2]], [[CPY2]]
86 ; CHECK-NEXT pslld $31, [[CPY2]]
87 ; Check that CPY1 is not redefined.
88 ; CHECK-NOT: , [[CPY1]]
89 ; CHECK: punpcklbw [[CPY1]], [[CPY1]]
90 ; CHECK-NEXT: punpcklwd [[CPY1]], [[CPY1]]
91 ; CHECK-NEXT pslld $31, [[CPY1]]
92 define <16 x float> @foo(<16 x float> %x) {
93 bb:
94   %v3 = icmp slt <16 x i32> undef, zeroinitializer
95   %v14 = zext <16 x i1> %v3 to <16 x i32>
96   %v16 = fcmp olt <16 x float> %x, zeroinitializer
97   %v17 = sext <16 x i1> %v16 to <16 x i32>
98   %v18 = zext <16 x i1> %v16 to <16 x i32>
99   %v19 = xor <16 x i32> %v14, %v18
100   %v20 = or <16 x i32> %v17, undef
101   %v21 = fptosi <16 x float> %x to <16 x i32>
102   %v22 = sitofp <16 x i32> %v21 to <16 x float>
103   %v69 = fcmp ogt <16 x float> %v22, zeroinitializer
104   %v75 = and <16 x i1> %v69, %v3
105   %v77 = bitcast <16 x float> %v22 to <16 x i32>
106   %v79 = sext <16 x i1> %v75 to <16 x i32>
107   %v80 = and <16 x i32> undef, %v79
108   %v81 = xor <16 x i32> %v77, %v80
109   %v82 = and <16 x i32> undef, %v81
110   %v83 = xor <16 x i32> %v19, %v82
111   %v84 = and <16 x i32> %v83, %v20
112   %v85 = xor <16 x i32> %v19, %v84
113   %v86 = bitcast <16 x i32> %v85 to <16 x float>
114   ret <16 x float> %v86
115 }