1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -passes=slp-vectorizer,dce -S -mtriple=x86_64-apple-macosx10.8.0 -mcpu=corei7-avx | FileCheck %s 3 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 8 30; 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]], 1 38; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[INC]], 100 39; 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 8 42; CHECK-NEXT: [[TMP7:%.*]] = extractelement <2 x double> [[TMP4]], i32 0 43; CHECK-NEXT: ret double [[TMP7]] 44; 45entry: 46 %arrayidx = getelementptr inbounds double, ptr %A, i64 1 47 %0 = load double, ptr %arrayidx, align 8 48 %1 = load double, ptr %A, align 8 49 br label %for.body 50 51for.body: ; preds = %for.body, %entry 52 %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+01 56 %add2 = fadd double %G.019, 1.000000e+01 57 %mul = fmul double %add, 4.000000e+00 58 %mul3 = fmul double %add2, 4.000000e+00 59 %add4 = fadd double %mul, 4.000000e+00 60 %add5 = fadd double %mul3, 4.000000e+00 61 %inc = add nsw i32 %i.020, 1 62 %exitcond = icmp eq i32 %inc, 100 63 br i1 %exitcond, label %for.end, label %for.body 64 65for.end: ; preds = %for.body 66 store double %add5, ptr %B, align 8 67 %arrayidx7 = getelementptr inbounds double, ptr %B, i64 1 68 store double %add4, ptr %arrayidx7, align 8 69 ret double %mul3 70} 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 the 74; external users. 75; This test would assert because we would keep the scalar fpext and fadd alive. 76; PR18129 77 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 4 82; CHECK-NEXT: [[CONV:%.*]] = sitofp i32 [[TMP0]] to float 83; CHECK-NEXT: [[TMP1:%.*]] = load float, ptr [[C:%.*]], align 4 84; CHECK-NEXT: [[SUB:%.*]] = fsub float 0.000000e+00, [[TMP1]] 85; CHECK-NEXT: [[MUL:%.*]] = fmul float [[SUB]], 0.000000e+00 86; CHECK-NEXT: [[ADD:%.*]] = fadd float [[CONV]], [[MUL]] 87; CHECK-NEXT: [[CONV1:%.*]] = fpext float [[ADD]] to double 88; CHECK-NEXT: [[SUB3:%.*]] = fsub float 1.000000e+00, [[TMP1]] 89; CHECK-NEXT: [[MUL4:%.*]] = fmul float [[SUB3]], 0.000000e+00 90; CHECK-NEXT: [[ADD5:%.*]] = fadd float [[CONV]], [[MUL4]] 91; CHECK-NEXT: [[CONV6:%.*]] = fpext float [[ADD5]] to double 92; CHECK-NEXT: [[TOBOOL:%.*]] = fcmp une float [[ADD]], 0.000000e+00 93; 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 8 100; CHECK-NEXT: [[CONV7:%.*]] = fptosi double [[E_0]] to i32 101; CHECK-NEXT: store i32 [[CONV7]], ptr [[B:%.*]], align 4 102; CHECK-NEXT: ret i32 undef 103; 104 ptr noalias %d) { 105entry: 106 %0 = load i32, ptr %d, align 4 107 %conv = sitofp i32 %0 to float 108 %1 = load float, ptr %c 109 %sub = fsub float 0.000000e+00, %1 110 %mul = fmul float %sub, 0.000000e+00 111 %add = fadd float %conv, %mul 112 %conv1 = fpext float %add to double 113 %sub3 = fsub float 1.000000e+00, %1 114 %mul4 = fmul float %sub3, 0.000000e+00 115 %add5 = fadd float %conv, %mul4 116 %conv6 = fpext float %add5 to double 117 %tobool = fcmp une float %add, 0.000000e+00 118 br i1 %tobool, label %if.then, label %if.end 119 120if.then: 121 br label %if.end 122 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 8 127 %conv7 = fptosi double %e.0 to i32 128 store i32 %conv7, ptr %b, align 4 129 ret i32 undef 130} 131