|  | 
|  | 1 | +; RUN: opt < %s -passes=simplifycfg -S | FileCheck %s | 
|  | 2 | + | 
|  | 3 | +; CHECK: switch i32 %state.0, label %sw.epilog | 
|  | 4 | +; CHECK-NEXT: i32 0, label %sw.bb | 
|  | 5 | +; CHECK-NEXT: i32 1, label %VM__OP_1 | 
|  | 6 | +; CHECK-NEXT: i32 2, label %sw.bb4 | 
|  | 7 | + | 
|  | 8 | +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" | 
|  | 9 | +target triple = "x86_64-unknown-linux-gnu" | 
|  | 10 | + | 
|  | 11 | +@.str = private unnamed_addr constant [23 x i8] c"OP_1:(instruction=%d)\0A\00", align 1 | 
|  | 12 | +@.str.1 = private unnamed_addr constant [28 x i8] c"TERMINATE:(instruction=%d)\0A\00", align 1 | 
|  | 13 | + | 
|  | 14 | +; Function Attrs: mustprogress norecurse uwtable | 
|  | 15 | +define dso_local noundef i32 @main() #0 { | 
|  | 16 | +entry: | 
|  | 17 | +  %bytecode = alloca [2 x ptr], align 16 | 
|  | 18 | +  store ptr blockaddress(@main, %VM__OP_1), ptr %bytecode, align 16, !tbaa !5 | 
|  | 19 | +  %arrayidx1 = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 1 | 
|  | 20 | +  store ptr blockaddress(@main, %VM__TERMINATE), ptr %arrayidx1, align 8, !tbaa !5 | 
|  | 21 | +  br label %while.body | 
|  | 22 | + | 
|  | 23 | +while.body:                                       ; preds = %entry, %sw.epilog | 
|  | 24 | +  %state.0 = phi i32 [ 0, %entry ], [ %state.1, %sw.epilog ] | 
|  | 25 | +  %index.0 = phi i32 [ 0, %entry ], [ %index.2, %sw.epilog ] | 
|  | 26 | +  switch i32 %state.0, label %sw.epilog [ | 
|  | 27 | +    i32 0, label %sw.bb | 
|  | 28 | +    i32 1, label %VM__OP_1 | 
|  | 29 | +    i32 2, label %sw.bb4 | 
|  | 30 | +  ] | 
|  | 31 | + | 
|  | 32 | +sw.bb:                                            ; preds = %while.body | 
|  | 33 | +  br label %indirectgoto | 
|  | 34 | + | 
|  | 35 | +VM__OP_1:                                         ; preds = %while.body, %indirectgoto | 
|  | 36 | +  %index.1 = phi i32 [ %index.3, %indirectgoto ], [ %index.0, %while.body ] | 
|  | 37 | +  br label %sw.epilog | 
|  | 38 | + | 
|  | 39 | +sw.bb4:                                           ; preds = %while.body | 
|  | 40 | +  %call = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i32 noundef %index.0) | 
|  | 41 | +  %inc = add nsw i32 %index.0, 1 | 
|  | 42 | +  br label %indirectgoto | 
|  | 43 | + | 
|  | 44 | +sw.epilog:                                        ; preds = %while.body, %VM__OP_1 | 
|  | 45 | +  %state.1 = phi i32 [ %state.0, %while.body ], [ 2, %VM__OP_1 ] | 
|  | 46 | +  %index.2 = phi i32 [ %index.0, %while.body ], [ %index.1, %VM__OP_1 ] | 
|  | 47 | +  br label %while.body, !llvm.loop !9 | 
|  | 48 | + | 
|  | 49 | +VM__TERMINATE:                                    ; preds = %indirectgoto | 
|  | 50 | +  %call7 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %index.3) | 
|  | 51 | +  ret i32 0 | 
|  | 52 | + | 
|  | 53 | +indirectgoto:                                     ; preds = %sw.bb4, %sw.bb | 
|  | 54 | +  %index.3 = phi i32 [ %inc, %sw.bb4 ], [ %index.0, %sw.bb ] | 
|  | 55 | +  %idxprom.pn = sext i32 %index.3 to i64 | 
|  | 56 | +  %indirect.goto.dest.in = getelementptr inbounds [2 x ptr], ptr %bytecode, i64 0, i64 %idxprom.pn | 
|  | 57 | +  %indirect.goto.dest = load ptr, ptr %indirect.goto.dest.in, align 8, !tbaa !5 | 
|  | 58 | +  indirectbr ptr %indirect.goto.dest, [label %VM__OP_1, label %VM__TERMINATE] | 
|  | 59 | +} | 
|  | 60 | +declare i32 @printf(ptr noundef, ...) #1 | 
|  | 61 | + | 
|  | 62 | +attributes #0 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } | 
|  | 63 | +attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" } | 
|  | 64 | + | 
|  | 65 | +!llvm.module.flags = !{!0, !1, !2, !3} | 
|  | 66 | +!llvm.ident = !{!4} | 
|  | 67 | + | 
|  | 68 | +!0 = !{i32 1, !"wchar_size", i32 4} | 
|  | 69 | +!1 = !{i32 8, !"PIC Level", i32 2} | 
|  | 70 | +!2 = !{i32 7, !"PIE Level", i32 2} | 
|  | 71 | +!3 = !{i32 7, !"uwtable", i32 2} | 
|  | 72 | +!4 = !{!"clang version 18.0.0git (https://github.com/llvm/llvm-project.git 67782d2de5ea9c8653b8f0110237a3c355291c0e)"} | 
|  | 73 | +!5 = !{!6, !6, i64 0} | 
|  | 74 | +!6 = !{!"any pointer", !7, i64 0} | 
|  | 75 | +!7 = !{!"omnipotent char", !8, i64 0} | 
|  | 76 | +!8 = !{!"Simple C++ TBAA"} | 
|  | 77 | +!9 = !{!10, !10, i64 0} | 
|  | 78 | +!10 = !{!"int", !7, i64 0} | 
|  | 79 | +!11 = distinct !{!11, !12, !13} | 
|  | 80 | +!12 = !{!"llvm.loop.mustprogress"} | 
|  | 81 | +!13 = !{!"llvm.loop.unroll.disable"} | 
|  | 82 | + | 
0 commit comments