| ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py |
| ; RUN: opt < %s -basicaa -slp-vectorizer -dce -S -mtriple=i386-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s |
| |
| target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128" |
| target triple = "i386-apple-macosx10.8.0" |
| |
| ; int foo(double *A, int n, int m) { |
| ; double sum = 0, v1 = 2, v0 = 3; |
| ; for (int i=0; i < n; ++i) |
| ; sum += 7*A[i*2] + 7*A[i*2+1]; |
| ; return sum; |
| ; } |
| |
| define i32 @reduce(double* nocapture %A, i32 %n, i32 %m) { |
| ; CHECK-LABEL: @reduce( |
| ; CHECK-NEXT: entry: |
| ; CHECK-NEXT: [[CMP13:%.*]] = icmp sgt i32 [[N:%.*]], 0 |
| ; CHECK-NEXT: br i1 [[CMP13]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]] |
| ; CHECK: for.body: |
| ; CHECK-NEXT: [[I_015:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ] |
| ; CHECK-NEXT: [[SUM_014:%.*]] = phi double [ [[ADD6:%.*]], [[FOR_BODY]] ], [ 0.000000e+00, [[ENTRY]] ] |
| ; CHECK-NEXT: [[MUL:%.*]] = shl nsw i32 [[I_015]], 1 |
| ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, double* [[A:%.*]], i32 [[MUL]] |
| ; CHECK-NEXT: [[TMP0:%.*]] = bitcast double* [[ARRAYIDX]] to <2 x double>* |
| ; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, <2 x double>* [[TMP0]], align 4 |
| ; CHECK-NEXT: [[TMP2:%.*]] = fmul <2 x double> <double 7.000000e+00, double 7.000000e+00>, [[TMP1]] |
| ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x double> [[TMP2]], i32 0 |
| ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x double> [[TMP2]], i32 1 |
| ; CHECK-NEXT: [[ADD5:%.*]] = fadd double [[TMP3]], [[TMP4]] |
| ; CHECK-NEXT: [[ADD6]] = fadd double [[SUM_014]], [[ADD5]] |
| ; CHECK-NEXT: [[INC]] = add nsw i32 [[I_015]], 1 |
| ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], [[N]] |
| ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_FOR_END_CRIT_EDGE:%.*]], label [[FOR_BODY]] |
| ; CHECK: for.cond.for.end_crit_edge: |
| ; CHECK-NEXT: [[PHITMP:%.*]] = fptosi double [[ADD6]] to i32 |
| ; CHECK-NEXT: br label [[FOR_END]] |
| ; CHECK: for.end: |
| ; CHECK-NEXT: [[SUM_0_LCSSA:%.*]] = phi i32 [ [[PHITMP]], [[FOR_COND_FOR_END_CRIT_EDGE]] ], [ 0, [[ENTRY]] ] |
| ; CHECK-NEXT: ret i32 [[SUM_0_LCSSA]] |
| ; |
| entry: |
| %cmp13 = icmp sgt i32 %n, 0 |
| br i1 %cmp13, label %for.body, label %for.end |
| |
| for.body: ; preds = %entry, %for.body |
| %i.015 = phi i32 [ %inc, %for.body ], [ 0, %entry ] |
| %sum.014 = phi double [ %add6, %for.body ], [ 0.000000e+00, %entry ] |
| %mul = shl nsw i32 %i.015, 1 |
| %arrayidx = getelementptr inbounds double, double* %A, i32 %mul |
| %0 = load double, double* %arrayidx, align 4 |
| %mul1 = fmul double %0, 7.000000e+00 |
| %add12 = or i32 %mul, 1 |
| %arrayidx3 = getelementptr inbounds double, double* %A, i32 %add12 |
| %1 = load double, double* %arrayidx3, align 4 |
| %mul4 = fmul double %1, 7.000000e+00 |
| %add5 = fadd double %mul1, %mul4 |
| %add6 = fadd double %sum.014, %add5 |
| %inc = add nsw i32 %i.015, 1 |
| %exitcond = icmp eq i32 %inc, %n |
| br i1 %exitcond, label %for.cond.for.end_crit_edge, label %for.body |
| |
| for.cond.for.end_crit_edge: ; preds = %for.body |
| %phitmp = fptosi double %add6 to i32 |
| br label %for.end |
| |
| for.end: ; preds = %for.cond.for.end_crit_edge, %entry |
| %sum.0.lcssa = phi i32 [ %phitmp, %for.cond.for.end_crit_edge ], [ 0, %entry ] |
| ret i32 %sum.0.lcssa |
| } |
| |