65 lines · plain
1; Test load hoist2; RUN: opt -passes=gvn-hoist -S < %s | FileCheck %s3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"4target triple = "x86_64-pc_linux"5 6; Function Attrs: nounwind uwtable7define ptr @foo(ptr noalias nocapture readonly %in, ptr noalias %out, i32 %size, ptr nocapture readonly %trigger) {8entry:9 %cmp11 = icmp eq i32 %size, 010 br i1 %cmp11, label %for.end, label %for.body.lr.ph11 12for.body.lr.ph: ; preds = %entry13 %0 = add i32 %size, -114 br label %for.body15 16; CHECK-LABEL: for.body17; CHECK: load18; CHECK: %2 = getelementptr inbounds i32, ptr %in, i64 %indvars.iv19; CHECK: %3 = load i32, ptr %2, align 420 21for.body: ; preds = %for.body.lr.ph, %for.inc22 %indvars.iv = phi i64 [ 0, %for.body.lr.ph ], [ %indvars.iv.next, %for.inc ]23 %arrayidx = getelementptr inbounds i32, ptr %trigger, i64 %indvars.iv24 %1 = load i32, ptr %arrayidx, align 425 %cmp1 = icmp sgt i32 %1, 026 br i1 %cmp1, label %if.then, label %if.else27 28; CHECK-LABEL: if.then29if.then: ; preds = %for.body30; This load should be hoisted31 %arrayidx3 = getelementptr inbounds i32, ptr %in, i64 %indvars.iv32 %2 = load i32, ptr %arrayidx3, align 433 %conv = sitofp i32 %2 to float34 %add = fadd float %conv, 5.000000e-0135 %arrayidx5 = getelementptr inbounds float, ptr %out, i64 %indvars.iv36 store float %add, ptr %arrayidx5, align 437 br label %for.inc38 39if.else: ; preds = %for.body40 %arrayidx7 = getelementptr inbounds float, ptr %out, i64 %indvars.iv41 %3 = load float, ptr %arrayidx7, align 442 %div = fdiv float %3, 3.000000e+0043 store float %div, ptr %arrayidx7, align 444; This load should be hoisted in spite of store 45 %arrayidx9 = getelementptr inbounds i32, ptr %in, i64 %indvars.iv46 %4 = load i32, ptr %arrayidx9, align 447 %conv10 = sitofp i32 %4 to float48 %add13 = fadd float %div, %conv1049 store float %add13, ptr %arrayidx7, align 450 br label %for.inc51 52for.inc: ; preds = %if.then, %if.else53 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 154 %lftr.wideiv = trunc i64 %indvars.iv to i3255 %exitcond = icmp ne i32 %lftr.wideiv, %056 br i1 %exitcond, label %for.body, label %for.cond.for.end_crit_edge57 58for.cond.for.end_crit_edge: ; preds = %for.inc59 br label %for.end60 61for.end: ; preds = %entry, %for.cond.for.end_crit_edge62 ret ptr %out63}64 65