[CodeGenPrepare] Teach when it is profitable to speculate calls to @llvm.cttz/ctlz.
[oota-llvm.git] / test / CodeGen / X86 / break-sse-dep.ll
1 ; RUN: llc < %s -mtriple=x86_64-linux -mattr=+sse2 -mcpu=nehalem | FileCheck %s
2 ; RUN: llc < %s -mtriple=x86_64-win32 -mattr=+sse2 -mcpu=nehalem | FileCheck %s
3
4 define double @t1(float* nocapture %x) nounwind readonly ssp {
5 entry:
6 ; CHECK-LABEL: t1:
7 ; CHECK: movss ([[A0:%rdi|%rcx]]), %xmm0
8 ; CHECK: cvtss2sd %xmm0, %xmm0
9
10   %0 = load float* %x, align 4
11   %1 = fpext float %0 to double
12   ret double %1
13 }
14
15 define float @t2(double* nocapture %x) nounwind readonly ssp optsize {
16 entry:
17 ; CHECK-LABEL: t2:
18 ; CHECK: cvtsd2ss ([[A0]]), %xmm0
19   %0 = load double* %x, align 8
20   %1 = fptrunc double %0 to float
21   ret float %1
22 }
23
24 define float @squirtf(float* %x) nounwind {
25 entry:
26 ; CHECK-LABEL: squirtf:
27 ; CHECK: movss ([[A0]]), %xmm0
28 ; CHECK: sqrtss %xmm0, %xmm0
29   %z = load float* %x
30   %t = call float @llvm.sqrt.f32(float %z)
31   ret float %t
32 }
33
34 define double @squirt(double* %x) nounwind {
35 entry:
36 ; CHECK-LABEL: squirt:
37 ; CHECK: movsd ([[A0]]), %xmm0
38 ; CHECK: sqrtsd %xmm0, %xmm0
39   %z = load double* %x
40   %t = call double @llvm.sqrt.f64(double %z)
41   ret double %t
42 }
43
44 define float @squirtf_size(float* %x) nounwind optsize {
45 entry:
46 ; CHECK-LABEL: squirtf_size:
47 ; CHECK: sqrtss ([[A0]]), %xmm0
48   %z = load float* %x
49   %t = call float @llvm.sqrt.f32(float %z)
50   ret float %t
51 }
52
53 define double @squirt_size(double* %x) nounwind optsize {
54 entry:
55 ; CHECK-LABEL: squirt_size:
56 ; CHECK: sqrtsd ([[A0]]), %xmm0
57   %z = load double* %x
58   %t = call double @llvm.sqrt.f64(double %z)
59   ret double %t
60 }
61
62 declare float @llvm.sqrt.f32(float)
63 declare double @llvm.sqrt.f64(double)
64
65 ; CHECK-LABEL: loopdep1
66 ; CHECK: for.body
67 ;
68 ; This loop contains two cvtsi2ss instructions that update the same xmm
69 ; register.  Verify that the execution dependency fix pass breaks those
70 ; dependencies by inserting xorps instructions.
71 ;
72 ; If the register allocator chooses different registers for the two cvtsi2ss
73 ; instructions, they are still dependent on themselves.
74 ; CHECK: xorps [[XMM1:%xmm[0-9]+]]
75 ; CHECK: , [[XMM1]]
76 ; CHECK: cvtsi2ssl %{{.*}}, [[XMM1]]
77 ; CHECK: xorps [[XMM2:%xmm[0-9]+]]
78 ; CHECK: , [[XMM2]]
79 ; CHECK: cvtsi2ssl %{{.*}}, [[XMM2]]
80 ;
81 define float @loopdep1(i32 %m) nounwind uwtable readnone ssp {
82 entry:
83   %tobool3 = icmp eq i32 %m, 0
84   br i1 %tobool3, label %for.end, label %for.body
85
86 for.body:                                         ; preds = %entry, %for.body
87   %m.addr.07 = phi i32 [ %dec, %for.body ], [ %m, %entry ]
88   %s1.06 = phi float [ %add, %for.body ], [ 0.000000e+00, %entry ]
89   %s2.05 = phi float [ %add2, %for.body ], [ 0.000000e+00, %entry ]
90   %n.04 = phi i32 [ %inc, %for.body ], [ 1, %entry ]
91   %conv = sitofp i32 %n.04 to float
92   %add = fadd float %s1.06, %conv
93   %conv1 = sitofp i32 %m.addr.07 to float
94   %add2 = fadd float %s2.05, %conv1
95   %inc = add nsw i32 %n.04, 1
96   %dec = add nsw i32 %m.addr.07, -1
97   %tobool = icmp eq i32 %dec, 0
98   br i1 %tobool, label %for.end, label %for.body
99
100 for.end:                                          ; preds = %for.body, %entry
101   %s1.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add, %for.body ]
102   %s2.0.lcssa = phi float [ 0.000000e+00, %entry ], [ %add2, %for.body ]
103   %sub = fsub float %s1.0.lcssa, %s2.0.lcssa
104   ret float %sub
105 }
106
107 ; This loop contains a cvtsi2sd instruction that has a loop-carried
108 ; false dependency on an xmm that is modified by other scalar instructions
109 ; that follow it in the loop. Additionally, the source of convert is a 
110 ; memory operand. Verify the execution dependency fix pass breaks this
111 ; dependency by inserting a xor before the convert.
112 @x = common global [1024 x double] zeroinitializer, align 16
113 @y = common global [1024 x double] zeroinitializer, align 16
114 @z = common global [1024 x double] zeroinitializer, align 16
115 @w = common global [1024 x double] zeroinitializer, align 16
116 @v = common global [1024 x i32] zeroinitializer, align 16
117
118 define void @loopdep2() {
119 entry:
120   br label %for.cond1.preheader
121
122 for.cond1.preheader:                              ; preds = %for.inc14, %entry
123   %i.025 = phi i32 [ 0, %entry ], [ %inc15, %for.inc14 ]
124   br label %for.body3
125
126 for.body3:
127   %indvars.iv = phi i64 [ 0, %for.cond1.preheader ], [ %indvars.iv.next, %for.body3 ]
128   %arrayidx = getelementptr inbounds [1024 x i32]* @v, i64 0, i64 %indvars.iv
129   %0 = load i32* %arrayidx, align 4
130   %conv = sitofp i32 %0 to double
131   %arrayidx5 = getelementptr inbounds [1024 x double]* @x, i64 0, i64 %indvars.iv
132   %1 = load double* %arrayidx5, align 8
133   %mul = fmul double %conv, %1
134   %arrayidx7 = getelementptr inbounds [1024 x double]* @y, i64 0, i64 %indvars.iv
135   %2 = load double* %arrayidx7, align 8
136   %mul8 = fmul double %mul, %2
137   %arrayidx10 = getelementptr inbounds [1024 x double]* @z, i64 0, i64 %indvars.iv
138   %3 = load double* %arrayidx10, align 8
139   %mul11 = fmul double %mul8, %3
140   %arrayidx13 = getelementptr inbounds [1024 x double]* @w, i64 0, i64 %indvars.iv
141   store double %mul11, double* %arrayidx13, align 8
142   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
143   %exitcond = icmp eq i64 %indvars.iv.next, 1024
144   br i1 %exitcond, label %for.inc14, label %for.body3
145
146 for.inc14:                                        ; preds = %for.body3
147   %inc15 = add nsw i32 %i.025, 1
148   %exitcond26 = icmp eq i32 %inc15, 100000
149   br i1 %exitcond26, label %for.end16, label %for.cond1.preheader
150
151 for.end16:                                        ; preds = %for.inc14
152   ret void
153
154 ;CHECK-LABEL:@loopdep2
155 ;CHECK: xorps [[XMM0:%xmm[0-9]+]], [[XMM0]]
156 ;CHECK-NEXT: cvtsi2sdl {{.*}}, [[XMM0]]
157 ;CHECK-NEXT: mulsd {{.*}}, [[XMM0]]
158 ;CHECK-NEXT: mulsd {{.*}}, [[XMM0]]
159 ;CHECK-NEXT: mulsd {{.*}}, [[XMM0]]
160 ;CHECK-NEXT: movsd [[XMM0]],
161 }