160 lines · plain
1; RUN: opt -passes=consthoist -mtriple=x86_64-unknown-linux-gnu -consthoist-with-block-frequency=true -S < %s | FileCheck %s2 3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"4 5; Check when BFI is enabled for constant hoisting, constant 2147483647016; will not be hoisted to the func entry.7; CHECK-LABEL: @test1(8; CHECK: entry:9; CHECK-NOT: bitcast i64 214748364701 to i6410; CHECK: if.then:11 12; Function Attrs: norecurse nounwind uwtable13define i64 @test1(ptr nocapture %a) {14entry:15 %arrayidx = getelementptr inbounds i64, ptr %a, i64 916 %t0 = load i64, ptr %arrayidx, align 817 %cmp = icmp slt i64 %t0, 56418 br i1 %cmp, label %if.then, label %if.else519 20if.then: ; preds = %entry21 %arrayidx1 = getelementptr inbounds i64, ptr %a, i64 522 %t1 = load i64, ptr %arrayidx1, align 823 %cmp2 = icmp slt i64 %t1, 100924 br i1 %cmp2, label %if.then3, label %return25 26if.then3: ; preds = %if.then27 %arrayidx4 = getelementptr inbounds i64, ptr %a, i64 628 %t2 = load i64, ptr %arrayidx4, align 829 %inc = add nsw i64 %t2, 130 store i64 %inc, ptr %arrayidx4, align 831 br label %return32 33if.else5: ; preds = %entry34 %arrayidx6 = getelementptr inbounds i64, ptr %a, i64 635 %t3 = load i64, ptr %arrayidx6, align 836 %cmp7 = icmp slt i64 %t3, 351237 br i1 %cmp7, label %if.then8, label %return38 39if.then8: ; preds = %if.else540 %arrayidx9 = getelementptr inbounds i64, ptr %a, i64 741 %t4 = load i64, ptr %arrayidx9, align 842 %inc10 = add nsw i64 %t4, 143 store i64 %inc10, ptr %arrayidx9, align 844 br label %return45 46return: ; preds = %if.else5, %if.then, %if.then8, %if.then347 %retval.0 = phi i64 [ 214748364701, %if.then3 ], [ 214748364701, %if.then8 ], [ 250148364702, %if.then ], [ 256148364704, %if.else5 ]48 ret i64 %retval.049}50 51; Check when BFI is enabled for constant hoisting, constant 21474836470152; in while.body will be hoisted to while.body.preheader. 214748364701 in53; if.then16 and if.else10 will be merged and hoisted to the beginning of54; if.else10 because if.else10 dominates if.then16.55; CHECK-LABEL: @test2(56; CHECK: entry:57; CHECK-NOT: bitcast i64 214748364701 to i6458; CHECK: while.body.preheader:59; CHECK-NEXT: bitcast i64 214748364701 to i6460; CHECK-NOT: bitcast i64 214748364701 to i6461; CHECK: if.else10:62; CHECK-NEXT: bitcast i64 214748364701 to i6463; CHECK-NOT: bitcast i64 214748364701 to i6464define i64 @test2(ptr nocapture %a) {65entry:66 %arrayidx = getelementptr inbounds i64, ptr %a, i64 967 %t0 = load i64, ptr %arrayidx, align 868 %cmp = icmp ult i64 %t0, 5669 br i1 %cmp, label %if.then, label %if.else10, !prof !070 71if.then: ; preds = %entry72 %arrayidx1 = getelementptr inbounds i64, ptr %a, i64 573 %t1 = load i64, ptr %arrayidx1, align 874 %cmp2 = icmp ult i64 %t1, 1075 br i1 %cmp2, label %while.cond.preheader, label %return, !prof !076 77while.cond.preheader: ; preds = %if.then78 %arrayidx7 = getelementptr inbounds i64, ptr %a, i64 679 %t2 = load i64, ptr %arrayidx7, align 880 %cmp823 = icmp ugt i64 %t2, 1000081 br i1 %cmp823, label %while.body.preheader, label %return82 83while.body.preheader: ; preds = %while.cond.preheader84 br label %while.body85 86while.body: ; preds = %while.body.preheader, %while.body87 %t3 = phi i64 [ %add, %while.body ], [ %t2, %while.body.preheader ]88 %add = add i64 %t3, 21474836470189 %cmp8 = icmp ugt i64 %add, 1000090 br i1 %cmp8, label %while.body, label %while.cond.return.loopexit_crit_edge91 92if.else10: ; preds = %entry93 %arrayidx11 = getelementptr inbounds i64, ptr %a, i64 694 %t4 = load i64, ptr %arrayidx11, align 895 %add2 = add i64 %t4, 21474836470196 %cmp12 = icmp ult i64 %add2, 3597 br i1 %cmp12, label %if.then16, label %return, !prof !098 99if.then16: ; preds = %if.else10100 %arrayidx17 = getelementptr inbounds i64, ptr %a, i64 7101 %t5 = load i64, ptr %arrayidx17, align 8102 %inc = add i64 %t5, 1103 store i64 %inc, ptr %arrayidx17, align 8104 br label %return105 106while.cond.return.loopexit_crit_edge: ; preds = %while.body107 store i64 %add, ptr %arrayidx7, align 8108 br label %return109 110return: ; preds = %while.cond.preheader, %while.cond.return.loopexit_crit_edge, %if.else10, %if.then, %if.then16111 %retval.0 = phi i64 [ 214748364701, %if.then16 ], [ 0, %if.then ], [ 0, %if.else10 ], [ 0, %while.cond.return.loopexit_crit_edge ], [ 0, %while.cond.preheader ]112 ret i64 %retval.0113}114 115!0 = !{!"branch_weights", i32 1, i32 2000}116 117; 214748364701 will be hoisted to entry block to reduce code size.118; CHECK-LABEL: @test3(119; CHECK: entry:120; CHECK-NEXT: %const = bitcast i64 214748364701 to i64121define i64 @test3(i64 %t0) {122entry:123 %cmp = icmp ult i64 %t0, 56124 br i1 %cmp, label %if.then, label %if.else125 126; CHECK: if.then:127; CHECK-NOT: %const = bitcast i64 214748364701 to i64128if.then:129 %add1 = add i64 %t0, 214748364701130 br label %return131 132; CHECK: if.else:133; CHECK-NOT: %const = bitcast i64 214748364701 to i64134if.else:135 %add2 = add i64 %t0, 214748364701136 br label %return137 138return:139 %retval = phi i64 [ %add1, %if.then ], [ %add2, %if.else ]140 ret i64 %retval141}142 143; 214748364701 will not be hoisted to entry block because it will only144; increase its live range.145; CHECK-LABEL: @test4(146; CHECK: nextblock:147; CHECK-NEXT: %add1 = add i64 %t0, 214748364701148define i64 @test4(i64 %t0) {149entry:150 %cmp = icmp ult i64 %t0, 56151 br label %nextblock152 153nextblock:154 %add1 = add i64 %t0, 214748364701155 br label %return156 157return:158 ret i64 %add1159}160