161 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py2; RUN: opt -passes=loop-unroll -mtriple=arm64-apple-iphoneos -S %s | FileCheck %s3 4; Check we unroll even with optsize, if the result is smaller, either because5; we have single iteration loops or bodies with constant folding opportunities6; after fully unrolling.7 8declare i32 @get()9 10define void @fully_unrolled_single_iteration(ptr %src) #0 {11; CHECK-LABEL: @fully_unrolled_single_iteration(12; CHECK-NEXT: entry:13; CHECK-NEXT: [[ARR:%.*]] = alloca [4 x i32], align 414; CHECK-NEXT: br label [[FOR_BODY:%.*]]15; CHECK: for.body:16; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[SRC:%.*]]17; CHECK-NEXT: store i32 [[V]], ptr [[ARR]], align 418; CHECK-NEXT: call void @use(ptr nonnull [[ARR]])19; CHECK-NEXT: ret void20;21entry:22 %arr = alloca [4 x i32], align 423 br label %for.body24 25for.body: ; preds = %for.body, %entry26 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]27 %src.idx = getelementptr inbounds i32, ptr %src, i64 %indvars.iv28 %v = load i32, ptr %src.idx29 %arrayidx = getelementptr inbounds [4 x i32], ptr %arr, i64 0, i64 %indvars.iv30 store i32 %v, ptr %arrayidx, align 431 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 132 %exitcond = icmp eq i64 %indvars.iv.next, 133 br i1 %exitcond, label %for.cond.cleanup, label %for.body34 35for.cond.cleanup: ; preds = %for.cond36 call void @use(ptr nonnull %arr) #437 ret void38}39 40 41define void @fully_unrolled_smaller() #0 {42; CHECK-LABEL: @fully_unrolled_smaller(43; CHECK-NEXT: entry:44; CHECK-NEXT: [[ARR:%.*]] = alloca [4 x i32], align 445; CHECK-NEXT: br label [[FOR_BODY:%.*]]46; CHECK: for.body:47; CHECK-NEXT: store i32 16, ptr [[ARR]], align 448; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr inbounds [4 x i32], ptr [[ARR]], i64 0, i64 149; CHECK-NEXT: store i32 4104, ptr [[ARRAYIDX_1]], align 450; CHECK-NEXT: [[ARRAYIDX_2:%.*]] = getelementptr inbounds [4 x i32], ptr [[ARR]], i64 0, i64 251; CHECK-NEXT: store i32 1048592, ptr [[ARRAYIDX_2]], align 452; CHECK-NEXT: [[ARRAYIDX_3:%.*]] = getelementptr inbounds [4 x i32], ptr [[ARR]], i64 0, i64 353; CHECK-NEXT: store i32 268435480, ptr [[ARRAYIDX_3]], align 454; CHECK-NEXT: call void @use(ptr nonnull [[ARR]])55; CHECK-NEXT: ret void56;57entry:58 %arr = alloca [4 x i32], align 459 br label %for.body60 61for.body: ; preds = %for.body, %entry62 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]63 %indvars.iv.tr = trunc i64 %indvars.iv to i3264 %shl.0 = shl i32 %indvars.iv.tr, 365 %shl.1 = shl i32 16, %shl.066 %or = or i32 %shl.1, %shl.067 %arrayidx = getelementptr inbounds [4 x i32], ptr %arr, i64 0, i64 %indvars.iv68 store i32 %or, ptr %arrayidx, align 469 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 170 %exitcond = icmp eq i64 %indvars.iv, 371 br i1 %exitcond, label %for.cond.cleanup, label %for.body72 73for.cond.cleanup: ; preds = %for.cond74 call void @use(ptr nonnull %arr) #475 ret void76}77 78define void @fully_unrolled_smaller_Oz() #1 {79; CHECK-LABEL: @fully_unrolled_smaller_Oz(80; CHECK-NEXT: entry:81; CHECK-NEXT: [[ARR:%.*]] = alloca [4 x i32], align 482; CHECK-NEXT: br label [[FOR_BODY:%.*]]83; CHECK: for.body:84; CHECK-NEXT: store i32 16, ptr [[ARR]], align 485; CHECK-NEXT: [[ARRAYIDX_1:%.*]] = getelementptr inbounds [4 x i32], ptr [[ARR]], i64 0, i64 186; CHECK-NEXT: store i32 4104, ptr [[ARRAYIDX_1]], align 487; CHECK-NEXT: [[ARRAYIDX_2:%.*]] = getelementptr inbounds [4 x i32], ptr [[ARR]], i64 0, i64 288; CHECK-NEXT: store i32 1048592, ptr [[ARRAYIDX_2]], align 489; CHECK-NEXT: [[ARRAYIDX_3:%.*]] = getelementptr inbounds [4 x i32], ptr [[ARR]], i64 0, i64 390; CHECK-NEXT: store i32 268435480, ptr [[ARRAYIDX_3]], align 491; CHECK-NEXT: call void @use(ptr nonnull [[ARR]])92; CHECK-NEXT: ret void93;94entry:95 %arr = alloca [4 x i32], align 496 br label %for.body97 98for.body: ; preds = %for.body, %entry99 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]100 %indvars.iv.tr = trunc i64 %indvars.iv to i32101 %shl.0 = shl i32 %indvars.iv.tr, 3102 %shl.1 = shl i32 16, %shl.0103 %or = or i32 %shl.1, %shl.0104 %arrayidx = getelementptr inbounds [4 x i32], ptr %arr, i64 0, i64 %indvars.iv105 store i32 %or, ptr %arrayidx, align 4106 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1107 %exitcond = icmp eq i64 %indvars.iv, 3108 br i1 %exitcond, label %for.cond.cleanup, label %for.body109 110for.cond.cleanup: ; preds = %for.cond111 call void @use(ptr nonnull %arr) #4112 ret void113}114 115 116define void @fully_unrolled_bigger() #0 {117; CHECK-LABEL: @fully_unrolled_bigger(118; CHECK-NEXT: entry:119; CHECK-NEXT: [[ARR:%.*]] = alloca [4 x i32], align 4120; CHECK-NEXT: br label [[FOR_BODY:%.*]]121; CHECK: for.body:122; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ]123; CHECK-NEXT: [[INDVARS_IV_TR:%.*]] = trunc i64 [[INDVARS_IV]] to i32124; CHECK-NEXT: [[SHL_0:%.*]] = shl i32 [[INDVARS_IV_TR]], 3125; CHECK-NEXT: [[SHL_1:%.*]] = shl i32 16, [[SHL_0]]126; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHL_1]], [[SHL_0]]127; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [4 x i32], ptr [[ARR]], i64 0, i64 [[INDVARS_IV]]128; CHECK-NEXT: store i32 [[OR]], ptr [[ARRAYIDX]], align 4129; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1130; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV]], 7131; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]132; CHECK: for.cond.cleanup:133; CHECK-NEXT: call void @use(ptr nonnull [[ARR]])134; CHECK-NEXT: ret void135;136entry:137 %arr = alloca [4 x i32], align 4138 br label %for.body139 140for.body: ; preds = %for.body, %entry141 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]142 %indvars.iv.tr = trunc i64 %indvars.iv to i32143 %shl.0 = shl i32 %indvars.iv.tr, 3144 %shl.1 = shl i32 16, %shl.0145 %or = or i32 %shl.1, %shl.0146 %arrayidx = getelementptr inbounds [4 x i32], ptr %arr, i64 0, i64 %indvars.iv147 store i32 %or, ptr %arrayidx, align 4148 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1149 %exitcond = icmp eq i64 %indvars.iv, 7150 br i1 %exitcond, label %for.cond.cleanup, label %for.body151 152for.cond.cleanup: ; preds = %for.cond153 call void @use(ptr nonnull %arr) #4154 ret void155}156 157declare void @use(ptr)158 159attributes #0 = { optsize }160attributes #1 = { minsize optsize }161