Home | History | Annotate | Download | only in LoopUnroll
      1 ; RUN: opt %s -S -o - -loop-unroll | FileCheck %s
      2 ; generated at -O3 from:
      3 ; void f() {
      4 ;   for (int i = 1; i <=32; i <<=2 )
      5 ;     bar(i>>1);
      6 ; }
      7 source_filename = "/tmp/loop.c"
      8 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
      9 target triple = "x86_64-apple-macosx10.13.0"
     10 
     11 ; Function Attrs: nounwind ssp uwtable
     12 define void @f() local_unnamed_addr #0 !dbg !8 {
     13 entry:
     14   tail call void @llvm.dbg.value(metadata i32 1, metadata !12, metadata !DIExpression()), !dbg !15
     15   br label %for.body, !dbg !16
     16 
     17 for.cond.cleanup:                                 ; preds = %for.body
     18   ret void, !dbg !17
     19 
     20 for.body:                                         ; preds = %entry, %for.body
     21   %i.04 = phi i32 [ 1, %entry ], [ %shl, %for.body ]
     22   tail call void @llvm.dbg.value(metadata i32 %i.04, metadata !12, metadata !DIExpression()), !dbg !15
     23   %shr = ashr i32 %i.04, 1, !dbg !18
     24 
     25   ; The loop gets unrolled entirely.
     26   ; CHECK: call void @llvm.dbg.value(metadata i32 1, metadata !12, metadata !DIExpression()), !dbg !15
     27   ; CHECK: call void @llvm.dbg.value(metadata i32 4, metadata !12, metadata !DIExpression()), !dbg !15
     28   ; CHECK: call void @llvm.dbg.value(metadata i32 16, metadata !12, metadata !DIExpression()), !dbg !15
     29   ; CHECK: call void @llvm.dbg.value(metadata i32 64, metadata !12, metadata !DIExpression()), !dbg !15
     30   
     31   %call = tail call i32 (i32, ...) bitcast (i32 (...)* @bar to i32 (i32, ...)*)(i32 %shr) #3, !dbg !20
     32   %shl = shl i32 %i.04, 2, !dbg !21
     33   tail call void @llvm.dbg.value(metadata i32 %shl, metadata !12, metadata !DIExpression()), !dbg !15
     34   %cmp = icmp slt i32 %shl, 33, !dbg !22
     35   br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !16, !llvm.loop !23
     36 }
     37 
     38 declare i32 @bar(...) local_unnamed_addr
     39 
     40 ; Function Attrs: nounwind readnone speculatable
     41 declare void @llvm.dbg.value(metadata, metadata, metadata) #2
     42 
     43 attributes #0 = { nounwind ssp uwtable }
     44 attributes #2 = { nounwind readnone speculatable }
     45 attributes #3 = { nounwind }
     46 
     47 !llvm.dbg.cu = !{!0}
     48 !llvm.module.flags = !{!3, !4, !5, !6}
     49 !llvm.ident = !{!7}
     50 
     51 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 (trunk 317113) (llvm/trunk 317122)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
     52 !1 = !DIFile(filename: "/tmp/loop.c", directory: "/Data/llvm")
     53 !2 = !{}
     54 !3 = !{i32 2, !"Dwarf Version", i32 4}
     55 !4 = !{i32 2, !"Debug Info Version", i32 3}
     56 !5 = !{i32 1, !"wchar_size", i32 4}
     57 !6 = !{i32 7, !"PIC Level", i32 2}
     58 !7 = !{!"clang version 6.0.0 (trunk 317113) (llvm/trunk 317122)"}
     59 !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !0, retainedNodes: !11)
     60 !9 = !DISubroutineType(types: !10)
     61 !10 = !{null}
     62 !11 = !{!12}
     63 !12 = !DILocalVariable(name: "i", scope: !13, file: !1, line: 2, type: !14)
     64 !13 = distinct !DILexicalBlock(scope: !8, file: !1, line: 2, column: 3)
     65 !14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
     66 !15 = !DILocation(line: 2, column: 12, scope: !13)
     67 !16 = !DILocation(line: 2, column: 3, scope: !13)
     68 !17 = !DILocation(line: 4, column: 1, scope: !8)
     69 !18 = !DILocation(line: 3, column: 10, scope: !19)
     70 !19 = distinct !DILexicalBlock(scope: !13, file: !1, line: 2, column: 3)
     71 !20 = !DILocation(line: 3, column: 5, scope: !19)
     72 !21 = !DILocation(line: 2, column: 29, scope: !19)
     73 !22 = !DILocation(line: 2, column: 21, scope: !19)
     74 !23 = distinct !{!23, !16, !24}
     75 !24 = !DILocation(line: 3, column: 13, scope: !13)
     76