1 ; Tests to make sure that loads and stores in a diamond get merged 2 ; Loads are hoisted into the header. Stores sunks into the footer. 3 ; RUN: opt -basicaa -memdep -mldst-motion -S < %s | FileCheck %s 4 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128" 5 6 %struct.node = type { i64, %struct.node*, %struct.node*, %struct.node*, i64, %struct.arc*, i64, i64, i64 } 7 %struct.arc = type { i64, i64, i64 } 8 9 define i64 @foo(%struct.node* nocapture readonly %r) nounwind { 10 entry: 11 %node.0.in16 = getelementptr inbounds %struct.node, %struct.node* %r, i64 0, i32 2 12 %node.017 = load %struct.node*, %struct.node** %node.0.in16, align 8 13 %tobool18 = icmp eq %struct.node* %node.017, null 14 br i1 %tobool18, label %while.end, label %while.body.preheader 15 16 ; CHECK-LABEL: while.body.preheader 17 while.body.preheader: ; preds = %entry 18 ; CHECK: load 19 br label %while.body 20 21 while.body: ; preds = %while.body.preheader, %if.end 22 %node.020 = phi %struct.node* [ %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, %struct.node* %node.020, i64 0, i32 4 25 %0 = load i64, i64* %orientation, align 8 26 %cmp = icmp eq i64 %0, 1 27 br i1 %cmp, label %if.then, label %if.else 28 ; CHECK: if.then 29 if.then: ; preds = %while.body 30 %a = getelementptr inbounds %struct.node, %struct.node* %node.020, i64 0, i32 5 31 ; CHECK-NOT: load %struct.arc 32 %1 = load %struct.arc*, %struct.arc** %a, align 8 33 %cost = getelementptr inbounds %struct.arc, %struct.arc* %1, i64 0, i32 0 34 ; CHECK-NOT: load i64, i64* 35 %2 = load i64, i64* %cost, align 8 36 %pred = getelementptr inbounds %struct.node, %struct.node* %node.020, i64 0, i32 1 37 ; CHECK-NOT: load %struct.node*, %struct.node** 38 %3 = load %struct.node*, %struct.node** %pred, align 8 39 %p = getelementptr inbounds %struct.node, %struct.node* %3, i64 0, i32 6 40 ; CHECK-NOT: load i64, i64* 41 %4 = load i64, i64* %p, align 8 42 %add = add nsw i64 %4, %2 43 %p1 = getelementptr inbounds %struct.node, %struct.node* %node.020, i64 0, i32 6 44 ; CHECK-NOT: store i64 45 store i64 %add, i64* %p1, align 8 46 br label %if.end 47 48 ; CHECK: if.else 49 if.else: ; preds = %while.body 50 %pred2 = getelementptr inbounds %struct.node, %struct.node* %node.020, i64 0, i32 1 51 ; CHECK-NOT: load %struct.node*, %struct.node** 52 %5 = load %struct.node*, %struct.node** %pred2, align 8 53 %p3 = getelementptr inbounds %struct.node, %struct.node* %5, i64 0, i32 6 54 ; CHECK-NOT: load i64, i64* 55 %6 = load i64, i64* %p3, align 8 56 %a4 = getelementptr inbounds %struct.node, %struct.node* %node.020, i64 0, i32 5 57 ; CHECK-NOT: load %struct.arc*, %struct.arc** 58 %7 = load %struct.arc*, %struct.arc** %a4, align 8 59 %cost5 = getelementptr inbounds %struct.arc, %struct.arc* %7, i64 0, i32 0 60 ; CHECK-NOT: load i64, i64* 61 %8 = load i64, i64* %cost5, align 8 62 %sub = sub nsw i64 %6, %8 63 %p6 = getelementptr inbounds %struct.node, %struct.node* %node.020, i64 0, i32 6 64 ; CHECK-NOT: store i64 65 store i64 %sub, i64* %p6, align 8 66 br label %if.end 67 68 ; CHECK: if.end 69 if.end: ; preds = %if.else, %if.then 70 ; CHECK: store 71 %inc = add nsw i64 %sum.019, 1 72 %node.0.in = getelementptr inbounds %struct.node, %struct.node* %node.020, i64 0, i32 2 73 %node.0 = load %struct.node*, %struct.node** %node.0.in, align 8 74 %tobool = icmp eq %struct.node* %node.0, null 75 br i1 %tobool, label %while.end.loopexit, label %while.body 76 77 while.end.loopexit: ; preds = %if.end 78 %inc.lcssa = phi i64 [ %inc, %if.end ] 79 br label %while.end 80 81 while.end: ; preds = %while.end.loopexit, %entry 82 %sum.0.lcssa = phi i64 [ 0, %entry ], [ %inc.lcssa, %while.end.loopexit ] 83 ret i64 %sum.0.lcssa 84 } 85