1 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -hoist-const-stores -ppc-stack-ptr-caller-preserved < %s | FileCheck %s 2 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-linux-gnu -hoist-const-stores -ppc-stack-ptr-caller-preserved < %s | FileCheck %s -check-prefix=CHECKBE 3 4 ; Test hoist out of single loop 5 define signext i32 @test1(i32 signext %lim, i32 (i32)* nocapture %Func) { 6 entry: 7 ; CHECK-LABEL: test1 8 ; CHECK: for.body.preheader 9 ; CHECK: std 2, 24(1) 10 ; CHECK: for.body 11 ; CHECK-NOT: std 2, 24(1) 12 ; CHECKBE-LABEL: test1 13 ; CHECKBE: for.body.preheader 14 ; CHECKBE: std 2, 40(1) 15 ; CHECKBE: for.body 16 ; CHECKBE-NOT: std 2, 40(1) 17 18 %cmp6 = icmp sgt i32 %lim, 0 19 br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup 20 21 for.body.preheader: ; preds = %entry 22 br label %for.body 23 24 for.cond.cleanup: ; preds = %for.body, %entry 25 %Sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.body ] 26 ret i32 %Sum.0.lcssa 27 28 for.body: ; preds = %for.body.preheader, %for.body 29 %i.08 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ] 30 %Sum.07 = phi i32 [ %add, %for.body ], [ 0, %for.body.preheader ] 31 %call = tail call signext i32 %Func(i32 signext %i.08) 32 %add = add nsw i32 %call, %Sum.07 33 %inc = add nuw nsw i32 %i.08, 1 34 %exitcond = icmp eq i32 %inc, %lim 35 br i1 %exitcond, label %for.cond.cleanup, label %for.body 36 } 37 38 ; Test hoist of nested loop goes to outter loop preheader 39 define signext i32 @test2(i32 signext %lim, i32 (i32)* nocapture %Func) { 40 entry: 41 ; CHECK-LABEL: test2 42 ; CHECK: for.body4.lr.ph.preheader 43 ; CHECK: std 2, 24(1) 44 ; CHECK: for.body4.lr.ph 45 ; CHECK-NOT: std 2, 24(1) 46 ; CHECKBE-LABEL: test2 47 ; CHECKBE: for.body4.lr.ph.preheader 48 ; CHECKBE: std 2, 40(1) 49 ; CHECKBE: for.body4.lr.ph 50 ; CHECKBE-NOT: std 2, 40(1) 51 52 %cmp20 = icmp sgt i32 %lim, 0 53 br i1 %cmp20, label %for.body4.lr.ph.preheader, label %for.cond.cleanup 54 55 for.body4.lr.ph.preheader: ; preds = %entry 56 br label %for.body4.lr.ph 57 58 for.cond.cleanup: ; preds = %for.cond.cleanup3, %entry 59 %Sum.0.lcssa = phi i32 [ 0, %entry ], [ %add, %for.cond.cleanup3 ] 60 ret i32 %Sum.0.lcssa 61 62 for.body4.lr.ph: ; preds = %for.body4.lr.ph.preheader, %for.cond.cleanup3 63 %j.022 = phi i32 [ %inc6, %for.cond.cleanup3 ], [ 0, %for.body4.lr.ph.preheader ] 64 %Sum.021 = phi i32 [ %add, %for.cond.cleanup3 ], [ 0, %for.body4.lr.ph.preheader ] 65 br label %for.body4 66 67 for.cond.cleanup3: ; preds = %for.body4 68 %inc6 = add nuw nsw i32 %j.022, 1 69 %exitcond24 = icmp eq i32 %inc6, %lim 70 br i1 %exitcond24, label %for.cond.cleanup, label %for.body4.lr.ph 71 72 for.body4: ; preds = %for.body4, %for.body4.lr.ph 73 %i.019 = phi i32 [ %j.022, %for.body4.lr.ph ], [ %inc, %for.body4 ] 74 %Sum.118 = phi i32 [ %Sum.021, %for.body4.lr.ph ], [ %add, %for.body4 ] 75 %call = tail call signext i32 %Func(i32 signext %i.019) 76 %add = add nsw i32 %call, %Sum.118 77 %inc = add nuw nsw i32 %i.019, 1 78 %exitcond = icmp eq i32 %inc, %lim 79 br i1 %exitcond, label %for.cond.cleanup3, label %for.body4 80 } 81 82 ; Test hoist out of if statement with low branch probability 83 ; FIXME: we shouldn't hoist in such cases as it could increase the number 84 ; of stores after hoisting. 85 define signext i32 @test3(i32 signext %lim, i32 (i32)* nocapture %Func) { 86 entry: 87 ; CHECK-LABEL: test3 88 ; CHECK: %for.body.lr.ph 89 ; CHECK: std 2, 24(1) 90 ; CHECK: %for.body 91 ; CHECK-NOT: std 2, 24(1) 92 ; CHECKBE-LABEL: test3 93 ; CHECKBE: %for.body.lr.ph 94 ; CHECKBE: std 2, 40(1) 95 ; CHECKBE: %for.body 96 ; CHECKBE-NOT: std 2, 40(1) 97 98 %cmp13 = icmp sgt i32 %lim, 0 99 br i1 %cmp13, label %for.body.lr.ph, label %for.cond.cleanup 100 101 for.body.lr.ph: ; preds = %entry 102 %sub = add nsw i32 %lim, -1 103 br label %for.body 104 105 for.cond.cleanup: ; preds = %if.end, %entry 106 %Sum.0.lcssa = phi i32 [ 0, %entry ], [ %add3, %if.end ] 107 ret i32 %Sum.0.lcssa 108 109 for.body: ; preds = %if.end, %for.body.lr.ph 110 %i.015 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %if.end ] 111 %Sum.014 = phi i32 [ 0, %for.body.lr.ph ], [ %add3, %if.end ] 112 %cmp1 = icmp eq i32 %i.015, %sub 113 br i1 %cmp1, label %if.then, label %if.end 114 115 if.then: ; preds = %for.body 116 %call = tail call signext i32 %Func(i32 signext %sub) 117 %add = add nsw i32 %call, %Sum.014 118 br label %if.end 119 120 if.end: ; preds = %if.then, %for.body 121 %Sum.1 = phi i32 [ %add, %if.then ], [ %Sum.014, %for.body ] 122 %call2 = tail call signext i32 @func(i32 signext %i.015) 123 %add3 = add nsw i32 %call2, %Sum.1 124 %inc = add nuw nsw i32 %i.015, 1 125 %exitcond = icmp eq i32 %inc, %lim 126 br i1 %exitcond, label %for.cond.cleanup, label %for.body 127 } 128 129 declare signext i32 @func(i32 signext) 130