83 lines · plain
1; Tests to make sure that loads and stores in a diamond get merged2; Loads are hoisted into the header. Stores sunks into the footer.3; RUN: opt -passes=gvn-hoist -S < %s | FileCheck %s4target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"5 6%struct.node = type { i64, ptr, ptr, ptr, i64, ptr, i64, i64, i64 }7%struct.arc = type { i64, i64, i64 }8 9define i64 @foo(ptr nocapture readonly %r) nounwind {10entry:11 %node.0.in16 = getelementptr inbounds %struct.node, ptr %r, i64 0, i32 212 %node.017 = load ptr, ptr %node.0.in16, align 813 %tobool18 = icmp eq ptr %node.017, null14 br i1 %tobool18, label %while.end, label %while.body.preheader15 16; CHECK-LABEL: while.body.preheader17while.body.preheader: ; preds = %entry18; CHECK: load19 br label %while.body20 21while.body: ; preds = %while.body.preheader, %if.end22 %node.020 = phi ptr [ %node.0, %if.end ], [ %node.017, %while.body.preheader ]23 %sum.019 = phi i64 [ %inc, %if.end ], [ 0, %while.body.preheader ]24 %orientation = getelementptr inbounds %struct.node, ptr %node.020, i64 0, i32 425 %0 = load i64, ptr %orientation, align 826 %cmp = icmp eq i64 %0, 127 br i1 %cmp, label %if.then, label %if.else28; CHECK: if.then29if.then: ; preds = %while.body30 %a = getelementptr inbounds %struct.node, ptr %node.020, i64 0, i32 531; CHECK-NOT: load %struct.arc32 %1 = load ptr, ptr %a, align 833; CHECK-NOT: load i64, ptr34 %2 = load i64, ptr %1, align 835 %pred = getelementptr inbounds %struct.node, ptr %node.020, i64 0, i32 136; CHECK-NOT: load ptr, ptr37 %3 = load ptr, ptr %pred, align 838 %p = getelementptr inbounds %struct.node, ptr %3, i64 0, i32 639; CHECK-NOT: load i64, ptr40 %4 = load i64, ptr %p, align 841 %add = add nsw i64 %4, %242 %p1 = getelementptr inbounds %struct.node, ptr %node.020, i64 0, i32 643; FIXME: store i6444 store i64 %add, ptr %p1, align 845 br label %if.end46 47; CHECK: if.else48if.else: ; preds = %while.body49 %pred2 = getelementptr inbounds %struct.node, ptr %node.020, i64 0, i32 150; CHECK-NOT: load ptr, ptr51 %5 = load ptr, ptr %pred2, align 852 %p3 = getelementptr inbounds %struct.node, ptr %5, i64 0, i32 653; CHECK-NOT: load i64, ptr54 %6 = load i64, ptr %p3, align 855 %a4 = getelementptr inbounds %struct.node, ptr %node.020, i64 0, i32 556; CHECK-NOT: load ptr, ptr57 %7 = load ptr, ptr %a4, align 858; CHECK-NOT: load i64, ptr59 %8 = load i64, ptr %7, align 860 %sub = sub nsw i64 %6, %861 %p6 = getelementptr inbounds %struct.node, ptr %node.020, i64 0, i32 662; FIXME: store i6463 store i64 %sub, ptr %p6, align 864 br label %if.end65 66; CHECK: if.end67if.end: ; preds = %if.else, %if.then68; FIXME: store69 %inc = add nsw i64 %sum.019, 170 %node.0.in = getelementptr inbounds %struct.node, ptr %node.020, i64 0, i32 271 %node.0 = load ptr, ptr %node.0.in, align 872 %tobool = icmp eq ptr %node.0, null73 br i1 %tobool, label %while.end.loopexit, label %while.body74 75while.end.loopexit: ; preds = %if.end76 %inc.lcssa = phi i64 [ %inc, %if.end ]77 br label %while.end78 79while.end: ; preds = %while.end.loopexit, %entry80 %sum.0.lcssa = phi i64 [ 0, %entry ], [ %inc.lcssa, %while.end.loopexit ]81 ret i64 %sum.0.lcssa82}83