216 lines · plain
1; RUN: opt < %s -loop-reduce -S -mtriple=x86_64-unknown-unknown 2>&1 | FileCheck %s2 3; Provide legal integer types.4target datalayout = "n8:16:32:64"5 6 7define void @foobar(i32 %n) nounwind {8 9; CHECK-LABEL: foobar(10; CHECK: phi double11 12entry:13 %cond = icmp eq i32 %n, 0 ; <i1>:0 [#uses=2]14 br i1 %cond, label %return, label %bb.nph15 16bb.nph: ; preds = %entry17 %umax = select i1 %cond, i32 1, i32 %n ; <i32> [#uses=1]18 br label %bb19 20bb: ; preds = %bb, %bb.nph21 %i.03 = phi i32 [ 0, %bb.nph ], [ %indvar.next, %bb ] ; <i32> [#uses=3]22 tail call void @bar( i32 %i.03 ) nounwind23 %tmp1 = uitofp i32 %i.03 to double ; <double>:1 [#uses=1]24 tail call void @foo( double %tmp1 ) nounwind25 %indvar.next = add nsw nuw i32 %i.03, 1 ; <i32> [#uses=2]26 %exitcond = icmp eq i32 %indvar.next, %umax ; <i1> [#uses=1]27 br i1 %exitcond, label %return, label %bb28 29return: ; preds = %bb, %entry30 ret void31}32 33; Unable to eliminate cast because the mantissa bits for double are not enough34; to hold all of i64 IV bits.35define void @foobar2(i64 %n) nounwind {36 37; CHECK-LABEL: foobar2(38; CHECK-NOT: phi double39; CHECK-NOT: phi float40 41entry:42 %cond = icmp eq i64 %n, 0 ; <i1>:0 [#uses=2]43 br i1 %cond, label %return, label %bb.nph44 45bb.nph: ; preds = %entry46 %umax = select i1 %cond, i64 1, i64 %n ; <i64> [#uses=1]47 br label %bb48 49bb: ; preds = %bb, %bb.nph50 %i.03 = phi i64 [ 0, %bb.nph ], [ %indvar.next, %bb ] ; <i64> [#uses=3]51 %tmp1 = trunc i64 %i.03 to i32 ; <i32>:1 [#uses=1]52 tail call void @bar( i32 %tmp1 ) nounwind53 %tmp2 = uitofp i64 %i.03 to double ; <double>:2 [#uses=1]54 tail call void @foo( double %tmp2 ) nounwind55 %indvar.next = add nsw nuw i64 %i.03, 1 ; <i64> [#uses=2]56 %exitcond = icmp eq i64 %indvar.next, %umax ; <i1> [#uses=1]57 br i1 %exitcond, label %return, label %bb58 59return: ; preds = %bb, %entry60 ret void61}62 63; Unable to eliminate cast due to potentional overflow.64define void @foobar3() nounwind {65 66; CHECK-LABEL: foobar3(67; CHECK-NOT: phi double68; CHECK-NOT: phi float69 70entry:71 %tmp0 = tail call i32 (...) @nn( ) nounwind ; <i32>:0 [#uses=1]72 %cond = icmp eq i32 %tmp0, 0 ; <i1>:1 [#uses=1]73 br i1 %cond, label %return, label %bb74 75bb: ; preds = %bb, %entry76 %i.03 = phi i32 [ 0, %entry ], [ %indvar.next, %bb ] ; <i32> [#uses=3]77 tail call void @bar( i32 %i.03 ) nounwind78 %tmp2 = uitofp i32 %i.03 to double ; <double>:2 [#uses=1]79 tail call void @foo( double %tmp2 ) nounwind80 %indvar.next = add nuw nsw i32 %i.03, 1 ; <i32>:3 [#uses=2]81 %tmp4 = tail call i32 (...) @nn( ) nounwind ; <i32>:4 [#uses=1]82 %exitcond = icmp ugt i32 %tmp4, %indvar.next ; <i1>:5 [#uses=1]83 br i1 %exitcond, label %bb, label %return84 85return: ; preds = %bb, %entry86 ret void87}88 89; Unable to eliminate cast due to overflow.90define void @foobar4() nounwind {91 92; CHECK-LABEL: foobar4(93; CHECK-NOT: phi double94; CHECK-NOT: phi float95 96entry:97 br label %bb.nph98 99bb.nph: ; preds = %entry100 br label %bb101 102bb: ; preds = %bb, %bb.nph103 %i.03 = phi i8 [ 0, %bb.nph ], [ %indvar.next, %bb ] ; <i32> [#uses=3]104 %tmp2 = sext i8 %i.03 to i32 ; <i32>:0 [#uses=1]105 tail call void @bar( i32 %tmp2 ) nounwind106 %tmp3 = uitofp i8 %i.03 to double ; <double>:1 [#uses=1]107 tail call void @foo( double %tmp3 ) nounwind108 %indvar.next = add nsw nuw i8 %i.03, 1 ; <i32> [#uses=2]109 %tmp = sext i8 %indvar.next to i32110 %exitcond = icmp eq i32 %tmp, 32767 ; <i1> [#uses=1]111 br i1 %exitcond, label %return, label %bb112 113return: ; preds = %bb, %entry114 ret void115}116 117; Unable to eliminate cast because the integer IV overflows (accum exceeds118; SINT_MAX).119 120define i32 @foobar5() {121; CHECK-LABEL: foobar5(122; CHECK-NOT: phi double123; CHECK-NOT: phi float124entry:125 br label %loop126 127loop:128 %accum = phi i32 [ -3220, %entry ], [ %accum.next, %loop ]129 %iv = phi i32 [ 12, %entry ], [ %iv.next, %loop ]130 %tmp1 = sitofp i32 %accum to double131 tail call void @foo( double %tmp1 ) nounwind132 %accum.next = add i32 %accum, 9597741133 %iv.next = add nuw nsw i32 %iv, 1134 %exitcond = icmp ugt i32 %iv, 235135 br i1 %exitcond, label %exit, label %loop136 137exit: ; preds = %loop138 ret i32 %accum.next139}140 141; Can eliminate if we set nsw and, thus, think that we don't overflow SINT_MAX.142 143define i32 @foobar6() {144; CHECK-LABEL: foobar6(145; CHECK: phi double146 147entry:148 br label %loop149 150loop:151 %accum = phi i32 [ -3220, %entry ], [ %accum.next, %loop ]152 %iv = phi i32 [ 12, %entry ], [ %iv.next, %loop ]153 %tmp1 = sitofp i32 %accum to double154 tail call void @foo( double %tmp1 ) nounwind155 %accum.next = add nsw i32 %accum, 9597741156 %iv.next = add nuw nsw i32 %iv, 1157 %exitcond = icmp ugt i32 %iv, 235158 br i1 %exitcond, label %exit, label %loop159 160exit: ; preds = %loop161 ret i32 %accum.next162}163 164; Unable to eliminate cast because the integer IV overflows (accum exceeds165; UINT_MAX).166 167define i32 @foobar7() {168; CHECK-LABEL: foobar7(169; CHECK-NOT: phi double170; CHECK-NOT: phi float171entry:172 br label %loop173 174loop:175 %accum = phi i32 [ -3220, %entry ], [ %accum.next, %loop ]176 %iv = phi i32 [ 12, %entry ], [ %iv.next, %loop ]177 %tmp1 = uitofp i32 %accum to double178 tail call void @foo( double %tmp1 ) nounwind179 %accum.next = add i32 %accum, 9597741180 %iv.next = add nuw nsw i32 %iv, 1181 %exitcond = icmp ugt i32 %iv, 235182 br i1 %exitcond, label %exit, label %loop183 184exit: ; preds = %loop185 ret i32 %accum.next186}187 188; Can eliminate if we set nuw and, thus, think that we don't overflow UINT_MAX.189 190define i32 @foobar8() {191; CHECK-LABEL: foobar8(192; CHECK: phi double193 194entry:195 br label %loop196 197loop:198 %accum = phi i32 [ -3220, %entry ], [ %accum.next, %loop ]199 %iv = phi i32 [ 12, %entry ], [ %iv.next, %loop ]200 %tmp1 = uitofp i32 %accum to double201 tail call void @foo( double %tmp1 ) nounwind202 %accum.next = add nuw i32 %accum, 9597741203 %iv.next = add nuw nsw i32 %iv, 1204 %exitcond = icmp ugt i32 %iv, 235205 br i1 %exitcond, label %exit, label %loop206 207exit: ; preds = %loop208 ret i32 %accum.next209}210 211declare void @bar(i32)212 213declare void @foo(double)214 215declare i32 @nn(...)216