229 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc < %s -mtriple=x86_64-pc-linux-gnu | FileCheck %s -check-prefixes=CHECK,ALIGN3; RUN: llc < %s -mtriple=x86_64-pc-linux-gnu -align-loops=32 | FileCheck %s -check-prefixes=CHECK,ALIGN324; RUN: llc < %s -mtriple=x86_64-pc-linux-gnu -align-loops=256 | FileCheck %s -check-prefixes=CHECK,ALIGN2565 6; This test is to check if .p2align can be correctly generated by considerring7; 1. -align-loops=N from llc option8; 2. loop metadata node !{!"llvm.loop.align", i32 64}9; The test IR is generated from below simple C file:10; $ clang -S -emit-llvm loop.c11; $ cat loop.c12; void bar(void);13; void var(void);14; void foo(int a) {15; for (int i = 0; i < a; ++i)16; bar();17; for (int i = 0; i < a; ++i)18; var();19; }20; The difference between test1 and test2 is test2 only set one loop metadata node for the second loop.21 22; CHECK-LABEL: test1:23; ALIGN: .p2align 624; ALIGN-NEXT: .LBB0_2: # %for.body25; ALIGN: .p2align 926; ALIGN-NEXT: .LBB0_3: # %for.body27 28; ALIGN32: .p2align 629; ALIGN32-NEXT: .LBB0_2: # %for.body30; ALIGN32: .p2align 931; ALIGN32-NEXT: .LBB0_3: # %for.body32 33; ALIGN256: .p2align 834; ALIGN256-NEXT: .LBB0_2: # %for.body35; ALIGN256: .p2align 936; ALIGN256-NEXT: .LBB0_3: # %for.body37 38define void @test1(i32 %a) nounwind {39entry:40 %cmp12 = icmp sgt i32 %a, 041 br i1 %cmp12, label %for.body, label %for.cond.cleanup442 43for.body: ; preds = %entry, %for.body44 %i.013 = phi i32 [ %inc, %for.body ], [ 0, %entry ]45 tail call void @bar()46 %inc = add nuw nsw i32 %i.013, 147 %exitcond.not = icmp eq i32 %inc, %a48 br i1 %exitcond.not, label %for.body5, label %for.body, !llvm.loop !049 50for.cond.cleanup4: ; preds = %for.body5, %entry51 ret void52 53for.body5: ; preds = %for.body, %for.body554 %i1.015 = phi i32 [ %inc7, %for.body5 ], [ 0, %for.body ]55 tail call void @var()56 %inc7 = add nuw nsw i32 %i1.015, 157 %exitcond16.not = icmp eq i32 %inc7, %a58 br i1 %exitcond16.not, label %for.cond.cleanup4, label %for.body5, !llvm.loop !259}60 61; CHECK-LABEL: test2:62; ALIGN: .p2align 463; ALIGN-NEXT: .LBB1_2: # %for.body64; ALIGN: .p2align 965; ALIGN-NEXT: .LBB1_3: # %for.body66 67; ALIGN32: .p2align 568; ALIGN32-NEXT: .LBB1_2: # %for.body69; ALIGN32: .p2align 970; ALIGN32-NEXT: .LBB1_3: # %for.body71 72; ALIGN256: .p2align 873; ALIGN256-NEXT: .LBB1_2: # %for.body74; ALIGN256: .p2align 975; ALIGN256-NEXT: .LBB1_3: # %for.body76define void @test2(i32 %a) nounwind {77entry:78 %cmp12 = icmp sgt i32 %a, 079 br i1 %cmp12, label %for.body, label %for.cond.cleanup480 81for.body: ; preds = %entry, %for.body82 %i.013 = phi i32 [ %inc, %for.body ], [ 0, %entry ]83 tail call void @bar()84 %inc = add nuw nsw i32 %i.013, 185 %exitcond.not = icmp eq i32 %inc, %a86 br i1 %exitcond.not, label %for.body5, label %for.body87 88for.cond.cleanup4: ; preds = %for.body5, %entry89 ret void90 91for.body5: ; preds = %for.body, %for.body592 %i1.015 = phi i32 [ %inc7, %for.body5 ], [ 0, %for.body ]93 tail call void @var()94 %inc7 = add nuw nsw i32 %i1.015, 195 %exitcond16.not = icmp eq i32 %inc7, %a96 br i1 %exitcond16.not, label %for.cond.cleanup4, label %for.body5, !llvm.loop !297}98 99; test3 and test4 is to check if .p2align can be correctly set on loops with100; multi latches. The IR is generated from below simple C file:101; $ clang -O0 -S -emit-llvm loop.c102; $ cat loop.c103; int test3() {104; int i = 0;105; [[clang::code_align(32)]]106; while (i < 10) {107; if (i % 2) {108; continue;109; }110; i++;111; }112; }113; CHECK-LABEL: test3_multilatch:114; ALIGN: .p2align 6115; ALIGN-NEXT: .LBB2_1: # %while.cond116define dso_local i32 @test3_multilatch() #0 {117entry:118 %retval = alloca i32, align 4119 %i = alloca i32, align 4120 store i32 0, ptr %retval, align 4121 store i32 0, ptr %i, align 4122 br label %while.cond123 124while.cond: ; preds = %if.end, %if.then, %entry125 %0 = load i32, ptr %i, align 4126 %cmp = icmp slt i32 %0, 10127 br i1 %cmp, label %while.body, label %while.end128 129while.body: ; preds = %while.cond130 %1 = load i32, ptr %i, align 4131 %rem = srem i32 %1, 2132 %tobool = icmp ne i32 %rem, 0133 br i1 %tobool, label %if.then, label %if.end134 135if.then: ; preds = %while.body136 br label %while.cond, !llvm.loop !0137 138if.end: ; preds = %while.body139 %2 = load i32, ptr %i, align 4140 %inc = add nsw i32 %2, 1141 store i32 %inc, ptr %i, align 4142 br label %while.cond, !llvm.loop !0143 144while.end: ; preds = %while.cond145 %3 = load i32, ptr %retval, align 4146 ret i32 %3147}148 149; CHECK-LABEL: test4_multilatch:150; ALIGN: .p2align 6151; ALIGN-NEXT: .LBB3_4: # %bb4152define void @test4_multilatch(i32 %a, i32 %b, i32 %c, i32 %d) nounwind {153entry:154 br label %bb1155 156bb1: ; preds = %bb2, %bb4, %entry157 call void @bar()158 %cmp3 = icmp sgt i32 %c, 10159 br i1 %cmp3, label %bb3, label %bb4160 161bb2: ; preds = %bb3162 call void @bar()163 %cmp1 = icmp sgt i32 %a, 11164 br i1 %cmp1, label %bb1, label %exit, !llvm.loop !0165 166bb3: ; preds = %bb1167 call void @bar()168 %cmp2 = icmp sgt i32 %b, 12169 br i1 %cmp2, label %bb2, label %exit170 171bb4: ; preds = %bb1172 call void @bar()173 %cmp4 = icmp sgt i32 %d, 14174 br i1 %cmp4, label %bb1, label %exit175 176exit: ; preds = %bb2, %bb3, %bb4177 ret void178}179 180; test5 is to check if .p2align can be correctly set on loops with a single181; latch that's not the exiting block.182; The test IR is generated from below simple C file:183; $ clang -O0 -S -emit-llvm loop.c184; $ cat loop.c185; int test5(int n) {186; int i = 0;187; [[clang::code_align(64)]]188; while (i < n) {189; i++;190; }191; }192; CHECK-LABEL: test5:193; ALIGN: .p2align 6194; ALIGN-NEXT: .LBB4_1: # %while.cond195define i32 @test5(i32 %n) #0 {196entry:197 %retval = alloca i32, align 4198 %n.addr = alloca i32, align 4199 %i = alloca i32, align 4200 store i32 %n, ptr %n.addr, align 4201 store i32 0, ptr %i, align 4202 br label %while.cond203 204while.cond: ; preds = %while.body, %entry205 %i.val = load i32, ptr %i, align 4206 %n.val = load i32, ptr %n.addr, align 4207 %cmp = icmp slt i32 %i.val, %n.val208 br i1 %cmp, label %while.body, label %while.end209 210while.body: ; preds = %while.cond211 %tmp = load i32, ptr %i, align 4212 %inc = add nsw i32 %tmp, 1213 store i32 %inc, ptr %i, align 4214 br label %while.cond, !llvm.loop !0215 216while.end: ; preds = %while.cond217 %val = load i32, ptr %retval, align 4218 ret i32 %val219}220 221 222declare void @bar()223declare void @var()224 225!0 = distinct !{!0, !1}226!1 = !{!"llvm.loop.align", i32 64}227!2 = distinct !{!2, !3}228!3 = !{!"llvm.loop.align", i32 512}229