131 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt < %s -passes=slp-vectorizer,dce -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s3 4target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"5target triple = "x86_64-apple-macosx10.8.0"6 7; double foo(ptr restrict b, ptr restrict a, int n, int m) {8; double r=a[1];9; double g=a[0];10; double x;11; for (int i=0; i < 100; i++) {12; r += 10;13; g += 10;14; r *= 4;15; g *= 4;16; x = g; <----- external user!17; r += 4;18; g += 4;19; }20; b[0] = g;21; b[1] = r;22;23; return x; <-- must extract here!24; }25 26define double @ext_user(ptr noalias nocapture %B, ptr noalias nocapture %A, i32 %n, i32 %m) {27; CHECK-LABEL: @ext_user(28; CHECK-NEXT: entry:29; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[A:%.*]], align 830; CHECK-NEXT: br label [[FOR_BODY:%.*]]31; CHECK: for.body:32; CHECK-NEXT: [[I_020:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[INC:%.*]], [[FOR_BODY]] ]33; CHECK-NEXT: [[TMP2:%.*]] = phi <2 x double> [ [[TMP1]], [[ENTRY]] ], [ [[TMP5:%.*]], [[FOR_BODY]] ]34; CHECK-NEXT: [[TMP3:%.*]] = fadd <2 x double> [[TMP2]], splat (double 1.000000e+01)35; CHECK-NEXT: [[TMP4:%.*]] = fmul <2 x double> [[TMP3]], splat (double 4.000000e+00)36; CHECK-NEXT: [[TMP5]] = fadd <2 x double> [[TMP4]], splat (double 4.000000e+00)37; CHECK-NEXT: [[INC]] = add nsw i32 [[I_020]], 138; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], 10039; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END:%.*]], label [[FOR_BODY]]40; CHECK: for.end:41; CHECK-NEXT: store <2 x double> [[TMP5]], ptr [[B:%.*]], align 842; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x double> [[TMP4]], i32 043; CHECK-NEXT: ret double [[TMP7]]44;45entry:46 %arrayidx = getelementptr inbounds double, ptr %A, i64 147 %0 = load double, ptr %arrayidx, align 848 %1 = load double, ptr %A, align 849 br label %for.body50 51for.body: ; preds = %for.body, %entry52 %i.020 = phi i32 [ 0, %entry ], [ %inc, %for.body ]53 %G.019 = phi double [ %1, %entry ], [ %add5, %for.body ]54 %R.018 = phi double [ %0, %entry ], [ %add4, %for.body ]55 %add = fadd double %R.018, 1.000000e+0156 %add2 = fadd double %G.019, 1.000000e+0157 %mul = fmul double %add, 4.000000e+0058 %mul3 = fmul double %add2, 4.000000e+0059 %add4 = fadd double %mul, 4.000000e+0060 %add5 = fadd double %mul3, 4.000000e+0061 %inc = add nsw i32 %i.020, 162 %exitcond = icmp eq i32 %inc, 10063 br i1 %exitcond, label %for.end, label %for.body64 65for.end: ; preds = %for.body66 store double %add5, ptr %B, align 867 %arrayidx7 = getelementptr inbounds double, ptr %B, i64 168 store double %add4, ptr %arrayidx7, align 869 ret double %mul370}71 72; A need-to-gather entry cannot be an external use of the scalar element.73; Instead the insertelement instructions of the need-to-gather entry are the74; external users.75; This test would assert because we would keep the scalar fpext and fadd alive.76; PR1812977 78define i32 @needtogather(ptr noalias %a, ptr noalias %b, ptr noalias %c,79; CHECK-LABEL: @needtogather(80; CHECK-NEXT: entry:81; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[D:%.*]], align 482; CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[TMP0]] to float83; CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[C:%.*]], align 484; CHECK-NEXT: [[SUB:%.*]] = fsub float 0.000000e+00, [[TMP1]]85; CHECK-NEXT: [[MUL:%.*]] = fmul float [[SUB]], 0.000000e+0086; CHECK-NEXT: [[ADD:%.*]] = fadd float [[CONV]], [[MUL]]87; CHECK-NEXT: [[CONV1:%.*]] = fpext float [[ADD]] to double88; CHECK-NEXT: [[SUB3:%.*]] = fsub float 1.000000e+00, [[TMP1]]89; CHECK-NEXT: [[MUL4:%.*]] = fmul float [[SUB3]], 0.000000e+0090; CHECK-NEXT: [[ADD5:%.*]] = fadd float [[CONV]], [[MUL4]]91; CHECK-NEXT: [[CONV6:%.*]] = fpext float [[ADD5]] to double92; CHECK-NEXT: [[TOBOOL:%.*]] = fcmp une float [[ADD]], 0.000000e+0093; CHECK-NEXT: br i1 [[TOBOOL]], label [[IF_THEN:%.*]], label [[IF_END:%.*]]94; CHECK: if.then:95; CHECK-NEXT: br label [[IF_END]]96; CHECK: if.end:97; CHECK-NEXT: [[STOREMERGE:%.*]] = phi double [ [[CONV6]], [[IF_THEN]] ], [ [[CONV1]], [[ENTRY:%.*]] ]98; CHECK-NEXT: [[E_0:%.*]] = phi double [ [[CONV1]], [[IF_THEN]] ], [ [[CONV6]], [[ENTRY]] ]99; CHECK-NEXT: store double [[STOREMERGE]], ptr [[A:%.*]], align 8100; CHECK-NEXT: [[CONV7:%.*]] = fptosi double [[E_0]] to i32101; CHECK-NEXT: store i32 [[CONV7]], ptr [[B:%.*]], align 4102; CHECK-NEXT: ret i32 undef103;104 ptr noalias %d) {105entry:106 %0 = load i32, ptr %d, align 4107 %conv = sitofp i32 %0 to float108 %1 = load float, ptr %c109 %sub = fsub float 0.000000e+00, %1110 %mul = fmul float %sub, 0.000000e+00111 %add = fadd float %conv, %mul112 %conv1 = fpext float %add to double113 %sub3 = fsub float 1.000000e+00, %1114 %mul4 = fmul float %sub3, 0.000000e+00115 %add5 = fadd float %conv, %mul4116 %conv6 = fpext float %add5 to double117 %tobool = fcmp une float %add, 0.000000e+00118 br i1 %tobool, label %if.then, label %if.end119 120if.then:121 br label %if.end122 123if.end:124 %storemerge = phi double [ %conv6, %if.then ], [ %conv1, %entry ]125 %e.0 = phi double [ %conv1, %if.then ], [ %conv6, %entry ]126 store double %storemerge, ptr %a, align 8127 %conv7 = fptosi double %e.0 to i32128 store i32 %conv7, ptr %b, align 4129 ret i32 undef130}131