1; Test load hoist 2; RUN: opt -basicaa -memdep -mldst-motion -S < %s | FileCheck %s 3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 4target triple = "x86_64-pc_linux" 5 6; Function Attrs: nounwind uwtable 7define float* @foo(i32* noalias nocapture readonly %in, float* noalias %out, i32 %size, i32* nocapture readonly %trigger) { 8entry: 9 %cmp11 = icmp eq i32 %size, 0 10 br i1 %cmp11, label %for.end, label %for.body.lr.ph 11 12for.body.lr.ph: ; preds = %entry 13 %0 = add i32 %size, -1 14 br label %for.body 15 16; CHECK-LABEL: for.body 17; CHECK: load 18; CHECK: %2 = getelementptr inbounds i32, i32* %in, i64 %indvars.iv 19; CHECK: %3 = load i32, i32* %2, align 4 20 21for.body: ; preds = %for.body.lr.ph, %for.inc 22 %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.inc ] 23 %arrayidx = getelementptr inbounds i32, i32* %trigger, i64 %indvars.iv 24 %1 = load i32, i32* %arrayidx, align 4 25 %cmp1 = icmp sgt i32 %1, 0 26 br i1 %cmp1, label %if.then, label %if.else 27 28; CHECK-LABEL: if.then 29if.then: ; preds = %for.body 30; This load should be hoisted 31 %arrayidx3 = getelementptr inbounds i32, i32* %in, i64 %indvars.iv 32 %2 = load i32, i32* %arrayidx3, align 4 33 %conv = sitofp i32 %2 to float 34 %add = fadd float %conv, 5.000000e-01 35 %arrayidx5 = getelementptr inbounds float, float* %out, i64 %indvars.iv 36 store float %add, float* %arrayidx5, align 4 37 br label %for.inc 38 39if.else: ; preds = %for.body 40 %arrayidx7 = getelementptr inbounds float, float* %out, i64 %indvars.iv 41 %3 = load float, float* %arrayidx7, align 4 42 %div = fdiv float %3, 3.000000e+00 43 store float %div, float* %arrayidx7, align 4 44; This load should be hoisted in spite of store 45 %arrayidx9 = getelementptr inbounds i32, i32* %in, i64 %indvars.iv 46 %4 = load i32, i32* %arrayidx9, align 4 47 %conv10 = sitofp i32 %4 to float 48 %add13 = fadd float %div, %conv10 49 store float %add13, float* %arrayidx7, align 4 50 br label %for.inc 51 52for.inc: ; preds = %if.then, %if.else 53 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1 54 %lftr.wideiv = trunc i64 %indvars.iv to i32 55 %exitcond = icmp ne i32 %lftr.wideiv, %0 56 br i1 %exitcond, label %for.body, label %for.cond.for.end_crit_edge 57 58for.cond.for.end_crit_edge: ; preds = %for.inc 59 br label %for.end 60 61for.end: ; preds = %entry, %for.cond.for.end_crit_edge 62 ret float* %out 63} 64 65